From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53F22CD5BAA for ; Thu, 5 Sep 2024 11:26:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C159B6B00C2; Thu, 5 Sep 2024 07:26:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC5CC6B00C6; Thu, 5 Sep 2024 07:26:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A656A6B00ED; Thu, 5 Sep 2024 07:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8789C6B00C2 for ; Thu, 5 Sep 2024 07:26:55 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 37A0081BC1 for ; Thu, 5 Sep 2024 11:26:55 +0000 (UTC) X-FDA: 82530457590.22.17F9745 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by imf22.hostedemail.com (Postfix) with ESMTP id 3048AC0013 for ; Thu, 5 Sep 2024 11:26:52 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=O2m+LQX2; spf=pass (imf22.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725535484; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MT1b/AWbDQ4Zc2FSXLwenhXbbMScTqyTjSATBO5zm2Q=; b=mImsrhW7qSr0x/m8lQzCK+vSRSXmA7FELUPhPY5AuWIWh3UOtV5MhxWGqc5XryxiFpsK4B HBNwbiTITdCrQzT8H4npihNzaR7ajpb8hsbCemBJPiB9wzPU912Au0O1wlnUQYT2fenQUa 4Q+RtQ/arzKw4PN5UmMULbAC3kNNuy4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=O2m+LQX2; spf=pass (imf22.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725535484; a=rsa-sha256; cv=none; b=gmC6iYymWCfEEGGhepP8WfljlXHzId/7ajxFGUx8tDjucVMgiUbwNY9uJMafA9+UHPGC5p LTJ/UaNawf8bvNVKqvq2Q0ZwKYN94muUyJLLhzNEyzcinoQHer32AgBKFIU1Yrw3uaCmfp 2qT9d2XMpBKvBk9IsRzRQfcH+M6ZN2Q= Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5334c4cc17fso748390e87.2 for ; Thu, 05 Sep 2024 04:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1725535611; x=1726140411; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=MT1b/AWbDQ4Zc2FSXLwenhXbbMScTqyTjSATBO5zm2Q=; b=O2m+LQX2Q8NPculvCcpAMMeyD5caqrP0dSZTKiMAC1KXlMMGIsVsj3qoV779Q67FNu kxpi89rUR8UoKQ8EqacqsuE0AKDXcYk6eAuij32bOtXP3uZ0tYTgxpW1i4qyifE/Yd7p f4hAUEgzHp+/S2Zy/VWIk0pTVE07isvaaxKgHDI2JTjQZblRXvwo4cJy6bGdW4l8axEy 7QRdLbE4BPnyAfg9gqjTpZDf+laJMfP0GTrfsNVnDZW+hj8oH4SK/rBlhdK8vUQxLPzR A3Uo340nSjr0iVRpQrbBVSgcGIfgXhOPdBw1/aMMv3FXwP2e5CTtYF+zb7Whs4zsxNmb iFcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535611; x=1726140411; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MT1b/AWbDQ4Zc2FSXLwenhXbbMScTqyTjSATBO5zm2Q=; b=IpZM27snjX6TZ+2eCwGP665A2INvd+xtvhoCknNrJnB9ZxdlQsBt13IOilgmvuQ1CT k5RQijcQ1yYABBTnqh+Tb+il+3b8aNsXCUKPqACzKVUZVwVmRBU0oJoUftlTpIuUwVPw H4rC8TZVwOU9+Y+srOzKjzB1WNav1PuPEwe/BazFtSiIL40WmfJndySIc94lnwDDtKWa tkUJZUHIWqWdwHd7L+vu3ByKAKMreOyIpLVq2ciFIFIim6/rQJMZICfwg2/nu8vJ+m6B kLT/EbcRJ91yQy7clE7WzYAvAOELfc2f99796iLErp8Kh4eXO12vn8vcdgynF92Z3muw 1FAg== X-Forwarded-Encrypted: i=1; AJvYcCUbnX2YUnzsL+0GqiBx1zirZaxBAgBLl/ice+vkXm0ZEKWD8itx4kGhuiaeG3bhPGsQYCd2+Pi4cQ==@kvack.org X-Gm-Message-State: AOJu0YyoDFfvUf+fVHZXXj4dbRxVBgrDqrhEnsqzN79q1oBbPEYNL1IO kUFGj07CtiPqYofeCTuetIz+IXi2J320D8tzw7m2HmySGU+KGOSjet5soA+sx2I= X-Google-Smtp-Source: AGHT+IEtrnolfEptjFfOHaUd4JcPGLaKbwZaBjtKbHZL9CqfOihD83PJlSp/4jz+xU32g7o2FRHYcQ== X-Received: by 2002:a05:6512:230c:b0:530:ad7d:8957 with SMTP id 2adb3069b0e04-53546bb3b33mr14872842e87.49.1725535611082; Thu, 05 Sep 2024 04:26:51 -0700 (PDT) Received: from localhost ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a764794c9sm55307966b.1.2024.09.05.04.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 04:26:50 -0700 (PDT) Date: Thu, 5 Sep 2024 13:26:50 +0200 From: Michal Hocko To: Kent Overstreet Cc: Andrew Morton , Christoph Hellwig , Yafang Shao , jack@suse.cz, Vlastimil Babka , Dave Chinner , Christian Brauner , Alexander Viro , Paul Moore , James Morris , "Serge E. Hallyn" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-bcachefs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2 v2] remove PF_MEMALLOC_NORECLAIM Message-ID: References: <20240902095203.1559361-1-mhocko@kernel.org> <20240902145252.1d2590dbed417d223b896a00@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3048AC0013 X-Stat-Signature: 6f39n6jss4ejcc7b4ycp7dfb8ofeh3b9 X-Rspam-User: X-HE-Tag: 1725535612-287531 X-HE-Meta: U2FsdGVkX1/dSb1Jg8A2yZr3Sq2kASfdWrO9irjpoKruOk6vAgpvxOgYHH1CT1EnVLE+BQiruqgPnFo9NbOIfOZrjslOvf0OXjVrNWTCSUqV8JshxdfQPmcmTEbMB82cU/Z2Ej5+uK7Vp1QgSY+8cBKIW9jwR8DXtjXyWFvCGP53ZBhQLRc/QgxpB07xF0lMmDItUTg0YYKrpTZcmqK8qsHZz61OS7t7XRRJV0aPA1m+aI2wuRdVni7FEWUJ6IcFnqQ4pxntwiVIA5oFQmEZSGoTpysuYjDGZJk/OTsa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E/aVjc50obvDfTodIkBUtJeRNnpboYovw5XbzoXDEhrlcra5ANWg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed 04-09-24 14:03:13, Kent Overstreet wrote: > On Wed, Sep 04, 2024 at 06:46:00PM GMT, Michal Hocko wrote: > > On Wed 04-09-24 12:05:56, Kent Overstreet wrote: > > > On Wed, Sep 04, 2024 at 09:14:29AM GMT, Michal Hocko wrote: > > > > On Tue 03-09-24 19:53:41, Kent Overstreet wrote: > > > > [...] > > > > > However, if we agreed that GFP_NOFAIL meant "only fail if it is not > > > > > possible to satisfy this allocation" (and I have been arguing that that > > > > > is the only sane meaning) - then that could lead to a lot of error paths > > > > > getting simpler. > > > > > > > > > > Because there are a lot of places where there's essentially no good > > > > > reason to bubble up an -ENOMEM to userspace; if we're actually out of > > > > > memory the current allocation is just one out of many and not > > > > > particularly special, better to let the oom killer handle it... > > > > > > > > This is exactly GFP_KERNEL semantic for low order allocations or > > > > kvmalloc for that matter. They simply never fail unless couple of corner > > > > cases - e.g. the allocating task is an oom victim and all of the oom > > > > memory reserves have been consumed. This is where we call "not possible > > > > to allocate". > > > > > > *nod* > > > > > > Which does beg the question of why GFP_NOFAIL exists. > > > > Exactly for the reason that even rare failure is not acceptable and > > there is no way to handle it other than keep retrying. Typical code was > > while (!(ptr = kmalloc())) > > ; > > But is it _rare_ failure, or _no_ failure? > > You seem to be saying (and I just reviewed the code, it looks like > you're right) that there is essentially no difference in behaviour > between GFP_KERNEL and GFP_NOFAIL. The fundamental difference is that (appart from unsupported allocation mode/size) the latter never returns NULL and you can rely on that fact. Our docummentation says: * %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller * cannot handle allocation failures. The allocation could block * indefinitely but will never return with failure. Testing for * failure is pointless. > So given that - why the wart? > > I think we might be able to chalk it up to history; I'd have to go > spunking through the history (or ask Dave or Ted, maybe they'll chime > in), but I suspect GFP_KERNEL didn't provide such strong guarantees when > the allocation loops & GFP_NOFAIL were introduced. Sure, go ahead. If you manage to remove all existing users of __GFP_NOFAIL (without replacing them with retry loops in the caller) then I would be more than happy to remove __GFP_NOFAIL in the allocator. [...] > > But the point is there are some which _do_ need this. We have discussed > > that in other email thread where you have heard why XFS and EXT4 does > > that and why they are not going to change that model. > > No, I agree that they need the strong guarantees. > > But if there's an actual bug, returning an error is better than killing > the task. Killing the task is really bad; these allocations are deep in > contexts where locks and refcounts are held, and the system will just > grind to a halt. Not sure what you mean by these allocations but I am not aware that any of the existing user would be really buggy. Also as I've said elsewhere, there is simply no good way to handle a buggy caller. Killing the buggy context has some downsides, returning NULL has others. I have argued that the former has better predictable behavior than potentially silent failure. We can clearly disagree on this but I also do not see why that is relevant to the original discussion because my argument against PF_MEMALLOC_NORECLAIM was focused on correct GPF_NOFAIL nested context that would get an unexpected failure mode. No matter what kind of failure mode that is it would be unexpected for those users. > > > But as a matter of policy going forward, yes we should be saying that > > > even GFP_NOFAIL allocations should be checking for -ENOMEM. > > > > I argue that such NOFAIL semantic has no well defined semantic and legit > > users are forced to do > > while (!(ptr = kmalloc(GFP_NOFAIL))) ; > > or > > BUG_ON(!(ptr = kmalloc(GFP_NOFAIL))); > > > > So it has no real reason to exist. > > I'm arguing that it does, provided when it returns NULL is defined to > be: > - invalid allocation context > - a size that is so big that it will never be possible to satisfy. Those are not really important situations because you are arguing about a buggy code that needs fixing. As said above we can argue how to deal with those users to get a predictable behavior but as the matter of fact, correct users can expect never seeing the failure so handling failure might be a) impossible and b) unfeasible (i.e. you are adding a dead code that is never tested). [...] > For large allocations in bcachefs: in journal replay we read all the > keys in the journal, and then we create a big flat array with references > to all of those keys to sort and dedup them. > > We haven't hit the INT_MAX size limit there yet, but filesystem sizes > being what they are, we will soon. I've heard of users with 150 TB > filesystems, and once the fsck scalability issues are sorted we'll be > aiming for petabytes. Dirty keys in the journal scales more with system > memory, but I'm leasing machines right now with a quarter terabyte of > ram. I thought you were arguing about bcachefs handling failure mode so presumably you do not need to use __GFP_NOFAIL for those. I am sorry but I am getting lost in these arguments. -- Michal Hocko SUSE Labs