aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2011-03-23 19:42:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-23 22:46:28 -0400
commit6b3ae58efca06623c197fd6d91ded4aa3a8fe039 (patch)
tree6460e4e1ce206d391b862a3d398a9e22e33ecb3c /include
parent5564e88ba6fd2f6dcd83a592771810cd84b5ae80 (diff)
memcg: remove direct page_cgroup-to-page pointer
In struct page_cgroup, we have a full word for flags but only a few are reserved. Use the remaining upper bits to encode, depending on configuration, the node or the section, to enable page_cgroup-to-page lookups without a direct pointer. This saves a full word for every page in a system with memory cgroups enabled. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: Minchan Kim <minchan.kim@gmail.com> Cc: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/page_cgroup.h75
1 files changed, 58 insertions, 17 deletions
diff --git a/include/linux/page_cgroup.h b/include/linux/page_cgroup.h
index 6b63679ce8a1..f5de21de31dd 100644
--- a/include/linux/page_cgroup.h
+++ b/include/linux/page_cgroup.h
@@ -1,8 +1,26 @@
1#ifndef __LINUX_PAGE_CGROUP_H 1#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H 2#define __LINUX_PAGE_CGROUP_H
3 3
4enum {
5 /* flags for mem_cgroup */
6 PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */
7 PCG_CACHE, /* charged as cache */
8 PCG_USED, /* this object is in use. */
9 PCG_MIGRATION, /* under page migration */
10 /* flags for mem_cgroup and file and I/O status */
11 PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */
12 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
13 /* No lock in page_cgroup */
14 PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */
15 __NR_PCG_FLAGS,
16};
17
18#ifndef __GENERATING_BOUNDS_H
19#include <generated/bounds.h>
20
4#ifdef CONFIG_CGROUP_MEM_RES_CTLR 21#ifdef CONFIG_CGROUP_MEM_RES_CTLR
5#include <linux/bit_spinlock.h> 22#include <linux/bit_spinlock.h>
23
6/* 24/*
7 * Page Cgroup can be considered as an extended mem_map. 25 * Page Cgroup can be considered as an extended mem_map.
8 * A page_cgroup page is associated with every page descriptor. The 26 * A page_cgroup page is associated with every page descriptor. The
@@ -13,7 +31,6 @@
13struct page_cgroup { 31struct page_cgroup {
14 unsigned long flags; 32 unsigned long flags;
15 struct mem_cgroup *mem_cgroup; 33 struct mem_cgroup *mem_cgroup;
16 struct page *page;
17 struct list_head lru; /* per cgroup LRU list */ 34 struct list_head lru; /* per cgroup LRU list */
18}; 35};
19 36
@@ -32,19 +49,7 @@ static inline void __init page_cgroup_init(void)
32#endif 49#endif
33 50
34struct page_cgroup *lookup_page_cgroup(struct page *page); 51struct page_cgroup *lookup_page_cgroup(struct page *page);
35 52struct page *lookup_cgroup_page(struct page_cgroup *pc);
36enum {
37 /* flags for mem_cgroup */
38 PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */
39 PCG_CACHE, /* charged as cache */
40 PCG_USED, /* this object is in use. */
41 PCG_MIGRATION, /* under page migration */
42 /* flags for mem_cgroup and file and I/O status */
43 PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */
44 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
45 /* No lock in page_cgroup */
46 PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */
47};
48 53
49#define TESTPCGFLAG(uname, lname) \ 54#define TESTPCGFLAG(uname, lname) \
50static inline int PageCgroup##uname(struct page_cgroup *pc) \ 55static inline int PageCgroup##uname(struct page_cgroup *pc) \
@@ -117,6 +122,39 @@ static inline void move_unlock_page_cgroup(struct page_cgroup *pc,
117 local_irq_restore(*flags); 122 local_irq_restore(*flags);
118} 123}
119 124
125#ifdef CONFIG_SPARSEMEM
126#define PCG_ARRAYID_WIDTH SECTIONS_SHIFT
127#else
128#define PCG_ARRAYID_WIDTH NODES_SHIFT
129#endif
130
131#if (PCG_ARRAYID_WIDTH > BITS_PER_LONG - NR_PCG_FLAGS)
132#error Not enough space left in pc->flags to store page_cgroup array IDs
133#endif
134
135/* pc->flags: ARRAY-ID | FLAGS */
136
137#define PCG_ARRAYID_MASK ((1UL << PCG_ARRAYID_WIDTH) - 1)
138
139#define PCG_ARRAYID_OFFSET (BITS_PER_LONG - PCG_ARRAYID_WIDTH)
140/*
141 * Zero the shift count for non-existant fields, to prevent compiler
142 * warnings and ensure references are optimized away.
143 */
144#define PCG_ARRAYID_SHIFT (PCG_ARRAYID_OFFSET * (PCG_ARRAYID_WIDTH != 0))
145
146static inline void set_page_cgroup_array_id(struct page_cgroup *pc,
147 unsigned long id)
148{
149 pc->flags &= ~(PCG_ARRAYID_MASK << PCG_ARRAYID_SHIFT);
150 pc->flags |= (id & PCG_ARRAYID_MASK) << PCG_ARRAYID_SHIFT;
151}
152
153static inline unsigned long page_cgroup_array_id(struct page_cgroup *pc)
154{
155 return (pc->flags >> PCG_ARRAYID_SHIFT) & PCG_ARRAYID_MASK;
156}
157
120#else /* CONFIG_CGROUP_MEM_RES_CTLR */ 158#else /* CONFIG_CGROUP_MEM_RES_CTLR */
121struct page_cgroup; 159struct page_cgroup;
122 160
@@ -137,7 +175,7 @@ static inline void __init page_cgroup_init_flatmem(void)
137{ 175{
138} 176}
139 177
140#endif 178#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
141 179
142#include <linux/swap.h> 180#include <linux/swap.h>
143 181
@@ -173,5 +211,8 @@ static inline void swap_cgroup_swapoff(int type)
173 return; 211 return;
174} 212}
175 213
176#endif 214#endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
177#endif 215
216#endif /* !__GENERATING_BOUNDS_H */
217
218#endif /* __LINUX_PAGE_CGROUP_H */