After this documentation was released in July 2003, I was approached by Prentice Hall and asked to write a book on the Linux VM under the Bruce Peren's Open Book Series.

The book is available and called simply "Understanding The Linux Virtual Memory Manager". There is a lot of additional material in the book that is not available here, including details on later 2.4 kernels, introductions to 2.6, a whole new chapter on the shared memory filesystem, coverage of TLB management, a lot more code commentary, countless other additions and clarifications and a CD with lots of cool stuff on it. This material (although now dated and lacking in comparison to the book) will remain available although I obviously encourge you to buy the book from your favourite book store :-) . As the book is under the Bruce Perens Open Book Series, it will be available 90 days after appearing on the book shelves which means it is not available right now. When it is available, it will be downloadable from http://www.phptr.com/perens so check there for more information.

To be fully clear, this webpage is not the actual book.
next up previous contents index
Next: 12.9 Reading/Writing the Swap Up: 12. Swap Management Previous: 12.7 Swapping In Pages   Contents   Index

12.8 Swapping Out Pages

Pages are written out to disk when the pages in the swap cache are laundered. To launder a page, the address_space$\rightarrow$a_ops is consulted to find the appropriate write-out function. In the case of swap, the address_space is swapper_space and the swap operations are contained in swap_aops. The registered write-out function is swap_writepage().

Figure 12.5: Call Graph: sys_writepage()
\includegraphics[width=17cm]{graphs/swap_writepage.ps}

swap_writepage() makes a decision based on what is returned by the function remove_exclusive_swap_page(). remove_exclusive_swap_page() checks if there is any other processes referencing the requested page page in the swap cache by examining the page count with the pagecache_lock held. If no other process does, the page is removed from the swap cache and freed.

If the page was removed from the swap cache, 1 is returned to swap_writepage() which will unlock the page waking any process that was waiting on it. If the page still exists in the swap cache, 0 is returned and rw_swap_page() is called to write the contents of the page out to backing storage.


next up previous contents index
Next: 12.9 Reading/Writing the Swap Up: 12. Swap Management Previous: 12.7 Swapping In Pages   Contents   Index
Mel 2004-02-15