Frequently Asked Question

How does the kernel manage memory?

Every process sees a private virtual address space, on x86-64 a 48-bit window of 256 TB. The kernel maintains page tables that translate virtual addresses to physical pages, 4 KB at a time (with 2 MB and 1 GB huge pages as options). When a process touches an address with no mapping, the CPU raises a page fault and the kernel decides what to do: allocate a fresh page (anonymous memory), read from disk (file-backed memory), swap a page back in, or kill the process (SIGSEGV).

The same physical page can be mapped read-only into many processes, that's how shared libraries and fork()'s copy-on-write work. Free physical memory is managed by the buddy allocator; the slab allocators (SLAB/SLUB/SLOB) carve those pages into kernel data structures. You can see the breakdown in /proc/meminfo.

Video

Further reading and video