Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


❑ PG_writebackis set for pages whose contents are in the process of being written back to a block
device.
❑ PG_slabis set for pages that are part of the slab allocator discussed in Section 3.6.
❑ PG_swapcacheis set if the page is in the swap cache; in this case,privatecontains an entry of
typeswap_entry_t(further details are provided in Chapter 18).
❑ When the available amount of memory gets smaller, the kernel tries to periodicallyreclaimpages,
that is, get rid of inactive, unused pages. Chapter 18 discusses the details. Once the kernel has
decided to reclaim a specific page, this is announced by setting thePG_reclaimflag.
❑ PG_buddyis set if the page is free and contained on the lists of the buddy system, that is, the core

The Principle of Slab Allocation


❑ PG_compounddenotes that the page is part of a larger compound page consisting of multiple
adjacent regular pages.

A number of standard macros are defined to check if a page has a specific bit is set, or to manipulate a
bit. Their names follow a certain pattern:

❑ PageXXX(page)checks if a page has thePG_XXXbit set. For instance,PageDirtychecks for the
PG_dirtybit, whilePageActivechecks forPG_active,andsoon.
❑ To set a bit if it is not set and return the previous value,SetPageXXXis provided.
❑ ClearPageXXXunconditionally deletes a specific bit.
❑ TestClearPageXXXclears a bit if it is set, but also returns the previously active value.

Notice that these operations are implemented atomically. Chapter 5 discusses what this means in more
detail.

Often it is necessary to wait until the state of a page changes, and then resume work. Two auxiliary
functions provided by the kernel are of particular interest for us:

<pagemap.h>
void wait_on_page_locked(struct page *page);
void wait_on_page_writeback(struct page *page)

Assume that one part of the kernel wants to wait until a locked page has been unlocked.
wait_on_page_lockedallows for doing this. While how this is technically done is discussed in
Chapter 14, it suffices to know here that after calling the function, the kernel will go to sleep if the page
is locked. Once the page becomes unlocked, the sleeper is automatically woken up and can continue
its work.

wait_on_page_writebackworks similarly, but waits until any pending writeback operations in which
the data contained in the page are synchronized with a block device — a hard disk, for instance — have
been finished.

3.3 Page Tables


Hierarchically linked page tables are used to support the rapid and efficient management of large address
spaces. The principle behind this approach and thebenefits it brings as compared to linear addressing
are discussed in Chapter 1. Here we take a closer look at the technical aspects of implementation.
Free download pdf