Memory usage reported by RSS is much higher than RocksDB MemoryUtil
Opened this issue · 2 comments
we use RocksDB v9.4 with C API,
we want to control the total memory used by rocksdb, the WIKI told me there are mainly four parts contribute to RAM usage:
memtable / block cache / table reader / iterator pinned block.
we only use get and multi-get, so iterator can be filter out. Here is my setting:
- key_size = 19B, val_sz = 22B, SST = 64MB,
- memtable = 64MB, at most two memtables, that is 128MB at most
- 10bit bloom filter per kv, for each 250M kv that is 310MB filter blocks
- block_size = 4KB, for each 250M kv, there is 250M * (1+19+1+22) / 4K = 2750K bocks (ken_len, key, val_len, val), leading to 2750K * (19+4+1) = 65MB index blocks ( a key, a offset and size)
- for each 250M kv, we reserved 450MB > (310MB + 65MB) RAM for table reader (or called meta blocks -- fd, filter blocks and index blocks)
- for each 250M kv, we set hyper_block_cache = 440MB
We want rocksdb to consume <1GB RAM per 250M kv, we create rocksdb_memory_consumers_create, add block cache and DB to it, after feeding the DB 250M kv and warm up reading, we get from rocksdb_memory_consumers_create that the three usages are exactly what we thought:
rocksdb_approximate_memory_usage_get_mem_table_total < 64MB
rocksdb_approximate_memory_usage_get_mem_table_readers_total ≈ 440MB
rocksdb_approximate_memory_usage_get_cache_total ≈ 440MB
BUT, the RES in top command shows RocksDB consumed 1.5GB RAM. which is 50% higher than we thought, more over, when we get from rocksdb_memory_consumers_create the total memory is 8GB, the RES shows us 12GB RAM usage, also 50% higher
why the Memory usage reported by RSS is much higher than RocksDB MemoryUtil? Are our calculations wrong?
Any comments you may make are greatly appreciated, thanks you!
Do you use allow_mmap_read
or allow_mmap_write
, the mmapped memory is not accounted in those categories.
Looks like mmap_read is supposed to be used in combination of no compression + no block cache. So that probably is not the case here.
Do you useLooks like mmap_read is supposed to be used in combination of no compression + no block cache. So that probably is not the case here.allow_mmap_read
orallow_mmap_write
, the mmapped memory is not accounted in those categories.
thank you @jowlyzhang , I will have a try on mmap related options
we didn't change any mmap-related options, there is no compression but we did set a hyper clock cache,