Skip to content

Restrict zmadvise_dontneed_range() to jemalloc builds - #3791

Merged
enjoy-binbin merged 1 commit into
valkey-io:unstablefrom
enjoy-binbin:jemalloc_zmadvise
May 24, 2026
Merged

enjoy-binbin merged 1 commit into
valkey-io:unstablefrom
enjoy-binbin:jemalloc_zmadvise

Conversation

@enjoy-binbin

Copy link
Copy Markdown
Member

Align with zmadvise_dontneed(): gate the helper also on
USE_JEMALLOC so it becomes a no-op outside jemalloc builds.

Align with `zmadvise_dontneed()`: gate the helper also on
`USE_JEMALLOC` so it becomes a no-op outside jemalloc builds.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin
enjoy-binbin requested a review from zuiderkwast May 20, 2026 07:56
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 535f4b5f-21ff-4bdd-8da1-8b61899fe390

📥 Commits

Reviewing files that changed from the base of the PR and between 4b25a70 and 59cc36c.

📒 Files selected for processing (1)
  • src/zmalloc.c

📝 Walkthrough

Walkthrough

The PR refines conditional compilation in the memory allocator. The zmadvise_dontneed_range() function's Linux-specific madvise(MADV_DONTNEED) code path is now compiled only when both USE_JEMALLOC and __linux__ are defined, restricting the optimization to jemalloc-enabled Linux builds.

Changes

zmadvise jemalloc conditioning

Layer / File(s) Summary
jemalloc-specific madvise guard
src/zmalloc.c
The preprocessor guard for zmadvise_dontneed_range() is tightened from #if defined(__linux__) to #if defined(USE_JEMALLOC) && defined(__linux__), ensuring the memory advice optimization compiles only for jemalloc-backed Linux builds.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: restricting zmadvise_dontneed_range() compilation to jemalloc-enabled builds.
Description check ✅ Passed The description clearly relates to the changeset, explaining the alignment with zmadvise_dontneed() and the USE_JEMALLOC gate.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@dvkashapov

Copy link
Copy Markdown
Member

Does it not work without jemalloc or behaviour is different? I thought it is just a syscall in Linux and works with any alloc.

@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.68%. Comparing base (8274099) to head (59cc36c).
⚠️ Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3791      +/-   ##
============================================
- Coverage     76.70%   76.68%   -0.03%     
============================================
  Files           162      162              
  Lines         80697    80697              
============================================
- Hits          61900    61883      -17     
- Misses        18797    18814      +17     
Files with missing lines Coverage Δ
src/zmalloc.c 84.61% <ø> (ø)

... and 19 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.

@enjoy-binbin

Copy link
Copy Markdown
Member Author

Does it not work without jemalloc or behaviour is different? I thought it is just a syscall in Linux and works with any alloc.

It works with any alloc i think. But actually i don't know the details very much, this USE_JEMALLOC is used in the very beginning, like it was introduced in d4bca53. So there might be other reasons here, or perhaps we have only tested this on jemalloc.

        /* Currently we use zmadvise_dontneed only when we use jemalloc with Linux.
         * so we avoid these pointless loops when they're not going to do anything. */

@dvkashapov dvkashapov 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.

Makes sense, LGTM

@enjoy-binbin
enjoy-binbin merged commit cce8f49 into valkey-io:unstable May 24, 2026
62 checks passed
@enjoy-binbin
enjoy-binbin deleted the jemalloc_zmadvise branch May 24, 2026 03:52
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 15, 2026
Align with `zmadvise_dontneed()`: gate the helper also on
`USE_JEMALLOC` so it becomes a no-op outside jemalloc builds.

Signed-off-by: Binbin <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 30, 2026
Align with `zmadvise_dontneed()`: gate the helper also on
`USE_JEMALLOC` so it becomes a no-op outside jemalloc builds.

Signed-off-by: Binbin <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
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)
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