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 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 20 | void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 21 | |
| 22 | #ifdef CONFIG_SPARSEMEM |
| 23 | static inline void __init page_cgroup_init_flatmem(void) |
| 24 | { |
| 25 | } |
| 26 | extern void __init page_cgroup_init(void); |
| 27 | #else |
| 28 | void __init page_cgroup_init_flatmem(void); |
| 29 | static inline void __init page_cgroup_init(void) |
| 30 | { |
| 31 | } |
| 32 | #endif |
| 33 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 34 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
| 35 | |
| 36 | enum { |
| 37 | /* flags for mem_cgroup */ |
| 38 | PCG_LOCK, /* page cgroup is locked */ |
| 39 | PCG_CACHE, /* charged as cache */ |
| 40 | PCG_USED, /* this object is in use. */ |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 41 | PCG_ACCT_LRU, /* page has been accounted for */ |
KAMEZAWA Hiroyuki | 8725d54 | 2010-04-06 14:35:05 -0700 | [diff] [blame] | 42 | PCG_FILE_MAPPED, /* page is accounted as "mapped" */ |
akpm@linux-foundation.org | ac39cf8 | 2010-05-26 14:42:46 -0700 | [diff] [blame] | 43 | PCG_MIGRATION, /* under page migration */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | #define TESTPCGFLAG(uname, lname) \ |
| 47 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ |
| 48 | { return test_bit(PCG_##lname, &pc->flags); } |
| 49 | |
| 50 | #define SETPCGFLAG(uname, lname) \ |
| 51 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ |
| 52 | { set_bit(PCG_##lname, &pc->flags); } |
| 53 | |
| 54 | #define CLEARPCGFLAG(uname, lname) \ |
| 55 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ |
| 56 | { clear_bit(PCG_##lname, &pc->flags); } |
| 57 | |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 58 | #define TESTCLEARPCGFLAG(uname, lname) \ |
| 59 | static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ |
| 60 | { return test_and_clear_bit(PCG_##lname, &pc->flags); } |
| 61 | |
Daisuke Nishimura | 57f9fd7d | 2009-12-15 16:47:11 -0800 | [diff] [blame] | 62 | TESTPCGFLAG(Locked, LOCK) |
| 63 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 64 | /* Cache flag is set only once (at allocation) */ |
| 65 | TESTPCGFLAG(Cache, CACHE) |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 66 | CLEARPCGFLAG(Cache, CACHE) |
| 67 | SETPCGFLAG(Cache, CACHE) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 68 | |
| 69 | TESTPCGFLAG(Used, USED) |
| 70 | CLEARPCGFLAG(Used, USED) |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 71 | SETPCGFLAG(Used, USED) |
| 72 | |
| 73 | SETPCGFLAG(AcctLRU, ACCT_LRU) |
| 74 | CLEARPCGFLAG(AcctLRU, ACCT_LRU) |
| 75 | TESTPCGFLAG(AcctLRU, ACCT_LRU) |
| 76 | TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 77 | |
KAMEZAWA Hiroyuki | 8725d54 | 2010-04-06 14:35:05 -0700 | [diff] [blame] | 78 | |
| 79 | SETPCGFLAG(FileMapped, FILE_MAPPED) |
| 80 | CLEARPCGFLAG(FileMapped, FILE_MAPPED) |
| 81 | TESTPCGFLAG(FileMapped, FILE_MAPPED) |
| 82 | |
akpm@linux-foundation.org | ac39cf8 | 2010-05-26 14:42:46 -0700 | [diff] [blame] | 83 | SETPCGFLAG(Migration, MIGRATION) |
| 84 | CLEARPCGFLAG(Migration, MIGRATION) |
| 85 | TESTPCGFLAG(Migration, MIGRATION) |
| 86 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 87 | static inline int page_cgroup_nid(struct page_cgroup *pc) |
| 88 | { |
| 89 | return page_to_nid(pc->page); |
| 90 | } |
| 91 | |
| 92 | static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc) |
| 93 | { |
| 94 | return page_zonenum(pc->page); |
| 95 | } |
| 96 | |
| 97 | static inline void lock_page_cgroup(struct page_cgroup *pc) |
| 98 | { |
| 99 | bit_spin_lock(PCG_LOCK, &pc->flags); |
| 100 | } |
| 101 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 102 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
| 103 | { |
| 104 | bit_spin_unlock(PCG_LOCK, &pc->flags); |
| 105 | } |
| 106 | |
| 107 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
| 108 | struct page_cgroup; |
| 109 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 110 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 111 | { |
| 112 | } |
| 113 | |
| 114 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) |
| 115 | { |
| 116 | return NULL; |
| 117 | } |
KAMEZAWA Hiroyuki | 94b6da5 | 2008-10-22 14:15:05 -0700 | [diff] [blame] | 118 | |
| 119 | static inline void page_cgroup_init(void) |
| 120 | { |
| 121 | } |
| 122 | |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 123 | static inline void __init page_cgroup_init_flatmem(void) |
| 124 | { |
| 125 | } |
| 126 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 127 | #endif |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 128 | |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 129 | #include <linux/swap.h> |
Jaswinder Singh Rajput | 9757275 | 2009-09-20 16:20:44 +0530 | [diff] [blame] | 130 | |
| 131 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP |
Daisuke Nishimura | 0249144 | 2010-03-10 15:22:17 -0800 | [diff] [blame] | 132 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
| 133 | unsigned short old, unsigned short new); |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 134 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
| 135 | extern unsigned short lookup_swap_cgroup(swp_entry_t ent); |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 136 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
| 137 | extern void swap_cgroup_swapoff(int type); |
| 138 | #else |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 139 | |
| 140 | static inline |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 141 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 142 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 143 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static inline |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 147 | unsigned short lookup_swap_cgroup(swp_entry_t ent) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 148 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 149 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static inline int |
| 153 | swap_cgroup_swapon(int type, unsigned long max_pages) |
| 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static inline void swap_cgroup_swapoff(int type) |
| 159 | { |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | #endif |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 164 | #endif |