Add KSM doctor check and memfd probe evidence#267
Conversation
WaylandYang
left a comment
There was a problem hiding this comment.
Thanks for tackling #5. I think this needs one more proof point before merge.
The implementation marks a controller-side MAP_SHARED memfd mapping as MADV_MERGEABLE, but Linux KSM documentation says KSM only merges private anonymous pages and does not merge page-cache/file-backed pages. Since memfd/shmem MAP_SHARED pages appear to fall on the wrong side of that boundary, this may be a no-op apart from adding a populated controller mapping.
Could you add evidence from /sys/kernel/mm/ksm/pages_shared, pages_sharing, etc. showing that memfd-backed fork families actually merge with this change?
|
No problems. I will verify and add right now. |
|
Thanks, you were right to ask for the counters here. I added But the memfd So I removed the controller-side memfd |
WaylandYang
left a comment
There was a problem hiding this comment.
Thanks for checking the counters and changing direction. This version is much better: it removes the no-op runtime memfd hint, keeps the useful doctor signal, and leaves a reproducible probe/results trail for why the MAP_SHARED memfd path is not the right #5 implementation.
I checked the updated diff: no remaining runtime MADV_MERGEABLE path in forkd-vmm/controller, cargo fmt --check passes locally, and bench/ksm-memfd/probe.py passes py_compile.
|
Merged this updated version into Local checks:
Leaving |
Summary
This updates the #5 follow-up after checking the KSM counters directly.
The original version of this PR tried to mark a controller-side
MAP_SHAREDmemfd mapping asMADV_MERGEABLE. After the review, I added a small probe underbench/ksm-memfd/and ran it against/sys/kernel/mm/ksmcounters. The result matches the concern from review: the anonymous private control case merges, but the memfdMAP_SHAREDcase does not movepages_sharedorpages_sharing.So this PR now removes the misleading memfd-side hint instead of keeping a no-op mapping around. What remains is:
forkd doctorKSM row, so operators can see when KSM is disabled or haspages_to_scan=0;MAP_SHAREDis not the right implementation path for KSM directed hints for fork families #5;This does not claim to fully fix #5 anymore. It narrows the next implementation attempt to a mapping/backing shape KSM actually scans.
Issues
Helps #5 by adding the doctor check and ruling out the memfd
MAP_SHAREDapproach.Documents #257 and #263.
Testing
cargo fmt --checkgit diff --checkcargo test --workspacecargo clippy --workspace --all-targets -- -D warningspython -m py_compile sdk/mcp/forkd_mcp/server.py bench/ksm-memfd/probe.pydocker run --rm --privileged -v "$PWD:/work" -w /work python:3.12-slim bash -lc 'python bench/ksm-memfd/probe.py --pages 4096 --timeout 30'