Master the fundamental concepts of memory management through this focused micro-challenge.
/proc/self/pagemap exposes how the kernel maps each virtual page: PFN, present, swapped, soft-dirty bits. It is the userspace microscope for paging behavior without writing a kernel module.
Each 8-byte entry per 4 KB page:
63: present0-54: PFN if presentFor example, reading pagemap for your stack VA tells you the exact physical frame backing the current stack page after a fault.
Tools like smem, pmap, and Chrome's about://memory-internals all read /proc/PID/pagemap to report real per-process memory usage instead of guessing from virtual address space size. Getting a bit offset wrong , present is bit 62, not 61 , silently reports swapped-out pages as resident, exactly the kind of bug that makes memory-usage dashboards lie to operators.
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 mmap regions, touch pages selectively, and decode pagemap entries to print a map of resident pages. The task asks you to confirm demand paging by seeing present bits flip only after access.
Read and parse /proc/self/pagemap.
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