Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory usage reported by RSS is much higher than RocksDB MemoryUtil #13199

Open
979357361 opened this issue Dec 9, 2024 · 2 comments
Open

Memory usage reported by RSS is much higher than RocksDB MemoryUtil #13199

979357361 opened this issue Dec 9, 2024 · 2 comments

Comments

@979357361
Copy link

979357361 commented Dec 9, 2024

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:

  1. key_size = 19B, val_sz = 22B, SST = 64MB,
  2. memtable = 64MB, at most two memtables, that is 128MB at most
  3. 10bit bloom filter per kv, for each 250M kv that is 310MB filter blocks
  4. 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)
  5. for each 250M kv, we reserved 450MB > (310MB + 65MB) RAM for table reader (or called meta blocks -- fd, filter blocks and index blocks)
  6. 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!

@jowlyzhang
Copy link
Contributor

jowlyzhang commented Dec 12, 2024

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.

@979357361
Copy link
Author

979357361 commented Dec 13, 2024

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.

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants