Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4448682img; Tue, 26 Mar 2019 09:34:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRWGIqOH8e1UsFric3qXdVYBjC/5HANIUxkaCqFNN4OKWrujKs5bZ3DvQ2gFb74/hIPBXe X-Received: by 2002:a65:410a:: with SMTP id w10mr29625132pgp.206.1553618093921; Tue, 26 Mar 2019 09:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553618093; cv=none; d=google.com; s=arc-20160816; b=R8adnRupWreFjmvnXBui4L/WEPqoGs0Cozfw/qnBbB6ORfKgw1Ny+x0qo3VIOGHRZW HU9sdJBwLOhpJNAYmjw9k3WqkrUekI3lTrqXVLUDT2HVfLGxFOPOAGCWuj72pV6Syebs vPuKr+JnFYe0VWq+dd1YnkYW3CGX9EvV+CUEoHRHwqKoFCtg7VlwC3Qeb7k5QDLxOvIN U1U6Jff17R3r8UOJX2+AsI/oGgFTRuvsRY50LFB4fx5toEMI8H6YatD2cpVeTbUuJj9w 6KBW26sidT5rwBSc6LulMvvEDOBNva4gL9MBAbX0bgRgKVIuLATxtkMK7jtDGBV4NV57 0EEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=H+7OVsvEwhn5IgvoV7terYZ4TNjyjLp8FU/v4rcpkwM=; b=FxDkcgnKYMQyKq1cRGAB32XJdE+8ZNKLpgpPo6ognXFUEhMRJGMwLnkwNVgTO4SYsz /TJNi52wVrUvGxOrjB/ammiVi2YU/zJ82TjbKJtS30/1LIM94aF82lhoWZcgBZYCidWf dZLNMHwsUdWFaS9N2B8dzDzUjAPA2wRA0xkB5I1ztBK9zOw1DoCu8NzDOoCNTEYAZSLB p129TbSSTh3/bWWQiDvyTok4wC0K8ft2iloFAPHHtzvwdziR9WzyZ/ZFb9XGzxCxVQVu 2tKEdJnOpmhg0K5/O0dwX3kDOTrKRpaOKU84TTlJH7mbpoNncGZ5dIsuVHsNKsOeW7iI jW7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si18084777plc.190.2019.03.26.09.34.38; Tue, 26 Mar 2019 09:34:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731540AbfCZQeB (ORCPT + 99 others); Tue, 26 Mar 2019 12:34:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:43340 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726175AbfCZQeA (ORCPT ); Tue, 26 Mar 2019 12:34:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9CD33ABC1; Tue, 26 Mar 2019 16:33:59 +0000 (UTC) Date: Tue, 26 Mar 2019 17:33:56 +0100 From: Michal Hocko To: Catalin Marinas Cc: Matthew Wilcox , Qian Cai , 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 Subject: Re: [PATCH v3] kmemleaak: survive in a low-memory situation Message-ID: <20190326163356.GS28406@dhcp22.suse.cz> References: <20190326154338.20594-1-cai@lca.pw> <20190326160536.GO10344@bombadil.infradead.org> <20190326162038.GH33308@arrakis.emea.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190326162038.GH33308@arrakis.emea.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 26-03-19 16:20:41, Catalin Marinas wrote: > 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. I have objected to that on several occasions. An implicit __GFP_NOFAIL is simply broken and __GFP_NOWAIT allocations are a shiny example of that. You cannot loop inside the allocator for an unbound amount of time potentially with locks held. I have heard that there are some plans to deal with that but nothing has really materialized AFAIK. d9570ee3bd1d should be reverted I believe. The proper way around is to keep a pool objects and keep spare objects for restrected allocation contexts. -- Michal Hocko SUSE Labs