Re: [BUG] kmemcg limit defeats __GFP_NOFAIL allocation

Michal Hocko
2019-09-04T11:25:05Z

On Wed 04-09-19 18:36:06, Tetsuo Handa wrote:
[...]
> The first bug is that __memcg_kmem_charge_memcg() in mm/memcontrol.c is
> failing to return 0 when it is a __GFP_NOFAIL allocation request.
> We should ignore limits when it is a __GFP_NOFAIL allocation request.

OK, fixing that sounds like a reasonable thing to do.

> If we force __memcg_kmem_charge_memcg() to return 0, then
>
> ----------
> struct page_counter *counter;
> int ret;
>
> + if (gfp & __GFP_NOFAIL)
> + return 0;
> +
> ret = try_charge(memcg, gfp, nr_pages);
> if (ret)
> return ret;
> ----------

This should be more likely something like

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9ec5e12486a7..05a4828edf9d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2820,7 +2820,8 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order,
return ret;

if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
- !page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) {
+ !page_counter_try_charge(&memcg->kmem, nr_pages, &counter) &&
+ !(gfp_mask & __GFP_NOFAIL)) {
cancel_charge(memcg, nr_pages);
return -ENOMEM;
}

> the second bug that alloc_slabmgmt() in mm/slab.c is returning NULL
> when it is a __GFP_NOFAIL allocation request will appear.
> I don't know how to handle this.

I am sorry, I do not follow, why would alloc_slabmgmt return NULL
with forcing gfp_nofail charges?
--
Michal Hocko
SUSE Labs