Syntax highlighting of PageOutKswapd

= Pageout and kswapd =
Most of this page to be written by ''<ams>'' from #mm - ''ams'', I hope the structure of the page will make it easier for you to follow the code.  If you have any questions about the code, I'll try to answer them on #mm -- ''riel''

[[TableOfContents]]
= Efficient use of Memory =
Linux, like most Unix operating systems, tries to use memory as efficiently as possible.  That is, all memory that is not in use by the kernel or processes may be used as file cache, to reduce the number of disk accesses the system has to do.  One consequence of this is that a busy Linux system will constantly run with most of its memory in use, and most memory allocations mean that another page had to be evicted from memory by the pageout code.

Under typical workloads, most of the memory will be in use by the page cache and by processes, which get their memory on demand after a page fault, see PageFaultHandling.  The memory allocator (PageAllocation) will allocate a free page, and activate the pageout code if the number of free pages has fallen too low.

= Asynchronous and Synchronous Pageout =
Most of the time, the rate of page allocations is relatively low.  In this case, the kswapd kernel thread can free memory as fast as it is allocated and the allocating processes can immediately get a memory page when needed, without having to wait for the pageout code.  Having kswapd free memory in the background helps the applications run at maximum speed.

However, sometimes the rate of page allocation is so high that kswapd can not keep up.  When that happens, the applications that are allocating pages will help free pages themselves, by calling the function ''try_to_free_pages''.  This has the effect of throttling the heavy memory allocators and (on NUMA systems) focussing the pageout code on those memory zones which the heavily allocating processes allocate from.

= kswapd =
== balance_pgdat ==
= try_to_free_pages =
= shrink_caches =
= shrink_zone =
== shrink_cache ==
=== shrink_list ===
=== pageout ===
=== swap_page ===
== refill_inactive_zone ==
= Shrink Slab =
Most kernel allocations are done through the slab allocator. Some kernel allocations are caches (eg. inodes and dentries), parts of which can be freed by the pageout code.  However, since each slab has its own data structure, they all need their own replacement algorithms, which are separate from the replacement algorithm used for page cache and process memory.  Usually the slab occupies a fairly small part of memory, and replacement of kernel data structures is beyond the scope of this document.


["