Skip to content

hashtable: fix dismissHashtable madvise size - #3533

Merged
madolson merged 1 commit into
valkey-io:unstablefrom
charsyam:fix/hashtable-dismiss-size
Apr 27, 2026
Merged

madolson merged 1 commit into
valkey-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().

@codecov

codecov Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.45%. Comparing base (4a42c95) to head (81012b3).
⚠️ Report is 20 commits behind head on unstable.

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.

@madolson madolson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

@madolson
madolson merged commit bb88665 into valkey-io:unstable Apr 27, 2026
59 checks passed
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
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 <[email protected]>
madolson pushed a commit that referenced this pull request Apr 27, 2026
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 <[email protected]>
sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 28, 2026
sarthakaggarwal97 added a commit that referenced this pull request Sep 16, 2026
Move the sorted set B+ tree note (#4359) to Behavior Changes: OBJECT
ENCODING now reports btree instead of skiplist, which is a client-visible
output change and matters more for upgrade decisions than the speedup.

Drop the notes for #3366 and #3791, neither of which is user-facing.
#3366 replaces dict with a wrapper around hashtable; scoping the
configured hash seed to data hashtables keeps hash-seed doing exactly
what valkey.conf documents it to do, and stops the seed leaking into
internal tables already populated during startup. #3791 makes the ranged
memory-release helper a no-op on non-jemalloc builds to match existing
behavior.

Add two changes that triage left out:
- #3533 fixed an undersized madvise range in dismissHashtable, so only
  about an eighth of the bucket array was hinted after fork. The fix
  cuts real copy-on-write overhead during background saves.
- #4566 logs the module version on load, which is operator-visible.

Signed-off-by: Sarthak Aggarwal <[email protected]>
(cherry picked from commit 097567a)
sarthakaggarwal97 added a commit that referenced this pull request Sep 16, 2026
Remove three entries whose changes shipped before 9.2.0, so 9.1 users
don't see them advertised as new:
- #3533 (dismissHashtable madvise size) was backported to 9.1 and is in
  the 9.1.0, 9.1.1 and 9.1.2 tags. It was added here by mistake.
- #3551 (hashtable iterator invalidate on exhaustion) is likewise in
  9.1.0; it just never made the 9.1 notes.
- #3586 (valkey-cli --cluster fix slot spreading) is already documented
  in both the 9.0 and 9.1 release notes and shipped in 9.0.6 and 9.1.0.

Fix the #4076 config name: the registered config is
priority-preemptive-poll-interval-us, not preemptive-poll-interval-us,
so the name as written would be rejected by CONFIG SET.

Rewrite the #4005 entry, which described only the internal tagging. The
user-facing surface is two new configs, priority-subnets and
maxclients-reserved, which together cap normal clients at maxclients
minus the reserved count so administrative clients keep guaranteed
slots, plus a connected_priority_clients field in INFO clients.

Move the sorted set B+ tree note (#4359) back to Performance. Listing it
as a behavior change for its OBJECT ENCODING output while #3212 changes
hash encoding output from hashtable to listpack in the Performance
section was inconsistent; both now sit together.

Drop the Redis comparison from the #4629 entry, which no other entry in
the 9.0, 9.1 or 9.2 notes makes.

Signed-off-by: Sarthak Aggarwal <[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.

2 participants