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 */ |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 6 | PCG_USED = 0x01, /* This page is charged to a memcg */ |
| 7 | PCG_MEM = 0x02, /* This page holds a memory charge */ |
| 8 | PCG_MEMSW = 0x04, /* This page holds a memory+swap charge */ |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 9 | }; |
| 10 | |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 11 | struct pglist_data; |
| 12 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 13 | #ifdef CONFIG_MEMCG |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 14 | struct mem_cgroup; |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 15 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 16 | /* |
| 17 | * Page Cgroup can be considered as an extended mem_map. |
| 18 | * A page_cgroup page is associated with every page descriptor. The |
| 19 | * page_cgroup helps us identify information about the cgroup |
| 20 | * All page cgroups are allocated at boot or memory hotplug event, |
| 21 | * then the page cgroup for pfn always exists. |
| 22 | */ |
| 23 | struct page_cgroup { |
| 24 | unsigned long flags; |
| 25 | struct mem_cgroup *mem_cgroup; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 28 | extern void pgdat_page_cgroup_init(struct pglist_data *pgdat); |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 29 | |
| 30 | #ifdef CONFIG_SPARSEMEM |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 31 | static inline void page_cgroup_init_flatmem(void) |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 32 | { |
| 33 | } |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 34 | extern void page_cgroup_init(void); |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 35 | #else |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 36 | extern void page_cgroup_init_flatmem(void); |
| 37 | static inline void page_cgroup_init(void) |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | #endif |
| 41 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 42 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 43 | |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 44 | static inline int PageCgroupUsed(struct page_cgroup *pc) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 45 | { |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 46 | return !!(pc->flags & PCG_USED); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 47 | } |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 48 | #else /* !CONFIG_MEMCG */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 49 | struct page_cgroup; |
| 50 | |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 51 | static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat) |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
| 55 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) |
| 56 | { |
| 57 | return NULL; |
| 58 | } |
KAMEZAWA Hiroyuki | 94b6da5 | 2008-10-22 14:15:05 -0700 | [diff] [blame] | 59 | |
| 60 | static inline void page_cgroup_init(void) |
| 61 | { |
| 62 | } |
| 63 | |
Vladimir Davydov | 434584f | 2014-08-08 14:19:26 -0700 | [diff] [blame] | 64 | static inline void page_cgroup_init_flatmem(void) |
KAMEZAWA Hiroyuki | ca371c0 | 2009-06-12 10:33:53 +0300 | [diff] [blame] | 65 | { |
| 66 | } |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 67 | #endif /* CONFIG_MEMCG */ |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 68 | |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 69 | #include <linux/swap.h> |
Jaswinder Singh Rajput | 9757275 | 2009-09-20 16:20:44 +0530 | [diff] [blame] | 70 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_MEMCG_SWAP |
Daisuke Nishimura | 0249144 | 2010-03-10 15:22:17 -0800 | [diff] [blame] | 72 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
| 73 | unsigned short old, unsigned short new); |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 74 | 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] | 75 | extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent); |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 76 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
| 77 | extern void swap_cgroup_swapoff(int type); |
| 78 | #else |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 79 | |
| 80 | static inline |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 81 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 82 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 83 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static inline |
Bob Liu | 9fb4b7c | 2012-01-12 17:18:48 -0800 | [diff] [blame] | 87 | unsigned short lookup_swap_cgroup_id(swp_entry_t ent) |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 88 | { |
KAMEZAWA Hiroyuki | a3b2d69 | 2009-04-02 16:57:45 -0700 | [diff] [blame] | 89 | return 0; |
KAMEZAWA Hiroyuki | 27a7faa | 2009-01-07 18:07:58 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static inline int |
| 93 | swap_cgroup_swapon(int type, unsigned long max_pages) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static inline void swap_cgroup_swapoff(int type) |
| 99 | { |
| 100 | return; |
| 101 | } |
| 102 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 103 | #endif /* CONFIG_MEMCG_SWAP */ |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 104 | |
Johannes Weiner | 6b3ae58 | 2011-03-23 16:42:30 -0700 | [diff] [blame] | 105 | #endif /* __LINUX_PAGE_CGROUP_H */ |