Linux Memory Manager: Pages

February 21, 2007 by hejian

Page is the basic unit of memory managed by Linux memory manager. Every physical page in the system has a struct page associated:

struct page {
unsigned long flags;
atomic_t _count; /* Usage count, see below. */
atomic_t _mapcount;
union {
struct {
unsigned long private;
struct address_space *mapping;
};
};
pgoff_t index; /* Our offset within mapping. */
struct list_head lru;
};

page->flags describe the status of the page:

#define PG_locked 0 /* Page is locked. Don't touch. */
#define PG_error 1
#define PG_referenced 2
#define PG_uptodate 3
#define PG_dirty 4
#define PG_lru 5
#define PG_active 6
#define PG_slab 7 /* slab debug (Suparna wants this) */
#define PG_checked 8 /* kill me in 2.5.. */
#define PG_arch_1 9
#define PG_reserved 10
#define PG_private 11 /* Has something at ->private */
#define PG_writeback 12 /* Page is under writeback */
#define PG_nosave 13 /* Used for system suspend/resume */
#define PG_compound 14 /* Part of a compound page */
#define PG_swapcache 15 /* Swap page: swp_entry_t in private */
#define PG_mappedtodisk 16 /* Has blocks allocated on-disk */
#define PG_reclaim 17 /* To be reclaimed asap */
#define PG_nosave_free 18 /* Free, should not be written */
#define PG_buddy 19 /* Page is free, on buddy lists */

Compound Page : A compound page is a higher-order page. To enable compound page support in the kernel, “Huge TLB Page Support” must be enabled at compile time. A compound page is composed of more then one page, the first of which is called the “head” page and the remainder of which are called “tail” pages. All compound pages will have the PG_compound bit set in there respective page->flags, and the page->lru.next pointing the the head page.

Leave a Reply

You must be logged in to post a comment.

Wordpress template made by HeJian