From: Catalin Marinas <catalin.marinas@arm.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Qian Cai <cai@lca.pw>,
akpm@linux-foundation.org, mhocko@kernel.org, cl@linux.com,
penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] kmemleaak: survive in a low-memory situation
Date: Tue, 26 Mar 2019 16:20:41 +0000 [thread overview]
Message-ID: <20190326162038.GH33308@arrakis.emea.arm.com> (raw)
In-Reply-To: <20190326160536.GO10344@bombadil.infradead.org>
On Tue, Mar 26, 2019 at 09:05:36AM -0700, Matthew Wilcox wrote:
> On Tue, Mar 26, 2019 at 11:43:38AM -0400, Qian Cai wrote:
> > Unless there is a brave soul to reimplement the kmemleak to embed it's
> > metadata into the tracked memory itself in a foreseeable future, this
> > provides a good balance between enabling kmemleak in a low-memory
> > situation and not introducing too much hackiness into the existing
> > code for now.
>
> I don't understand kmemleak. Kirill pointed me at this a few days ago:
>
> https://gist.github.com/kiryl/3225e235fea390aa2e49bf625bbe83ec
>
> It's caused by the XArray allocating memory using GFP_NOWAIT | __GFP_NOWARN.
> kmemleak then decides it needs to allocate memory to track this memory.
> So it calls kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp));
>
> #define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \
> __GFP_NORETRY | __GFP_NOMEMALLOC | \
> __GFP_NOWARN | __GFP_NOFAIL)
>
> then the page allocator gets to see GFP_NOFAIL | GFP_NOWAIT and gets angry.
>
> But I don't understand why kmemleak needs to mess with the GFP flags at
> all.
Originally, it was just preserving GFP_KERNEL | GFP_ATOMIC. Starting
with commit 6ae4bd1f0bc4 ("kmemleak: Allow kmemleak metadata allocations
to fail"), this mask changed, aimed at making kmemleak allocation
failures less verbose (i.e. just disable it since it's a debug tool).
Commit d9570ee3bd1d ("kmemleak: allow to coexist with fault injection")
introduced __GFP_NOFAIL but this came with its own problems which have
been previously reported (the warning you mentioned is another one of
these). We didn't get to any clear conclusion on how best to allow
allocations to fail with fault injection but not for the kmemleak
metadata. Your suggestion below would probably do the trick.
> Just allocate using the same flags as the caller, and fail the original
> allocation if the kmemleak allocation fails. Like this:
>
> +++ b/mm/slab.h
> @@ -435,12 +435,22 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags,
> for (i = 0; i < size; i++) {
> p[i] = kasan_slab_alloc(s, p[i], flags);
> /* As p[i] might get tagged, call kmemleak hook after KASAN. */
> - kmemleak_alloc_recursive(p[i], s->object_size, 1,
> - s->flags, flags);
> + if (kmemleak_alloc_recursive(p[i], s->object_size, 1,
> + s->flags, flags))
> + goto fail;
> }
>
> if (memcg_kmem_enabled())
> memcg_kmem_put_cache(s);
> + return;
> +
> +fail:
> + while (i > 0) {
> + kasan_blah(...);
> + kmemleak_blah();
> + i--;
> + }
> + free_blah(p);
> + *p = NULL;
> }
>
> #ifndef CONFIG_SLOB
>
>
> and if we had something like this, we wouldn't need kmemleak to have this
> self-disabling or must-succeed property.
We'd still need the self-disabling in place since there are a few other
places where we call kmemleak_alloc() from.
--
Catalin
next prev parent reply other threads:[~2019-03-26 16:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 15:43 Qian Cai
2019-03-26 16:00 ` Christopher Lameter
2019-03-26 16:28 ` Qian Cai
2019-03-26 16:05 ` Matthew Wilcox
2019-03-26 16:20 ` Catalin Marinas [this message]
2019-03-26 16:33 ` Michal Hocko
2019-03-26 16:06 ` Catalin Marinas
2019-03-26 22:52 ` Qian Cai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190326162038.GH33308@arrakis.emea.arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox