This is a Rust rewrite of the original C program that demonstrates major page faults by memory-mapping files and reading through them to generate I/O load.
- Memory-maps a file using
mmap(via thememmap2crate) - Uses
posix_fadviseto tell the kernel not to cache the file (POSIX_FADV_DONTNEED) - Reads through the entire file byte by byte to trigger major page faults
- Runs this in a loop to generate sustained I/O load
- Uses
sar -Bto monitor page fault statistics
- Uses Rust's memory safety features while maintaining equivalent functionality
- Uses the
memmap2crate for safe memory mapping - Uses
libccrate for direct system calls likeposix_fadvise - Proper error handling with Rust's
Resulttype - Uses
wrapping_addto handle integer overflow safely
cargo build --release
./target/release/majorfault <filename>cd docker
make -f Makefile.rust build
docker run --rm mjpf-rustsrc/main.rs- Main Rust implementationCargo.toml- Rust project configuration with dependenciesdocker/Dockerfile.rust- Multi-stage Docker build for Rust versiondocker/Makefile.rust- Build automation for Dockerdocker/load.sh- Shell script to run the program in a loop (unchanged)docker/bootsrap.sh- Bootstrap script to start load generation and monitoring (unchanged)
memmap2- Safe memory mappinglibc- Direct access to system calls
The program behaves identically to the original C version:
- Takes a filename as command line argument
- Memory maps the file
- Advises the kernel not to cache it
- Reads through every byte to trigger page faults
- Returns the sum of all bytes as exit code (modulo 256)
This generates major page faults that are visible across containers but the I/O is not multiplied, and can be capped by limiting IOPS.