Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, Bite Size Linux!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript". get the zine!
read the transcript!

every Linux process has a page table

* page table *

virtual memory address physical memory address
0x19723000 0x1422000
0x19724000 0x1423000
0x1524000 not in memory
0x1844000 0x4a000 read only

some pages are marked as either:

  • read only
  • not resident in memory

when you try to access a page that’s marked “not resident in memory” it triggers a ! page fault !

what happens during a page fault?

  • the MMU sends an interrupt
  • your program stops running
  • Linux kernel code to handle the page fault runs

Linux, represented by a box with a smiley face: I’ll fix the problem and let your program keep running

“not resident in memory” usually means the data is on disk!

virtual memory: Illustration of a bar that is about 60% filled in purple, labelled “in RAM”. The remaining 40% is filled in orange and labelled “on disk”

Having some virtual memory that is actually on disk is how swap and nmap work

how swap works

  1. run out of RAM
    Illustration where RAM bar is completely full, disk bar still has lots of room

  2. Linux saves some RAM data to disk
    Some of the RAM bar has now been moved over to the disk bar

  3. mark those pages as “not resident in memory” in the page table
    There are arrows between the RAM and disk bars, and the empty portion of the RAM bar is labelled “not resident”

  4. When a program tries to access the memory, there’s a ! page fault !

  5. Linux: time to move some data back to RAM!
    Illustration of virtual memory and RAM, with arrows running back and forth between them

  6. if this happens a lot, your program gets VERY SLOW
    program, sadly: I’m always waiting for data to be moved in & out of RAM