Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


ZONE_OOM_LOCKED, /* zone is in OOM killer zonelist */
} zone_flags_t;
It is also possible that none of these flags is set. This is the normal state of the zone.
ZONE_ALL_UNRECLAIMABLEis a state that can occur when the kernel tries to reuse some
pages of the zone (page reclaim, see Chapter 18), but this is not possible at all because
all pages arepinned. For instance, a userspace application could have used themlock
system call to instruct the kernel that pages must not be removed from physical memory,
for example, by swapping them out. Such a page is said to be pinned. If all pages in a
zone suffer this fate, the zone is unreclaimable, and the flag is set. To waste no time, the
swapping daemon scans zones of this kind very briefly when it is looking for pages to
reclaim.^2
On SMP systems, multiple CPUs could be tempted to reclaim a zone concurrently. The
flagZONE_RECLAIM_LOCKEDprevents this: If A CPU is reclaiming a zone, it set the flag. This
prevents other CPUs from trying.
ZONE_OOM_LOCKEDis reserved for an unfortunate situation: If processes use up so much
memory that essential operations cannot be completed anymore, then the kernel will try
to select the worst memory eater and kill it to obtain more free pages. The flag prevents
multiple CPUs from getting into their way in this case.
The kernel provides three auxiliary functions to test and set zone flags:
<mmzone.h>
void zone_set_flag(struct zone *zone, zone_flags_t flag)
int zone_test_and_set_flag(struct zone *zone, zone_flags_t flag)
void zone_clear_flag(struct zone *zone, zone_flags_t flag)

zone_set_flagandzone_clear_flagset and clear a certain flag, respectively.zone_test_
and_set_flagfirst tests if a given flag is set and does so if not. The old state of the flag is
returned to the caller.
❑ vm_statkeeps a plethora of statistical information about the zone. Since most of the infor-
mation kept in there will not make much sense at the moment, a detailed discussion is
deferred to Section 17.7.1. For now, it sufficesto know that the information is updated from
places all over the kernel. The auxiliary functionzone_page_stateallows for reading the
information invm_stat:
<vmstat.h>
static inline unsigned long zone_page_state(struct zone *zone,
enum zone_stat_item item)

itemcan, for instance, beNR_ACTIVEorNR_INACTIVEto query the number of active and
inactive pages stored onactive_listandinactive_listdiscussed above. The number of
free pages in the zone is obtained withNR_FREE_PAGES.
❑ prev_prioritystores the priority with which the zone was scanned in the last scan oper-
ation until sufficient page frames were freed intry_to_free_pages(see Chapter 17). As
you shall also see in Chapter 17, the decision as to whether mapped pages are swapped out
depends on this value.

(^2) However, scanning cannot be totally dispensed with becausethe zone may contain reclaimable pages again at some time
in the future. If so, the flag is removed and thekswapddaemon treats the zone again like any other zone.

Free download pdf