diff options
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 57 |
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 | ||
21 | struct cgroup_subsys mem_cgroup_subsys; | 25 | struct 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 | ||
70 | static inline | ||
71 | struct 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 | |||
77 | void 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 | |||
86 | void mm_free_cgroup(struct mm_struct *mm) | ||
87 | { | ||
88 | css_put(&mm->mem_cgroup->css); | ||
89 | } | ||
90 | |||
91 | void page_assign_page_cgroup(struct page *page, struct page_cgroup *pc) | ||
92 | { | ||
93 | page->page_cgroup = (unsigned long)pc; | ||
94 | } | ||
95 | |||
96 | struct page_cgroup *page_get_page_cgroup(struct page *page) | ||
97 | { | ||
98 | return page->page_cgroup; | ||
99 | } | ||
100 | |||
59 | static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft, | 101 | static 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 | ||
136 | static struct mem_cgroup init_mem_cgroup; | ||
137 | |||
94 | static struct cgroup_subsys_state * | 138 | static struct cgroup_subsys_state * |
95 | mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) | 139 | mem_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 | }; |