提交 11d67612 编写于 作者: Y Yafang Shao 提交者: Linus Torvalds

mm, memcg: fix error return value of mem_cgroup_css_alloc()

When I run my memcg testcase which creates lots of memcgs, I found
there're unexpected out of memory logs while there're still enough
available free memory.  The error log is

  mkdir: cannot create directory 'foo.65533': Cannot allocate memory

The reason is when we try to create more than MEM_CGROUP_ID_MAX memcgs,
an -ENOMEM errno will be set by mem_cgroup_css_alloc(), but the right
errno should be -ENOSPC "No space left on device", which is an
appropriate errno for userspace's failed mkdir.

As the errno really misled me, we should make it right.  After this
patch, the error log will be

  mkdir: cannot create directory 'foo.65533': No space left on device

[akpm@linux-foundation.org: s/EBUSY/ENOSPC/, per Michal]
[akpm@linux-foundation.org: s/EBUSY/ENOSPC/, per Michal]
Fixes: 73f576c0 ("mm: memcontrol: fix cgroup creation failure after many small jobs")
Suggested-by: NMatthew Wilcox <willy@infradead.org>
Signed-off-by: NYafang Shao <laoar.shao@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Acked-by: NMichal Hocko <mhocko@kernel.org>
Acked-by: NJohannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Link: http://lkml.kernel.org/r/20200407063621.GA18914@dhcp22.suse.cz
Link: http://lkml.kernel.org/r/1586192163-20099-1-git-send-email-laoar.shao@gmail.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 b5f20061
...@@ -4990,19 +4990,22 @@ static struct mem_cgroup *mem_cgroup_alloc(void) ...@@ -4990,19 +4990,22 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
unsigned int size; unsigned int size;
int node; int node;
int __maybe_unused i; int __maybe_unused i;
long error = -ENOMEM;
size = sizeof(struct mem_cgroup); size = sizeof(struct mem_cgroup);
size += nr_node_ids * sizeof(struct mem_cgroup_per_node *); size += nr_node_ids * sizeof(struct mem_cgroup_per_node *);
memcg = kzalloc(size, GFP_KERNEL); memcg = kzalloc(size, GFP_KERNEL);
if (!memcg) if (!memcg)
return NULL; return ERR_PTR(error);
memcg->id.id = idr_alloc(&mem_cgroup_idr, NULL, memcg->id.id = idr_alloc(&mem_cgroup_idr, NULL,
1, MEM_CGROUP_ID_MAX, 1, MEM_CGROUP_ID_MAX,
GFP_KERNEL); GFP_KERNEL);
if (memcg->id.id < 0) if (memcg->id.id < 0) {
error = memcg->id.id;
goto fail; goto fail;
}
memcg->vmstats_local = alloc_percpu(struct memcg_vmstats_percpu); memcg->vmstats_local = alloc_percpu(struct memcg_vmstats_percpu);
if (!memcg->vmstats_local) if (!memcg->vmstats_local)
...@@ -5046,7 +5049,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) ...@@ -5046,7 +5049,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
fail: fail:
mem_cgroup_id_remove(memcg); mem_cgroup_id_remove(memcg);
__mem_cgroup_free(memcg); __mem_cgroup_free(memcg);
return NULL; return ERR_PTR(error);
} }
static struct cgroup_subsys_state * __ref static struct cgroup_subsys_state * __ref
...@@ -5057,8 +5060,8 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -5057,8 +5060,8 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
long error = -ENOMEM; long error = -ENOMEM;
memcg = mem_cgroup_alloc(); memcg = mem_cgroup_alloc();
if (!memcg) if (IS_ERR(memcg))
return ERR_PTR(error); return ERR_CAST(memcg);
WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX); WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX);
memcg->soft_limit = PAGE_COUNTER_MAX; memcg->soft_limit = PAGE_COUNTER_MAX;
...@@ -5108,7 +5111,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -5108,7 +5111,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
fail: fail:
mem_cgroup_id_remove(memcg); mem_cgroup_id_remove(memcg);
mem_cgroup_free(memcg); mem_cgroup_free(memcg);
return ERR_PTR(-ENOMEM); return ERR_PTR(error);
} }
static int mem_cgroup_css_online(struct cgroup_subsys_state *css) static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册