Outline of the Linux Memory Management System

Note: as of sometime in mid-2001, all the links to the Linux source code at lxr.linux.no broke when lxr took the verion 2.4.0 code off of their site. I am working on getting another LXR repository set up to remedy this. However, kernel MM development has moved way beyond what's covered on this site; the material here is primarily of historical interest. More current documentation (still in progress, but looking very promising) can be found on Abhi Nayani's site -- JAK

These pages contain my notes on the Linux memory-management system. It is basically an educational experience on my part; while I am familiar with virtual memory management in theory, this is my first practical foray into the field. Hopefully others in the same position will benefit from my experience. I assume the reader has a general idea what "virtual memory" is, and is familiar with the notion of address translation using address-mapping tables (page tables). In the main document I try to present a reasonably organized view of the MM system, but there are occasional links into the vmnotes.html file containing my original stream-of-consciousness attempts to puzzle out various aspects of the code.

I am only looking at single-processor systems at the moment, and when it's necessary to understand platform-specific issues I concentrate on Intel architecture because that's what I have documentation for (though I may add some notes on SH3/SH4 later). Once I'm sure I understand the single-processor issues, I may look at SMP.

In general, for each topic, I first describe the principles embodied in the code at a high level; then I go on to interpret the code in enough detail that I can understand what's going on. If you have questions that aren't answered by my notes, please let me know so I can clarify things. I want to provide enough information so that the code is understandable, but avoid filling pages with fluffy descriptions of stuff that's obvious by looking at the code.

I have a nifty Tcl script that replaces everything that looks like a function, macro, struct, variable, typedef, filename, or line number with a link into the LXR kernel cross-referencer, so from almost anywhere in this text you can click to see the relevant code. Note that the LXR links attempt to open a (single) separate window for you to view the code, so if you click on a link and nothing seems to happen, see if you have a hidden or minimized browser window.

I encourage you to have a look at the Linux MM web site; there is some good documentation there. Especially, I encourage you to have a look at (my slightly edited version of) Paul Wilson's VM outline . That document is somewhat out-of-date, but still provides a nice overview of VM issues generally.

I'd love comments on this page, especially from folks who understand this stuff :-)

OK, enough yakking, here we go.

The basic principle Linux uses to fairly share memory resources is that each physical page of data (each logical page in Paul Wilson's terminology) carries with it a measure of its frequency of use, called its age. The more frequently a page is referenced, the less likely it is to be discarded by the kernel when memory becomes scarce. I'll discuss the details of the code and algorithms first, and then finally describe how it all works together to implement the memory-management policy.

Here are the main pieces of the Linux MM puzzle:

Questions and comments to Joe Knapka

The LXR links in this page were produced by lxrreplace.tcl, which is available for free.

Credits