Skip to content

Block ValkeyModule_Fork while a save is in progress - #4478

Open
nitaicaro wants to merge 1 commit into
valkey-io:forklessfrom
nitaicaro:forkless-fix-vmfork-during-save
Open

Block ValkeyModule_Fork while a save is in progress#4478
nitaicaro wants to merge 1 commit into
valkey-io:forklessfrom
nitaicaro:forkless-fix-vmfork-during-save

Conversation

@nitaicaro

Copy link
Copy Markdown
Contributor

A forkless save exists to avoid the CoW memory spike of a fork-based save. But the save still writes to the pages of the data it walks (object refcounts, the iterator epoch in object metadata, and rehash state in collections), and the main thread keeps serving writes. So if a fork child is alive during the save, all of those writes trigger CoW.

Before forkless a module could not fork during a save anyway: a save was a child process, and serverFork() allows only one child at a time. Now a forkless save is a background thread, so that check no longer sees it and VM_Fork() slips through. Reject VM_Fork() while any save is in progress to restore the old behavior.

A forkless save exists to avoid the copy-on-write memory spike of a
fork-based save. But the save still writes to the pages of the data it
walks (object refcounts, the iterator epoch in object metadata, and
rehash state in collections), and the main thread keeps serving writes.

If a module fork child is alive during the save, all of those writes
trigger copy-on-write page copies. That brings back the exact memory
spike forkless was made to avoid.

Before forkless a module could not fork during a save anyway: a save was
a child process, and serverFork() allows only one child at a time. A
forkless save is a background thread, so that check no longer sees it and
VM_Fork() slips through. Reject VM_Fork() while any save is in progress
to restore the old behavior.

Signed-off-by: Nitai Caro <caronita@amazon.com>
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 79dd4433-f5c4-430f-bbf1-70ea03a7c5e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.43%. Comparing base (0a50265) to head (6019e17).
⚠️ Report is 4 commits behind head on forkless.

Files with missing lines Patch % Lines
src/module.c 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           forkless    #4478      +/-   ##
============================================
- Coverage     79.69%   79.43%   -0.26%     
============================================
  Files           175      175              
  Lines         94841    93225    -1616     
============================================
- Hits          75581    74054    -1527     
+ Misses        19260    19171      -89     
Files with missing lines Coverage Δ
src/module.c 25.42% <0.00%> (-0.02%) ⬇️

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