From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 926248E0038 for ; Mon, 7 Jan 2019 21:06:40 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id w18so2085548qts.8 for ; Mon, 07 Jan 2019 18:06:40 -0800 (PST) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n202sor28554773qkn.6.2019.01.07.18.06.39 for (Google Transport Security); Mon, 07 Jan 2019 18:06:39 -0800 (PST) Subject: Re: [PATCH v2] kmemleak: survive in a low-memory situation References: <20190102165931.GB6584@arrakis.emea.arm.com> <20190102180619.12392-1-cai@lca.pw> <20190103093201.GB31793@dhcp22.suse.cz> <9197d86b-a684-c7f4-245b-63c890f1104f@lca.pw> <20190103170735.GV31793@dhcp22.suse.cz> <20190107104314.uugftsqcjsi5j6g2@mbp> From: Qian Cai Message-ID: <47dbc0fc-5322-10fb-a8c4-698a4b17e3b3@lca.pw> Date: Mon, 7 Jan 2019 21:06:37 -0500 MIME-Version: 1.0 In-Reply-To: <20190107104314.uugftsqcjsi5j6g2@mbp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas , Michal Hocko Cc: akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org On 1/7/19 5:43 AM, Catalin Marinas wrote: > On Thu, Jan 03, 2019 at 06:07:35PM +0100, Michal Hocko wrote: >>>> On Wed 02-01-19 13:06:19, Qian Cai wrote: >>>> [...] >>>>> diff --git a/mm/kmemleak.c b/mm/kmemleak.c >>>>> index f9d9dc250428..9e1aa3b7df75 100644 >>>>> --- a/mm/kmemleak.c >>>>> +++ b/mm/kmemleak.c >>>>> @@ -576,6 +576,16 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size, >>>>> struct rb_node **link, *rb_parent; >>>>> >>>>> object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); >>>>> +#ifdef CONFIG_PREEMPT_COUNT >>>>> + if (!object) { >>>>> + /* last-ditch effort in a low-memory situation */ >>>>> + if (irqs_disabled() || is_idle_task(current) || in_atomic()) >>>>> + gfp = GFP_ATOMIC; >>>>> + else >>>>> + gfp = gfp_kmemleak_mask(gfp) | __GFP_DIRECT_RECLAIM; >>>>> + object = kmem_cache_alloc(object_cache, gfp); >>>>> + } >>>>> +#endif > [...] >> I will not object to this workaround but I strongly believe that >> kmemleak should rethink the metadata allocation strategy to be really >> robust. > > This would be nice indeed and it was discussed last year. I just haven't > got around to trying anything yet: > > https://marc.info/?l=linux-mm&m=152812489819532 > It could be helpful to apply this 10-line patch first if has no fundamental issue, as it survives probably 50 times running LTP oom* workloads without a single kmemleak allocation failure. Of course, if someone is going to embed kmemleak metadata into slab objects itself soon, this workaround is not needed.