Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


allocator (a means to subdivide complete pages into into smaller portions, see Section 3.6.1), then it is
guaranteed to be only used by the kernel and not from somewhere else, so the map count information is
superfluous. Instead, the kernel can reinterpret the field to denote how many small memory objects into
which a page is subdivided are in use. The double interpretation looks as follows in the data structure
definition:

<mm_types.h>
struct page {
...
union {
atomic_t _mapcount; /* Count of ptes mapped in mms,
* to show when page is mapped
* & limit reverse map searches.
*/
unsigned int inuse; /* SLUB: Nr of objects */
};
...
}

Note thatatomic_tandunsigned intare two different data types — the first allows for changing values
atomically, that is, safe against concurrent access, while the second is a classical integer.atomic_tpro-
vides 32 bits,^6 and an integer also provides this many bits on each architecture supported by Linux. Now
it could be tempting to ‘‘simplify’’ the definition as follows:

struct page {
...
atomic_t counter;
...
}

This would bebadstyle, though, and is completely unacceptable to the kernel developers. The slub code
does not need atomicity to access its object counter, and this should also be reflected in the data type.
And, most importantly, readability of the code will suffer in both subsystems. While_mapcountand
inuseprovide a clear and concise description of what the element is about,countercould mean almost
everything.

Definition ofpage


The structure is defined as follows:

<mm.h>
struct page {
unsigned long flags; /* Atomic flags, some possibly
* updated asynchronously */
atomic_t _count; /* Usage count, see below. */
union {
atomic_t _mapcount; /* Count of ptes mapped in mms,
* to show when page is mapped
* & limit reverse map searches.
*/

(^6) Before kernel 2.6.3, this was not true. The Sparc architecture could only provide 24 bits for atomic manipulation, so the generic code
for all architecture needed to stick to this limit. Luckily, this problem has been resolved now by improvements in the Sparc specific
code.

Free download pdf