Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Four values, whose meanings are given below, are calculated^12 :

❑ distressis the key indicator as to how urgently the kernel needs fresh memory. It is calculated
using theprev_priorityvalue for right-shifting the fixed value 100.prev_priorityspecifies
the priority with which the zone had to be scanned during the lasttry_to_free_pagesrun
until the required number of pages was freed. Notice that the lowerprev_priorityis, the higher
the priority. The shift operations produce the followingdistressvalues for various priorities:

Priority Distress
70
61
53
46
312
225
150
0 100

Allpriorityvalues greater than 7 yield adistressfactor of 0. While 0 ensures the kernel that
there is no problem at all, 100 indicates massive trouble.
❑ mapped_ratioindicates the ratio of mapped memory pages (not only used to cache data but also
explicitly requested by processes to store data) to the total available memory. The ratio is calcu-
lated by dividing the current number of mapped pages by the total number of pages available at
system start. The result is scaled to a percentage value by multiplying by 100.
❑ mapped_ratiois used only to calculate a further value that is calledswap_tendencyand — as its
name suggests — indicates the swap tendency of the system. You are already familiar with the
first two calculation variables.sc_swappinessis an additional kernel parameter that is usually
based on the setting in/proc/sys/vm/swappiness.
❑ If there is a large imbalance between the lengths of the active and inactive lists, the kernel allows
swapping and page reclaim to happen more easily than usual to balance the situation. However,
some effort is made that large imbalances do not have much influence at lowswappinessvalues.
❑ The kernel now reduces all the information calculated so far to a truth value that answers the
following question: Are mapped pages to be swapped out or not?
Ifswap_tendencyis greater than or equal to 100, mapped pages are also swapped out, and
reclaim_mappedis set to 1. Otherwise, the variable retains its default value of 0 so that pages are
only reclaimed from the page cache.
Asvm_swappinessis added toswap_tendency, the administrator can enable the swapping of
mapped pages at any time regardless of the other system parameters by assigning the value of
100 to the variable.

Thelru_add_drainprocedure, which is invoked after the parameters have been calculated, distributes
the data currently held in the LRU cache to the system’s LRU lists. In contrast tolru_cache_add,touched
upon in Section 18.6.2, copying is performed when the temporary caches contain at least one element, not
only when they are completely filled.

(^12) The individual formulas were derived heuristically and are designed to guarantee good performance in many different situations.

Free download pdf