Skip to content

Fix bad memory accounting for sds when no malloc_size available#694

Merged
madolson merged 1 commit into
valkey-io:unstablefrom
ranshid:fix-sds-mem-accounting
Jun 25, 2024
Merged

Fix bad memory accounting for sds when no malloc_size available#694
madolson merged 1 commit into
valkey-io:unstablefrom
ranshid:fix-sds-mem-accounting

Conversation

@ranshid

@ranshid ranshid commented Jun 25, 2024

Copy link
Copy Markdown
Member

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

@ranshid ranshid requested a review from madolson June 25, 2024 12:47
@codecov

codecov Bot commented Jun 25, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.24%. Comparing base (4d3d6c0) to head (45ed952).

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     
Files Coverage Δ
src/sds.c 85.86% <100.00%> (ø)

... and 9 files with indirect coverage changes

@madolson madolson merged commit 3df9d42 into valkey-io:unstable 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]>
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

Successfully merging this pull request may close these issues.

3 participants