Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


set, but when is it going to be removed again? Either the kernel does not remove it automatically, but
then the page would remain in the active state forever even if it would only be used very little, or not at
all anymore. To remove the flag automatically after some specific time-out would require a huge number
of kernel timers because appropriate hardware support is not available on all CPUs supported by Linux.
Considering the large number of pages that are present in a typical system, this approach is also doomed
to fail.

CPU 1

CPU 0

lru_inactive lru_active

lru_add_pvecs lru_add_active_pvecs

1

1

4 3 3 2

SetPageActive
activate_page

shrink_active_list

_ _pagevec_lru_add
2 _ _pagevec_lru_add_active
3 SetPageLRU
4 SetPageActive
Figure 18-12: Page movements between the per-CPU page lists and
the global LRU lists. To simplify matters, only a single zone is used as
the basis of the global lists. Only the most important functions that
move pages between the active and inactive lists are shown.

Having two flags allows for implementing a more sophisticated approach to determining page activity.
The core idea is to use one flag to denote the current activity rating, and another one that signals if the
page has been recently referenced. Both bits need to be set in close cooperation. Figure 18-13 illustrates
the corresponding algorithm. Essentially the following steps are necessary:


  1. If the page is deemed active, thePG_activeflagisset;otherwise,not.Theflagdirectlycorre-
    sponds to the LRU list the page is on, namely, the (zone-specific)inactiveoractivelist.

  2. Each time the page is accessed, the flagPG_referencedis set. The function responsible for
    this ismark_page_accessed, and the kernel must make sure to call it appropriately.

  3. ThePG_referencedflag and information provided by reversemappingareusedtodeter-
    mine page activity. The crucial point is that thePG_referencedflag isremovedeach time an
    activity check is performed.page_referencedis the function that implements this behavior.

  4. Entermark_page_accessedagain. When it finds that thePG_accessedbitisalreadysetwhen
    it checks the page, this means thatnocheck was performed bypage_referenced. The calls

Free download pdf