8000 How is the memory usage for the key-value calculated? · redis redis · Discussion #13677 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How is the memory usage for the key-value calculated? #13677

Answered by sundb
hnzhrh asked this question in Q&A
Discussion options

You must be logged in to vote
  1. For the key, Redis object header (16B) + sds5(1B + 6B + 1B = 8B) = 24B

no, key was saved as sds, not robj, so it's 8B.

  1. For the value, Redis object header(16B) + sds8( len(1B) + alloc(1B) + flags(1B) + "abcdef" string(6B) + \0 (1B) = 10B, Will be to 16B. Am I right?)

there are two cases here:

  1. if the sds is OBJ_ENCODING_RAW encoding, consume 24B.
  2. if the sds is OBJ_ENCODING_EMBSTR encoding, consume 32B, because robj and sds are in contiguous memory, occupying a total of 24 bytes, so they are allocated to bin 32

Then will be 24B + 16B + 16B = 56B. And the dictEntry will be 24B at least. (jemalloc will make it to 36B? Am i right?)

so the memory is (24B or 32B) + 8B + 24B(dictEntry)

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@hnzhrh
Comment options

10000
@sundb
Comment options

sundb Dec 4, 2024
Collaborator

Answer selected by hnzhrh
@hnzhrh
Comment options

@sundb
Comment options

sundb Dec 4, 2024
Collaborator

@hnzhrh
Comment options

@liuruishima7758
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
0