diff options
author | Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | 2012-07-31 19:42:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-31 21:42:41 -0400 |
commit | da1def55919f4852c4759249a78d63a0c5d2d8f9 (patch) | |
tree | 9397a43deef85cf9c7f94671593454d77605d2b2 /mm/hugetlb_cgroup.c | |
parent | 6d76dcf40405144a448040a350fd214ddc243d5e (diff) |
hugetlb/cgroup: add support for cgroup removal
Add support for cgroup removal. If we don't have parent cgroup, the
charges are moved to root cgroup.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: David Rientjes <rientjes@google.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Hillf Danton <dhillf@gmail.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/hugetlb_cgroup.c')
-rw-r--r-- | mm/hugetlb_cgroup.c | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 63e04cfa437d..bc518bedea98 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c | |||
@@ -105,10 +105,76 @@ static void hugetlb_cgroup_destroy(struct cgroup *cgroup) | |||
105 | kfree(h_cgroup); | 105 | kfree(h_cgroup); |
106 | } | 106 | } |
107 | 107 | ||
108 | |||
109 | /* | ||
110 | * Should be called with hugetlb_lock held. | ||
111 | * Since we are holding hugetlb_lock, pages cannot get moved from | ||
112 | * active list or uncharged from the cgroup, So no need to get | ||
113 | * page reference and test for page active here. This function | ||
114 | * cannot fail. | ||
115 | */ | ||
116 | static void hugetlb_cgroup_move_parent(int idx, struct cgroup *cgroup, | ||
117 | struct page *page) | ||
118 | { | ||
119 | int csize; | ||
120 | struct res_counter *counter; | ||
121 | struct res_counter *fail_res; | ||
122 | struct hugetlb_cgroup *page_hcg; | ||
123 | struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup); | ||
124 | struct hugetlb_cgroup *parent = parent_hugetlb_cgroup(cgroup); | ||
125 | |||
126 | page_hcg = hugetlb_cgroup_from_page(page); | ||
127 | /* | ||
128 | * We can have pages in active list without any cgroup | ||
129 | * ie, hugepage with less than 3 pages. We can safely | ||
130 | * ignore those pages. | ||
131 | */ | ||
132 | if (!page_hcg || page_hcg != h_cg) | ||
133 | goto out; | ||
134 | |||
135 | csize = PAGE_SIZE << compound_order(page); | ||
136 | if (!parent) { | ||
137 | parent = root_h_cgroup; | ||
138 | /* root has no limit */ | ||
139 | res_counter_charge_nofail(&parent->hugepage[idx], | ||
140 | csize, &fail_res); | ||
141 | } | ||
142 | counter = &h_cg->hugepage[idx]; | ||
143 | res_counter_uncharge_until(counter, counter->parent, csize); | ||
144 | |||
145 | set_hugetlb_cgroup(page, parent); | ||
146 | out: | ||
147 | return; | ||
148 | } | ||
149 | |||
150 | /* | ||
151 | * Force the hugetlb cgroup to empty the hugetlb resources by moving them to | ||
152 | * the parent cgroup. | ||
153 | */ | ||
108 | static int hugetlb_cgroup_pre_destroy(struct cgroup *cgroup) | 154 | static int hugetlb_cgroup_pre_destroy(struct cgroup *cgroup) |
109 | { | 155 | { |
110 | /* We will add the cgroup removal support in later patches */ | 156 | struct hstate *h; |
111 | return -EBUSY; | 157 | struct page *page; |
158 | int ret = 0, idx = 0; | ||
159 | |||
160 | do { | ||
161 | if (cgroup_task_count(cgroup) || | ||
162 | !list_empty(&cgroup->children)) { | ||
163 | ret = -EBUSY; | ||
164 | goto out; | ||
165 | } | ||
166 | for_each_hstate(h) { | ||
167 | spin_lock(&hugetlb_lock); | ||
168 | list_for_each_entry(page, &h->hugepage_activelist, lru) | ||
169 | hugetlb_cgroup_move_parent(idx, cgroup, page); | ||
170 | |||
171 | spin_unlock(&hugetlb_lock); | ||
172 | idx++; | ||
173 | } | ||
174 | cond_resched(); | ||
175 | } while (hugetlb_cgroup_have_usage(cgroup)); | ||
176 | out: | ||
177 | return ret; | ||
112 | } | 178 | } |
113 | 179 | ||
114 | int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, | 180 | int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |