Skip to content

hashtable: fix dismissHashtable madvise size#3533

Open
charsyam wants to merge 1 commit intovalkey-io:unstablefrom
charsyam:fix/hashtable-dismiss-size
Open

hashtable: fix dismissHashtable madvise size#3533
charsyam wants to merge 1 commit intovalkey-io:unstablefrom
charsyam:fix/hashtable-dismiss-size

Conversation

@charsyam
Copy link
Copy Markdown
Contributor

The bug was in dismissHashtable(), which computes the size passed to zmadvise_dontneed() for the top-level hashtable
tables.

ht->tables[i] points to a contiguous array of bucket objects, but the code used sizeof(bucket *) instead of
sizeof(bucket) when calculating the length. That means it treated the allocation like an array of pointers rather than an
array of buckets.

As a result, the advised range was much smaller than the actual table allocation. On 64-bit builds, bucket is 64 bytes
while bucket * is 8 bytes, so only about one eighth of the table was covered. This does not usually break correctness,
but it defeats the purpose of the function: after a fork, we want to tell the kernel that the hashtable pages are no
longer needed so we reduce copy-on-write overhead. With the wrong size, most of the table memory was never included in
that hint.

The fix is to use sizeof(bucket) so the full top-level bucket array is passed to zmadvise_dontneed().

Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.45%. Comparing base (4a42c95) to head (81012b3).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3533      +/-   ##
============================================
+ Coverage     76.40%   76.45%   +0.05%     
============================================
  Files           159      159              
  Lines         79851    79851              
============================================
+ Hits          61008    61049      +41     
+ Misses        18843    18802      -41     
Files with missing lines Coverage Δ
src/hashtable.c 97.84% <100.00%> (ø)

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant