Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
Created November 14, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangentstorm/11b3ab5acd300d2e62f5 to your computer and use it in GitHub Desktop.
Save tangentstorm/11b3ab5acd300d2e62f5 to your computer and use it in GitHub Desktop.
(probably not paging) a wild guess about what i think paging might be

Most modern operating systems allow running many programs simultaneously.

There's no way to know how much ram a particular program will need, since this might depend on user actions (like opening a file). This means there's no way for the operating system to allocate a fixed chunk of ram for each process.

Since the amount of ram required by a process may change over time, you might want to leave lots of room for each process to grow.

On the other hand, RAM is a limited resource on a computer, so you want to pack the processes together tightly in ram.

These ideas are in conflict, because if we reserve too much "space to grow" for a process, we may waste too much RAM. But if we don't leave space, then programs may outgrow the space alloted.

This is pretty much the same problem we encounter with memory management inside a program or managing files on a disk.

Anyway, I think paging in ram is similar to allocating blocks on a file system:

  • a page is just a chunk of ram
  • pages can be joined together in a linked list

The linked list allows the cpu or os to create a virtual address space for each process which looks like a continuous region of ram but may actually be quite fragmented on the hardware.

In addition, pages have (at least) three access control bits: readable, writable, and executable. Usually the machine code for a program would be on pages marked 'executable' but not 'writable'. But when you're doing just-in-time compilation, you want to write machine code to a page in ram and then execute it. I can't think of any good reason for a page to be non-readable.

Pages can be shared between programs, allowing interprocess communication.

Pages can also be loaded from and saved to disk. This allows the OS to swap some pages to disk when ram is scarce, and allows some degree of decoupling from the low level hardware. (It's much faster to copy a page from memory to memory than to physically write that page to disk, so programs that use physical storage a lot probably have some kind of copy-on-write magic going on for their pages.)

That's all I can think of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment