KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_PAGE_CGROUP_H |
| 2 | #define __LINUX_PAGE_CGROUP_H |
| 3 | |
| 4 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR |
| 5 | #include <linux/bit_spinlock.h> |
| 6 | /* |
| 7 | * Page Cgroup can be considered as an extended mem_map. |
| 8 | * A page_cgroup page is associated with every page descriptor. The |
| 9 | * page_cgroup helps us identify information about the cgroup |
| 10 | * All page cgroups are allocated at boot or memory hotplug event, |
| 11 | * then the page cgroup for pfn always exists. |
| 12 | */ |
| 13 | struct page_cgroup { |
| 14 | unsigned long flags; |
| 15 | struct mem_cgroup *mem_cgroup; |
| 16 | struct page *page; |
| 17 | struct list_head lru; /* per cgroup LRU list */ |
| 18 | }; |
| 19 | |
| 20 | void __init pgdat_page_cgroup_init(struct pglist_data *pgdat); |
| 21 | void __init page_cgroup_init(void); |
| 22 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
| 23 | |
| 24 | enum { |
| 25 | /* flags for mem_cgroup */ |
| 26 | PCG_LOCK, /* page cgroup is locked */ |
| 27 | PCG_CACHE, /* charged as cache */ |
| 28 | PCG_USED, /* this object is in use. */ |
| 29 | /* flags for LRU placement */ |
| 30 | PCG_ACTIVE, /* page is active in this cgroup */ |
| 31 | PCG_FILE, /* page is file system backed */ |
| 32 | PCG_UNEVICTABLE, /* page is unevictableable */ |
| 33 | }; |
| 34 | |
| 35 | #define TESTPCGFLAG(uname, lname) \ |
| 36 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ |
| 37 | { return test_bit(PCG_##lname, &pc->flags); } |
| 38 | |
| 39 | #define SETPCGFLAG(uname, lname) \ |
| 40 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ |
| 41 | { set_bit(PCG_##lname, &pc->flags); } |
| 42 | |
| 43 | #define CLEARPCGFLAG(uname, lname) \ |
| 44 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ |
| 45 | { clear_bit(PCG_##lname, &pc->flags); } |
| 46 | |
| 47 | /* Cache flag is set only once (at allocation) */ |
| 48 | TESTPCGFLAG(Cache, CACHE) |
| 49 | |
| 50 | TESTPCGFLAG(Used, USED) |
| 51 | CLEARPCGFLAG(Used, USED) |
| 52 | |
| 53 | /* LRU management flags (from global-lru definition) */ |
| 54 | TESTPCGFLAG(File, FILE) |
| 55 | SETPCGFLAG(File, FILE) |
| 56 | CLEARPCGFLAG(File, FILE) |
| 57 | |
| 58 | TESTPCGFLAG(Active, ACTIVE) |
| 59 | SETPCGFLAG(Active, ACTIVE) |
| 60 | CLEARPCGFLAG(Active, ACTIVE) |
| 61 | |
| 62 | TESTPCGFLAG(Unevictable, UNEVICTABLE) |
| 63 | SETPCGFLAG(Unevictable, UNEVICTABLE) |
| 64 | CLEARPCGFLAG(Unevictable, UNEVICTABLE) |
| 65 | |
| 66 | static inline int page_cgroup_nid(struct page_cgroup *pc) |
| 67 | { |
| 68 | return page_to_nid(pc->page); |
| 69 | } |
| 70 | |
| 71 | static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc) |
| 72 | { |
| 73 | return page_zonenum(pc->page); |
| 74 | } |
| 75 | |
| 76 | static inline void lock_page_cgroup(struct page_cgroup *pc) |
| 77 | { |
| 78 | bit_spin_lock(PCG_LOCK, &pc->flags); |
| 79 | } |
| 80 | |
| 81 | static inline int trylock_page_cgroup(struct page_cgroup *pc) |
| 82 | { |
| 83 | return bit_spin_trylock(PCG_LOCK, &pc->flags); |
| 84 | } |
| 85 | |
| 86 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
| 87 | { |
| 88 | bit_spin_unlock(PCG_LOCK, &pc->flags); |
| 89 | } |
| 90 | |
| 91 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
| 92 | struct page_cgroup; |
| 93 | |
| 94 | static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) |
| 99 | { |
| 100 | return NULL; |
| 101 | } |
| 102 | #endif |
| 103 | #endif |