Share memory reduction logic and enable compaction for WSLC#40376
Open
Share memory reduction logic and enable compaction for WSLC#40376
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Linux init memory-reduction logic so it can be shared between the WSL2 init (main.cpp) and WSLC init (WSLCInit.cpp), and enables idle-time compaction + cache dropping for WSLC VMs.
Changes:
- Introduces a shared
UtilStartMemoryReductionThread()entry point inutil.cppand aMemoryReductionModeenum inutil.h. - Updates WSL2 init’s
ConfigureMemoryReduction()to delegate to the shared thread logic. - Starts the memory reduction thread in WSLC init with drop-caches behavior when idle.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/linux/init/util.h | Adds MemoryReductionMode and the shared thread API declaration. |
| src/linux/init/util.cpp | Implements shared idle monitoring + compaction/reclaim thread and moves helpers into util. |
| src/linux/init/main.cpp | Replaces local memory reduction thread logic with a call into UtilStartMemoryReductionThread(). |
| src/linux/init/WSLCInit.cpp | Enables memory reduction thread for WSLC init (drop caches + compaction when idle). |
c49dab8 to
5ae279f
Compare
39ccd6f to
19108ff
Compare
19108ff to
539a091
Compare
OneBlue
reviewed
May 4, 2026
Extract the memory compaction and cache reclaim thread into StartMemoryReductionThread() in util.cpp. WSLC now runs the same idle-based compaction and drop_caches logic that WSL2 uses, improving page reporting efficiency and reducing host memory pressure. - Add StartMemoryReductionThread() and MemoryReductionMode to util.h/cpp - WSL2 main.cpp delegates to shared implementation - WSLC WSLCInit.cpp calls StartMemoryReductionThread(DropCache) - Remove duplicated GetUserCpuTime/GetMemoryInUse from main.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… directly Address PR review feedback: - Remove redundant MemoryReductionMode enum and use the existing wire enum LX_MINI_INIT_MEMORY_RECLAIM_MODE directly, eliminating the unsafe static_cast that could have swapped Gradual/DropCache behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6ebc314 to
96357be
Compare
ProcessMessages may MS_MOVE /proc into the chroot target before invoking chroot(); starting the thread before that window risked failing path lookups under /proc. Defer the thread start until the first successful chroot, guarded by a once_flag so subsequent mount messages don't re-start. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
This PR refactors the Linux init memory-reduction logic so it can be shared between the WSL2 init (
main.cpp) and WSLC init (WSLCInit.cpp), and enables idle-time compaction + cache dropping for WSLC VMs.Changes
StartMemoryReductionThread(LX_MINI_INIT_MEMORY_RECLAIM_MODE)entry point inutil.cpp.GetUserCpuTimeandGetMemoryInUsehelpers toutil.cppas file-local (static) functions.StartMemoryReductionThreaddirectly instead of going throughConfigureMemoryReduction().LX_MINI_INIT_MEMORY_RECLAIM_MODEwire enum directly rather than introducing a separate enum.Notes