read the transcript!
On Linux, you start new processes using the fork() or clone() system call.
calling fork creates a child process that’s a copy of the caller
the cloned process has EXACTLY the same memory.
- same heap
- same stack
- same memory maps
if the parent has 36B of memory, the child will too.
copying all that memory every time we fork would be slow and a waste of RAM
often processes call
exec right after
fork, which means they don’t use the parent process’s memory basically at all!
so Linux lets them share physical RAM and only copies the memory when one of them tries to write
process: I’d like to change that memory
Linux: okay! I’ll make you your own copy!
Linux does this by giving both the processes identical page tables.
but it marks every page as read only.
when a process tries to write to a shared memory address:
- there’s a page fault=
- Linux makes a copy of the page & updates the page table
- the process continues, blissfully ignorant
process, happily: It’s just like I have my own copy