aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorPavel Emelianov <xemul@openvz.org>2008-02-07 03:13:51 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 11:42:18 -0500
commit78fb74669e80883323391090e4d26d17fe29488f (patch)
tree9154b703510415ae87bdae8750c1054e79710c61 /mm
parent8cdea7c05454260c0d4d83503949c358eb131d17 (diff)
Memory controller: accounting setup
Basic setup routines, the mm_struct has a pointer to the cgroup that it belongs to and the the page has a page_cgroup associated with it. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: Paul Menage <menage@google.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: Kirill Korotaev <dev@sw.ru> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c57
1 files changed, 53 insertions, 4 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 80e48cd9d0c7..4d4805eb37c7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3,6 +3,9 @@
3 * Copyright IBM Corporation, 2007 3 * Copyright IBM Corporation, 2007
4 * Author Balbir Singh <balbir@linux.vnet.ibm.com> 4 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
5 * 5 *
6 * Copyright 2007 OpenVZ SWsoft Inc
7 * Author: Pavel Emelianov <xemul@openvz.org>
8 *
6 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -17,6 +20,7 @@
17#include <linux/res_counter.h> 20#include <linux/res_counter.h>
18#include <linux/memcontrol.h> 21#include <linux/memcontrol.h>
19#include <linux/cgroup.h> 22#include <linux/cgroup.h>
23#include <linux/mm.h>
20 24
21struct cgroup_subsys mem_cgroup_subsys; 25struct cgroup_subsys mem_cgroup_subsys;
22 26
@@ -35,6 +39,13 @@ struct mem_cgroup {
35 * the counter to account for memory usage 39 * the counter to account for memory usage
36 */ 40 */
37 struct res_counter res; 41 struct res_counter res;
42 /*
43 * Per cgroup active and inactive list, similar to the
44 * per zone LRU lists.
45 * TODO: Consider making these lists per zone
46 */
47 struct list_head active_list;
48 struct list_head inactive_list;
38}; 49};
39 50
40/* 51/*
@@ -56,6 +67,37 @@ struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
56 css); 67 css);
57} 68}
58 69
70static inline
71struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
72{
73 return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
74 struct mem_cgroup, css);
75}
76
77void mm_init_cgroup(struct mm_struct *mm, struct task_struct *p)
78{
79 struct mem_cgroup *mem;
80
81 mem = mem_cgroup_from_task(p);
82 css_get(&mem->css);
83 mm->mem_cgroup = mem;
84}
85
86void mm_free_cgroup(struct mm_struct *mm)
87{
88 css_put(&mm->mem_cgroup->css);
89}
90
91void page_assign_page_cgroup(struct page *page, struct page_cgroup *pc)
92{
93 page->page_cgroup = (unsigned long)pc;
94}
95
96struct page_cgroup *page_get_page_cgroup(struct page *page)
97{
98 return page->page_cgroup;
99}
100
59static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft, 101static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft,
60 struct file *file, char __user *userbuf, size_t nbytes, 102 struct file *file, char __user *userbuf, size_t nbytes,
61 loff_t *ppos) 103 loff_t *ppos)
@@ -91,14 +133,21 @@ static struct cftype mem_cgroup_files[] = {
91 }, 133 },
92}; 134};
93 135
136static struct mem_cgroup init_mem_cgroup;
137
94static struct cgroup_subsys_state * 138static struct cgroup_subsys_state *
95mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) 139mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
96{ 140{
97 struct mem_cgroup *mem; 141 struct mem_cgroup *mem;
98 142
99 mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL); 143 if (unlikely((cont->parent) == NULL)) {
100 if (!mem) 144 mem = &init_mem_cgroup;
101 return -ENOMEM; 145 init_mm.mem_cgroup = mem;
146 } else
147 mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
148
149 if (mem == NULL)
150 return NULL;
102 151
103 res_counter_init(&mem->res); 152 res_counter_init(&mem->res);
104 return &mem->css; 153 return &mem->css;
@@ -123,5 +172,5 @@ struct cgroup_subsys mem_cgroup_subsys = {
123 .create = mem_cgroup_create, 172 .create = mem_cgroup_create,
124 .destroy = mem_cgroup_destroy, 173 .destroy = mem_cgroup_destroy,
125 .populate = mem_cgroup_populate, 174 .populate = mem_cgroup_populate,
126 .early_init = 0, 175 .early_init = 1,
127}; 176};