Fix bad memory accounting for sds when no malloc_size available#694
Merged
Conversation
Signed-off-by: ranshid <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #694 +/- ##
============================================
+ Coverage 70.21% 70.24% +0.02%
============================================
Files 110 110
Lines 60100 60100
============================================
+ Hits 42202 42215 +13
+ Misses 17898 17885 -13
|
enjoy-binbin
approved these changes
Jun 25, 2024
madolson
approved these changes
Jun 25, 2024
tezc
added a commit
to redis/redis
that referenced
this pull request
May 8, 2026
This PR is based on valkey-io/valkey#453 and valkey-io/valkey#694 When jemalloc frees memory, it performs a lookup to find the allocation's size class. `sdallocx()` lets us skip this lookup by passing the size we already know. Introduced a new free function wrapper for this: `zfree_with_size()`. Note: Impact of this optimization is only visible on hot paths e.g. on repeated memory deallocations. For the initial phase, I integrated this at `sdsfree()` only. Over time, we may expand the usage of this new API for other performance sensitive paths. For testing, added jemalloc config `--enable-opt-size-checks` to the daily fortify build. This makes jemalloc validate that the size passed to `sdallocx()` matches the actual allocation's size class, aborting on mismatch. ---- Signed-off-by: Vadym Khoptynets <[email protected]> Signed-off-by: Madelyn Olson <[email protected]> Co-authored-by: Madelyn Olson <[email protected]> Signed-off-by: ranshid <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Introduced by #453.
When we check the SDS _TYPE_5 allocation size we mistakenly used zmalloc_size which DOES take the PREFIX size into account when no malloc_size support.
Later when we free we add the PREFIX_SIZE again which leads to negative memory accounting on some tests.
Example test failure: https://github.com/valkey-io/valkey/actions/runs/9654170962/job/26627901497