Skip to content

Conversation

@CharlesChen888
Copy link
Contributor

@CharlesChen888 CharlesChen888 commented Jan 15, 2024

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.

@soloestoy
Copy link
Contributor

interesting... the reason is that expand and shrink have different expected sizes for the new hash table, right?

@CharlesChen888
Copy link
Contributor Author

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 _dictNextExp(d->ht_used[0]) and _dictNextExp(d->ht_used[0]+1) being diferent seems very low.

Copy link
Contributor

@enjoy-binbin enjoy-binbin left a 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

Copy link
Member

@oranagra oranagra left a 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

@oranagra oranagra added state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten and removed state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten labels Jan 17, 2024
@oranagra oranagra merged commit f81c3fd into redis:unstable Jan 18, 2024
roggervalf pushed a commit to roggervalf/redis that referenced this pull request Feb 11, 2024
…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.
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants