next up previous contents index
Next: 10.4 Page Hash Up: 10. Page Frame Reclamation Previous: 10.2 Page Cache   Contents   Index

10.3 Shrinking all caches

The function responsible for shrinking the various caches is shrink_caches(). It takes a few simple steps to free up some memory. The maximum number of pages that will be written to disk in any given pass is nr_pages which is initialised by try_to_free_pages_zone() to be SWAP_CLUSTER_MAX10.1 The limitation is there so that if kswapd schedules a large number of pages to be swapped to disk, it will sleep occasionally to allow the IO to takes place. As pages are freed, nr_pages is decremented to keep count.

The amount of work that will be performed also depends on the priority initialised by try_to_free_pages_zone() to be DEF_PRIORITY10.2. For each pass that does not free up enough pages, the priority is decremented for the highest priority been 1.

The function first it calls kmem_cache_reap() (See Section 8.1.7) which selects a slab cache to shrink. If nr_pages number of pages are freed, the work is complete and the function returns otherwise it will try to free nr_pages from other caches.

If other caches are the be affected, refill_inactive() to move pages from the active_list to the inactive_list discussed in the next subsection.

Next it shrinks the page cache by reclaiming pages at the end of the inactive_list with shrink_cache(). If there is a large number of pages in the queue that belong to processes, whole processes will be swapped out with swap_out()

Finally it shrinks three special caches, the dcache (shrink_dcache_memory()), the icache (shrink_icache_memory())and the dqcache (shrink_dqcache_memory()). These objects are quite small in themselves but a cascading effect allows a lot more pages to be freed in the form of buffer and disk caches.



\includegraphics[width=17cm]{graphs/shrink_caches.ps}
[1]
Figure: Call Graph: shrink_caches
[2]




Footnotes

...SWAP_CLUSTER_MAX10.1
Currently statically defined as 32 in mm/vmscan.c
...DEF_PRIORITY10.2
Currently statically defined as 6 in mm/vmscan.c

next up previous contents index
Next: 10.4 Page Hash Up: 10. Page Frame Reclamation Previous: 10.2 Page Cache   Contents   Index
Mel 2003-01-14