memtools explores page-level memory tracking using two mechanisms:
- Linux
userfaultfdfor demand paging and write-protect tracking mprotect+SIGSEGVfor signal-based dirty-page tracking
The repository contains both a Rust crate and small C++ reference programs that exercise the same ideas.
rust/— primary Rust crate, tests, benchmarks, and demo binariescpp/— small C++ programs foruserfaultfdandSIGSEGVdocs/— design notes and implementation tradeoffs
This is still an experimental systems project. The code is useful, but the repository is organized as a research-oriented prototype rather than a polished library release.
userfaultfdsupport is Linux-onlySIGSEGVtracking is the portability path for non-Linux Unix systems- The current codebase assumes Unix APIs and is not Windows-oriented
From rust/:
cargo build
cargo testRun the demo binary:
cargo runRun the stress binary:
cargo run --bin stressRun benchmarks:
cargo bench --bench simple
cargo bench --bench criterionFrom cpp/:
make runBuild only:
make test-userfaultfd
make test-sigsegvThe Rust crate allows creating memory areas with page-access tracking using
either userfaultfd or SIGSEGV.
Tracked memory can optionally be backed by a storage file descriptor. When present, pages are initialized from that descriptor and modified pages can later be committed back to storage.
If no storage file descriptor is provided, the memory is zero-initialized.
See:
rust/src/main.rsfor the current demo programrust/tests/sigsegv.rsfor the signal-based test flowdocs/design.mdfor deeper implementation notes
userfaultfdavoids the VMA-splitting overhead that comes with repeatedmprotectchanges.- The signal-based path is easier to prototype but harder to compose safely in larger applications because signal handlers are process-global.