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 | |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 4 | enum { |
| 5 | /* flags for mem_cgroup */ |
| 6 | PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */ |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 7 | PCG_USED, /* this object is in use. */ |
| 8 | PCG_MIGRATION, /* under page migration */ |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 9 | __NR_PCG_FLAGS, |
| 10 | }; |
| 11 | |
| 12 | #ifndef __GENERATING_BOUNDS_H |
| 13 | #include <generated/bounds.h> |
| 14 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_MEMCG |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 16 | #include <linux/bit_spinlock.h> |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 17 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 18 | /* |
| 19 | * Page Cgroup can be considered as an extended mem_map. |
| 20 | * A page_cgroup page is associated with every page descriptor. The |
| 21 | * page_cgroup helps us identify information about the cgroup |
| 22 | * All page cgroups are allocated at boot or memory hotplug event, |
| 23 | * then the page cgroup for pfn always exists. |
| 24 | */ |
| 25 | struct page_cgroup { |
| 26 | unsigned long flags; |
| 27 | struct mem_cgroup *mem_cgroup; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 30 | void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 31 | |
| 32 | #ifdef CONFIG_SPARSEMEM |
| 33 | static inline void __init page_cgroup_init_flatmem(void) |
| 34 | { |
| 35 | } |
| 36 | extern void __init page_cgroup_init(void); |
| 37 | #else |
| 38 | void __init page_cgroup_init_flatmem(void); |
| 39 | static inline void __init page_cgroup_init(void) |
| 40 | { |
| 41 | } |
| 42 | #endif |
| 43 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 44 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 45 | struct page *lookup_cgroup_page(struct page_cgroup *pc); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 46 | |
| 47 | #define TESTPCGFLAG(uname, lname) \ |
| 48 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ |
| 49 | { return test_bit(PCG_##lname, &pc->flags); } |
| 50 | |
| 51 | #define SETPCGFLAG(uname, lname) \ |
| 52 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ |
| 53 | { set_bit(PCG_##lname, &pc->flags); } |
| 54 | |
| 55 | #define CLEARPCGFLAG(uname, lname) \ |
| 56 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ |
| 57 | { clear_bit(PCG_##lname, &pc->flags); } |
| 58 | |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 59 | #define TESTCLEARPCGFLAG(uname, lname) \ |
| 60 | static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ |
| 61 | { return test_and_clear_bit(PCG_##lname, &pc->flags); } |
| 62 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 63 | TESTPCGFLAG(Used, USED) |
| 64 | CLEARPCGFLAG(Used, USED) |
Balbir Singh | 4b3bde4 | 2009-09-23 15:56:32 -0700 | [diff] [blame] | 65 | SETPCGFLAG(Used, USED) |
| 66 | |
akpm@linux-foundation.org | ac39cf8 | 2010-05-26 14:42:46 -0700 | [diff] [blame] | 67 | SETPCGFLAG(Migration, MIGRATION) |
| 68 | CLEARPCGFLAG(Migration, MIGRATION) |
| 69 | TESTPCGFLAG(Migration, MIGRATION) |
| 70 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 71 | static inline void lock_page_cgroup(struct page_cgroup *pc) |
| 72 | { |
KAMEZAWA Hiroyuki | dbd4ea7 | 2011-01-13 15:47:38 -0800 | [diff] [blame] | 73 | /* |
| 74 | * Don't take this lock in IRQ context. |
KAMEZAWA Hiroyuki | b2402857 | 2012-03-21 16:34:22 -0700 | [diff] [blame] | 75 | * This lock is for pc->mem_cgroup, USED, MIGRATION |
KAMEZAWA Hiroyuki | dbd4ea7 | 2011-01-13 15:47:38 -0800 | [diff] [blame] | 76 | */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 77 | bit_spin_lock(PCG_LOCK, &pc->flags); |
| 78 | } |
| 79 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 80 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
| 81 | { |
| 82 | bit_spin_unlock(PCG_LOCK, &pc->flags); |
| 83 | } |
| 84 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 85 | #else /* CONFIG_MEMCG */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 86 | struct page_cgroup; |
| 87 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 88 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 89 | { |
| 90 | } |
| 91 | |
| 92 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) |
| 93 | { |
| 94 | return NULL; |
| 95 | } |
KAMEZAWA Hiroyuki | 94b6da5 | 2008-10-22 14:15:05 -0700 | [diff] [blame] | 96 | |
| 97 | static inline void page_cgroup_init(void) |
| 98 | { |
| 99 | } |
| 100 | |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 101 | static inline void __init page_cgroup_init_flatmem(void) |
| 102 | { |
| 103 | } |
| 104 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 105 | #endif /* CONFIG_MEMCG */ |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 106 | |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 107 | #include <linux/swap.h> |
Jaswinder Singh Rajput | 9757275 | 2009-09-20 16:20:44 +0530 | [diff] [blame] | 108 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_MEMCG_SWAP |
Daisuke Nishimura | 0249144 | 2010-03-10 15:22:17 -0800 | [diff] [blame] | 110 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
| 111 | unsigned short old, unsigned short new); |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 112 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
Bob Liu | 9fb4b7c | 2012-01-12 17:18:48 -0800 | [diff] [blame] | 113 | extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent); |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 114 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
| 115 | extern void swap_cgroup_swapoff(int type); |
| 116 | #else |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 117 | |
| 118 | static inline |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 119 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 120 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 121 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static inline |
Bob Liu | 9fb4b7c | 2012-01-12 17:18:48 -0800 | [diff] [blame] | 125 | unsigned short lookup_swap_cgroup_id(swp_entry_t ent) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 126 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 127 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static inline int |
| 131 | swap_cgroup_swapon(int type, unsigned long max_pages) |
| 132 | { |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static inline void swap_cgroup_swapoff(int type) |
| 137 | { |
| 138 | return; |
| 139 | } |
| 140 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 141 | #endif /* CONFIG_MEMCG_SWAP */ |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 142 | |
| 143 | #endif /* !__GENERATING_BOUNDS_H */ |
| 144 | |
| 145 | #endif /* __LINUX_PAGE_CGROUP_H */ |