Master the fundamental concepts of memory management through this focused micro-challenge.
mmap() establishes a virtual mapping backed by a file or anonymous pages. The kernel creates VMA metadata first; physical pages often arrive on first touch via demand paging.
Typical sequence:
vm_area_struct with prot flags and file offsetFor example, mapping 1 MB read-only at 0x7F00_0000 from a database file lets the OS lazily read 4096-byte pages instead of loading the whole file at mmap time.
mmap() is the same syscall the dynamic linker uses to map shared libraries into a process and that glibc's malloc calls directly once an allocation crosses its mmap threshold, bypassing the heap entirely. Confusing MAP_PRIVATE with MAP_SHARED is a classic production bug: one silently writes your changes back to the underlying file, the other never does.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will simulate VMA creation and a fault handler that installs mappings on demand. This task asks you to distinguish MAP_PRIVATE copy-on-write behavior from shared mappings.
Implement mmap() and page fault handling simulation.
Requirements:
Success Criteria:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github