History

memcg: remove memcg_cgroup::id from IDR on mem_cgroup_css_alloc() failure

In case of memcg_online_kmem() failure, memcg_cgroup::id remains hashed in mem_cgroup_idr even after memcg memory is freed. This leads to leak of ID in mem_cgroup_idr. This patch adds removal into mem_cgroup_css_alloc(), which fixes the problem. For better readability, it adds a generic helper which is used in mem_cgroup_alloc() and mem_cgroup_id_put_many() as well.

Kirill Tkhai committed 8 years ago

Commit 7e97de01 parent e30cb131 file · +11 −4Browse files

Unified · Split

mm/memcontrol.c+11−4
@@ -4037,6 +4037,14 @@ static struct cftype mem_cgroup_legacy_files[] = { · 4036 unmodified lines
40374037
40384038 static DEFINE_IDR(mem_cgroup_idr);
40394039
4040+static void mem_cgroup_id_remove(struct mem_cgroup *memcg)
4041+{
4042+ if (memcg->id.id > 0) {
4043+ idr_remove(&mem_cgroup_idr, memcg->id.id);
4044+ memcg->id.id = 0;
4045+ }
4046+}
4047+
40404048 static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
40414049 {
40424050 VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0);
@@ -4047,8 +4055,7 @@ static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n) · 4 unmodified lines
40474055 {
40484056 VM_BUG_ON(atomic_read(&memcg->id.ref) < n);
40494057 if (atomic_sub_and_test(n, &memcg->id.ref)) {
4050− idr_remove(&mem_cgroup_idr, memcg->id.id);
4051− memcg->id.id = 0;
4058+ mem_cgroup_id_remove(memcg);
40524059
40534060 /* Memcg ID pins CSS */
40544061 css_put(&memcg->css);
@@ -4185,8 +4192,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) · 130 unmodified lines
41854192 idr_replace(&mem_cgroup_idr, memcg, memcg->id.id);
41864193 return memcg;
41874194 fail:
4188− if (memcg->id.id > 0)
4189− idr_remove(&mem_cgroup_idr, memcg->id.id);
4195+ mem_cgroup_id_remove(memcg);
41904196 __mem_cgroup_free(memcg);
41914197 return NULL;
41924198 }
@@ -4245,6 +4251,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) · 52 unmodified lines
42454251
42464252 return &memcg->css;
42474253 fail:
4254+ mem_cgroup_id_remove(memcg);
42484255 mem_cgroup_free(memcg);
42494256 return ERR_PTR(-ENOMEM);
42504257 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t