天天看点

关于宏PageReserved

宏PageReserved用来检测是否是该页是否为内核代码所用或者该页根本就没有使用。

定义在include/linux/page-flags.h中

#define TESTPAGEFLAG(uname, lname)                                \

static inline int Page##uname(struct page *page)                      \

                     { return test_bit(PG_##lname, &page->flags); }

#define SETPAGEFLAG(uname, lname)                                  \

static inline void SetPage##uname(struct page *page)                \

                     { set_bit(PG_##lname, &page->flags); }

#define CLEARPAGEFLAG(uname, lname)                              \

static inline void ClearPage##uname(struct page *page)                    \

                     { clear_bit(PG_##lname, &page->flags); }

#define PAGEFLAG(uname, lname) TESTPAGEFLAG(uname, lname)             \

       SETPAGEFLAG(uname, lname) CLEARPAGEFLAG(uname, lname)

#define __CLEARPAGEFLAG(uname, lname)                                 \

static inline void __ClearPage##uname(struct page *page)          \

                     { __clear_bit(PG_##lname, &page->flags); }

PAGEFLAG(Reserved, reserved) __CLEARPAGEFLAG(Reserved, reserved)

其中

__clear_bit() is non-atomic,

clear_bit - Clears a bit in memory. clear_bit() is atomic and may not be reordered.

set_bit - Atomically set a bit in memory. set_bit() is atomic and may not be reordered.

至于flag PG_reserved,在ULK第八章里有描述:

PG_reserved:The page frame is reserved for kernel code or is unusable.页框留给内核代码或者没有使用。

enum pageflags {

       PG_locked,           

       PG_error,

       PG_referenced,

       PG_uptodate,

       PG_dirty,

       PG_lru,

       PG_active,

#ifdef CONFIG_FASTFREE

       PG_fastfree,

#endif

       PG_slab,

       PG_owner_priv_1,

       PG_arch_1,

       PG_reserved,

       PG_private,          

       PG_writeback,             

#ifdef CONFIG_PAGEFLAGS_EXTENDED

       PG_head,             

       PG_tail,         

#else

       PG_compound,            

#endif

       PG_swapcache,           

       PG_mappedtodisk,

       PG_reclaim,          

       PG_buddy,           

#ifdef CONFIG_IA64_UNCACHED_ALLOCATOR

       PG_uncached,             

#endif

       __NR_PAGEFLAGS,

       PG_checked = PG_owner_priv_1,

       PG_pinned = PG_owner_priv_1,

       PG_savepinned = PG_dirty,

       PG_slob_page = PG_active,

       PG_slob_free = PG_private,

       PG_slub_frozen = PG_active,

       PG_slub_debug = PG_error,

};