Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


unsigned int inuse; /* SLUB: Nr of objects */
};
union {
struct {
unsigned long private; /* Mapping-private opaque data:
* usually used for buffer_heads
* if PagePrivate set; used for
* swp_entry_t if PageSwapCache;
* indicates order in the buddy
* system if PG_buddy is set.
*/
struct address_space *mapping; /* If low bit clear, points to
* inode address_space, or NULL.
* If page mapped as anonymous
* memory, low bit is set, and
* it points to anon_vma object:
* see PAGE_MAPPING_ANON below.
*/
};
...
struct kmem_cache *slab; /* SLUB: Pointer to slab */
struct page *first_page; /* Compound tail pages */
};
union {
pgoff_t index; /* Our offset within mapping. */
void *freelist; /* SLUB: freelist req. slab lock */
};
struct list_head lru; /* Pageout list, eg. active_list
* protected by zone->lru_lock!
*/
#if defined(WANT_PAGE_VIRTUAL)
void *virtual; /* Kernel virtual address (NULL if
not kmapped, ie. highmem) */
#endif /* WANT_PAGE_VIRTUAL */
};

The elementsslab,freelist,andinuseare used by the slub allocator. We do not need to be concerned
with these special arrangements, and they are not used if support for the slub allocator is not compiled
into the kernel, so I omit them in the following discussion to simplify matters.

Each page frame is described by this structure in an architecture-independent format that does not
depend on the CPU type used. Besides the slub elements, the page structure includes several other ele-
ments that can only be explained accurately in the context of kernel subsystems discussed elsewhere. I
shall nevertheless provide an overview of the contents of the structure, even though this means referenc-
ing later chapters.

❑ flagsstores architecture-independent flags to describe page attributes. I discuss the different
flag options below.
❑ _countis a usage count indicating the number of references to this page in the kernel. When its
value reaches 0, the kernel knows that thepageinstance is not currently in use and can therefore
be removed. If its value is greater than 0, the instance should on no account be removed from
memory. If you are not familiar with reference counters, you should consult Appendix C for
further information.
Free download pdf