Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Whereascountkeeps a record of the number of pages associated with the element,highis a watermark.
If the value ofcountexceedshigh, this indicates that there are too many pages in the list. No explicit
watermark for low fill states is used: When no elements are left, the list is refilled.

listis a doubly linked list that holds the per-CPU pages and is handled using standard methods of the
kernel.

If possible, the per-CPU caches are not filled with individual pages but with multipage chunks.batchis
a guideline to the number of pages to be added in a single pass.

Figure 3-6 illustrates graphically how the data structures of the per-CPU cache are filled on a dual-
processor system.

count = 36
high = 96 batch = 16
count = 16
high = 32 batch = 16

CPU 0

CPU 1 count = 36
high = 96 batch = 16

count = 36
high = 96 batch = 16

Freeing Pages


Cold pages

Figure 3-6: Per-CPU cache on a dual-processor system.

How watermarks are calculated and how the cache data structures are initialized are discussed in more
detail in Section 3.4.2.

Page Frames


Page framesrepresent the smallest unit of system memory, and an instance ofstruct pageis created for
each page in RAM. Kernel programmers take care to keep this structure as small as possible because the
memory of systems even with a moderate RAM configuration is broken down into averylarge number
of pages. For instance, an IA-32 system working with a standard page size of 4 KiB has around 100,000
pages given a main memory size of 384 MiB. Although this memory size is certainly not excessively large
for today’s standards, the number of pages is already considerable.

This is why the kernel makes great efforts to keepstruct pageas small as possible. The sheer number
of pages in a typical system causes even small changes in the structure to lead to a large increase in the
amount of physical memory required to keep allpageinstances.

Keeping the structure small is not exactly simplified by the ubiquity of pages: They are used in many
parts of memory management, and for varying applications. While one part of the kernel absolutely
depends on a specific piece of information being available instruct page, this could be useless for
another part, which itself depends a different piece of information, which could again be completely
useless for the other part, and so on....

ACunionlends itself naturally as a remedy for this problem, even if clarity ofstruct pageis not
increased at first. Consider an example: A physical page can be mapped into the virtual address space via
page tables from multiple places, and the kernel wants to keep track of how many places map the page.
For this end, a counter instruct pagecounts the number of mappings. If a page is used by the slub
Free download pdf