Code

View on GitHub

Lazy allocation #

make large_mmap
./large_mmap

Monitor memory usage:

watch -n 0.2 'ps -o pid,vsz,rss,comm -p $(pidof large_mmap)'

Monitor page fault events:

sudo perf stat -p $(pidof large_mmap) -e page-faults -I 1000

Observe perf counter going up with each page fault and RSS growing.

Follow-up: allow huge page mapping.

PF cost #

make pf_cost

Run few times:

./pf_cost

Observe large timing discrepancy between 1st and 2nd passes. Follow-up: allow huge page mapping.

Memory overcommit #

Inspect current memory state:

LANG=en watch -n0.2 free -h

Disable swap if you have one:

sudo swapoff -a

Then try to allocate something:

make alloc
./alloc 100

Obviously large overallocations are disallowed.

Try however to allocate slightly more than available:

./alloc 30

Inspect OOM killer events:

journalctl -k | grep -i "Out  of memory"