hashtable: fix dismissHashtable madvise size#3533
Open
charsyam wants to merge 1 commit intovalkey-io:unstablefrom
Open
hashtable: fix dismissHashtable madvise size#3533charsyam wants to merge 1 commit intovalkey-io:unstablefrom
charsyam wants to merge 1 commit intovalkey-io:unstablefrom
Conversation
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
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.
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().