-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Optimize dictTypeResizeAllowed to avoid mistaken OOM judgement. #12950
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
Conversation
|
interesting... the reason is that expand and shrink have different expected sizes for the new hash table, right? |
@soloestoy Yes, exactly. However the possibility of |
enjoy-binbin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought before that this size should be passed by the caller, otherwise it may be missed
oranagra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conceptually LGTM, but instead of passing a boolean, to the function i think we can pass the size.
the code just below the call to dictTypeResizeAllowed does use d->ht_used[0] with or without +1, so i think it should pass the same one to dictTypeResizeAllowed
…s#12950) When doing dict resizing, dictTypeResizeAllowed is used to judge whether the new allocated memory for rehashing would cause OOM. However when shrinking, we alloc `_dictNextExp(d->ht_used[0])` bytes of memory, while in `dictTypeResizeAllowed` we still use `_dictNextExp(d->ht_used[0]+1)` as the new allocated memory size. This will overestimate the memory used by shrinking at special conditions, causing a false OOM judgement.
…s#12950) When doing dict resizing, dictTypeResizeAllowed is used to judge whether the new allocated memory for rehashing would cause OOM. However when shrinking, we alloc `_dictNextExp(d->ht_used[0])` bytes of memory, while in `dictTypeResizeAllowed` we still use `_dictNextExp(d->ht_used[0]+1)` as the new allocated memory size. This will overestimate the memory used by shrinking at special conditions, causing a false OOM judgement.
When doing dict resizing, dictTypeResizeAllowed is used to judge whether the new allocated memory for rehashing would cause OOM.
However when shrinking, we alloc
_dictNextExp(d->ht_used[0])bytes of memory, while indictTypeResizeAllowedwe still use_dictNextExp(d->ht_used[0]+1)as the new allocated memory size. This will overestimate the memory used by shrinking at special conditions, causing a false OOM judgement.