cabinet

Cabinet Inspector Session 3

The following session inspects the virtual addresses of an mmap()ed file and shows the changing reference count.


Build everything:

$ make all
gcc -c -Wall -g  cabinet_inspector.c -o cabinet_inspector.o
gcc  cabinet_inspector.o -o cabinet_inspector 
gcc -c -Wall -g  mmapper.c -o mmapper.o
gcc   mmapper.o   -o mmapper
echo "OS is hard" > foo

mmap foo in first process in the background and check its refcount:

$ ./mmapper foo &
[1] 2339
PID 2339: mmap()ed foo to 0x7fb0b81e7000 with size = 11B
read first byte: O
to test, run:
    sudo ./cabinet_inspector 0x7fb0b81e7000 2339

to quit, press CTRL+C or run:
    kill -s INT 2339

$ sudo ./cabinet_inspector 0x7fb0b81e7000 2339
inspecting cabinet for 0x7fb0b81e7000 of pid=2339

[405] inspect_cabinet():
paddr: 0xd8092000
pf_paddr: 0xd8092000
pte_paddr: 0x3501c000
pmd_paddr: 0x35062000
pud_paddr: 0x35250000
p4d_paddr: 0x35250000
pgd_paddr: 0x351de000
dirty: no
refcount: 3

[proc] pagemap:
paddr: 0xd8092000
pf_paddr: 0xd8092000
exclusively mapped: yes
file-page: yes
swapped: no
present: yes

mmap foo in second process in the background and see refcount increase in first process:

$ ./mmapper foo &
[2] 2344
PID 2344: mmap()ed foo to 0x7fd62e3e7000 with size = 11B
read first byte: O
to test, run:
    sudo ./cabinet_inspector 0x7fd62e3e7000 2344

to quit, press CTRL+C or run:
    kill -s INT 2344

$ sudo ./cabinet_inspector 0x7fd62e3e7000 2344
inspecting cabinet for 0x7fd62e3e7000 of pid=2344

[405] inspect_cabinet():
paddr: 0xd8092000
pf_paddr: 0xd8092000
pte_paddr: 0x35201000
pmd_paddr: 0x35013000
pud_paddr: 0x351b3000
p4d_paddr: 0x351b3000
pgd_paddr: 0x351c8000
dirty: no
refcount: 4

[proc] pagemap:
paddr: 0xd8092000
pf_paddr: 0xd8092000
exclusively mapped: no
file-page: yes
swapped: no
present: yes

Kill second process and see refcount decrease in first process:

$ kill -s INT 2344
[2]+  Interrupt               ./mmapper foo

$ sudo ./cabinet_inspector 0x7fb0b81e7000 2339
inspecting cabinet for 0x7fb0b81e7000 of pid=2339

[405] inspect_cabinet():
paddr: 0xd8092000
pf_paddr: 0xd8092000
pte_paddr: 0x3501c000
pmd_paddr: 0x35062000
pud_paddr: 0x35250000
p4d_paddr: 0x35250000
pgd_paddr: 0x351de000
dirty: no
refcount: 3

[proc] pagemap:
paddr: 0xd8092000
pf_paddr: 0xd8092000
exclusively mapped: yes
file-page: yes
swapped: no
present: yes

Finally, clean up:

$ kill -s INT 2339
[1]+  Interrupt               ./mmapper foo