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 A688ACA0ED3 for ; Wed, 4 Sep 2024 07:22:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 225808D0230; Wed, 4 Sep 2024 03:22:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AF258D0228; Wed, 4 Sep 2024 03:22:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0282E8D0230; Wed, 4 Sep 2024 03:22:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D3A798D0228 for ; Wed, 4 Sep 2024 03:22:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05CC7C0B90 for ; Wed, 4 Sep 2024 07:22:29 +0000 (UTC) X-FDA: 82526212818.18.3BCEEE5 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf02.hostedemail.com (Postfix) with ESMTP id D7A6480003 for ; Wed, 4 Sep 2024 07:22:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=fACWfBID; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.45 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=1725434451; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wh+WjO/eVoggYon1VI8AmiDiYT97jA+3Yp6qqo8Bz0o=; b=S0p1wg8LZPb2EQ6X1MSAzZnxpGPM1C7CeLI7ZgIqX6QQsNHz0BaB00R8vK9j2zpye9qmwX gX1hkCIMZWpbqgGn0F0Ota/8J+PeYKIINdtMb5ekvZykr6rFiCBprJxDvgOEYm0Ibs6J8v yPFpTOzyLSmowQI6kOv5KbeTpOho1b0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725434451; a=rsa-sha256; cv=none; b=Qw4sJj8KVMibDACf+x5uXVXQy9CBmijzjAEN7nLsRzFvJGgNLJAnqoK7IXgTEOCx6sk6Dv ruSwkCj5mzwPevPy8w7d3R1TEsM/FEEMFT3jLHA3Bbq39f3u6FtLQOA0WuRpFqfABmJve4 f8eXDApMsU8tpEXpZugCAV1MSJGAJ4E= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=fACWfBID; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-53349ee42a9so8317526e87.3 for ; Wed, 04 Sep 2024 00:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1725434545; x=1726039345; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Wh+WjO/eVoggYon1VI8AmiDiYT97jA+3Yp6qqo8Bz0o=; b=fACWfBID+GivLImD/it3AVVlIxaJ4QSsQdRIzeFr+wiU7us00ULTwQLr14F3HKmwzp ESapy2nIJzVLka5j6gNG1hEFbVAC4VxZHzQiibR743q+BYbtfZFji/M7UtXMbn9W3SgP z6p84MKstbnJbqqZsZLqTkn2qXSgfaKW0yADl5gR5BoT0DWFsAY8KbYiAfM2YmMmRWn4 3hm2oolRP5NNnd/UmePoHQhA9t/zBWq/5PfLD7OjR9APKSJcOOgwCwMCLqKQ1tIiL0uv f6h6HXUA5PNeYgOyvlmfctAe/XPuMOASNLeaNv088+Dx4y61qTVyqYzN+9n4ROZEAeBS 1Gnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434545; x=1726039345; h=in-reply-to:content-transfer-encoding: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=Wh+WjO/eVoggYon1VI8AmiDiYT97jA+3Yp6qqo8Bz0o=; b=uDRnaQ2NSoJS0Hkqv1N2TIM57OAexBmyIMIG0htckFKuHTfHnVXTJMrImeq9SJhEuc FDjeeIOzkqxbxC6H3LtiSJiekd4tQwmsPcIXyMsVRaIghiC2PnDHUBgAqprSkRLk14dv 5/3UqAIsZnVf34Qd94C0Prp9fnyfvgtw6HYuMc3tASxKG26jvMvMxUMhsbLrDXQGehsM yYXQY8GYfeQhbJXqUpzrGwfW1Rjz/IL1vGyUgJ7vlPX3nxHBa3UFde6LlWQkZvSKYcSz 6yUhLCMMOj7YeTMIljANpRlqZtvDEtMaRhdY4kxmEl+iarpuwA3dhpFVzK4TWjfWNmGN QQNA== X-Forwarded-Encrypted: i=1; AJvYcCXiXNqe4a9pMGYjTXJFblY0YWwHwjY0eEg6Gu0ijc3EynP21djVxLha7u4LfPmRWipYUJmMSW2phw==@kvack.org X-Gm-Message-State: AOJu0Yzh3fPdorTXlQvbI20Ry1QuIB9+oZIxHSqWxg4rAUNgPL3jt+fi z8mGooSMcabUk9BuHsiOwMHyIAP6yXa5W1XgR6pQhlg3WSeAmdKawwkukg2cw3w= X-Google-Smtp-Source: AGHT+IG8z0kaSoq4W+20UCPAYQ/4EbWJkmc6rjz/n9sR4m5vvJuQveaRcmhYFgcpH0WFXJDIfkD49A== X-Received: by 2002:a05:6512:3350:b0:534:543e:1895 with SMTP id 2adb3069b0e04-53546bab3damr7960271e87.39.1725434544882; Wed, 04 Sep 2024 00:22:24 -0700 (PDT) Received: from localhost (109-81-82-19.rct.o2.cz. [109.81.82.19]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898919686bsm764838666b.134.2024.09.04.00.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:22:24 -0700 (PDT) Date: Wed, 4 Sep 2024 09:22:23 +0200 From: Michal Hocko To: Barry Song <21cnbao@gmail.com> Cc: 42.hyeyoo@gmail.com, akpm@linux-foundation.org, cl@linux.com, david@redhat.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, laoar.shao@gmail.com, linux-mm@kvack.org, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, virtualization@lists.linux.dev Subject: Re: [PATCH v4 3/3] mm: warn about illegal __GFP_NOFAIL usage in a more appropriate location and manner Message-ID: References: <20240903223935.1697-1-21cnbao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240903223935.1697-1-21cnbao@gmail.com> X-Stat-Signature: 6f3f8t7enmntgu3z4akp7pucp43kema9 X-Rspamd-Queue-Id: D7A6480003 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725434546-295489 X-HE-Meta: U2FsdGVkX1/v6IYvGxEimSgehiW61XzOIXBlYZxsZeMpnHT1zgR2uldBF1ekkkfip9tYO9/8fof81PRSC+kUX/iEEjjWSdE2Nr0z0Ex043+24YoY3xeeQAtKSEZUD12s7Yo3wiraVFWL8SAg7OJWM9piKoO5/3N9b+BtGzCdGlMEOaUOZCh0WivswPHPtDbGxBZHV4jRY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RjuTWx8axAWt7zkkAsOxG/6IFq8+fUBf2ksmFKZP2zIZDoPk6W5QmQ8vQe2cfhP0+MB1LvvDS1kKsshyIfKj+B7KgcYXv41BTUpOr/Cd8pkp9JOsDU54g790x4uNGuu7EF2FgmSWLmnoZ7x3GwAN59+TvOYueZDz1GzToTGu30LMsGKz5myVtwW5NhhFK+ESzSWfocrx2Jpbv13OXPSQwzE4YII1gxPneNVkBBEOvZsAOeTyudbTocobuAJI3pzCKioJ2Ui3FYoBRdpEhKa3l9iB50JKQ== 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 10:39:35, Barry Song wrote: > On Mon, Sep 2, 2024 at 7:58 PM Michal Hocko wrote: > > > > On Sat 31-08-24 08:28:23, Barry Song wrote: > > > From: Barry Song > > > > > > Three points for this change: > > > > > > 1. We should consolidate all warnings in one place. Currently, the > > >    order > 1 warning is in the hotpath, while others are in less > > >    likely scenarios. Moving all warnings to the slowpath will reduce > > >    the overhead for order > 1 and increase the visibility of other > > >    warnings. > > > > > > 2. We currently have two warnings for order: one for order > 1 in > > >    the hotpath and another for order > costly_order in the laziest > > >    path. I suggest standardizing on order > 1 since it’s been in > > >    use for a long time. > > > > > > 3. We don't need to check for __GFP_NOWARN in this case. __GFP_NOWARN > > >    is meant to suppress allocation failure reports, but here we're > > >    dealing with bug detection, not allocation failures. So replace > > >    WARN_ON_ONCE_GFP by WARN_ON_ONCE. > > > > > > Suggested-by: Vlastimil Babka > > > Signed-off-by: Barry Song > > > > Acked-by: Michal Hocko > > > > Updating the doc about order > 1 sounds like it would still fall into > > the scope of this patch. I don not think we absolutely have to document > > each unsupported gfp flags combination for GFP_NOFAIL but the order is a > > good addition with a note that kvmalloc should be used instead in such a > > case. > > Hi Andrew, > If there are no objections from Michal and David, could you please > squash the following: > > >From fc7a2a49e8d0811d706d13d2080393274f316806 Mon Sep 17 00:00:00 2001 > From: Barry Song > Date: Wed, 4 Sep 2024 10:26:19 +1200 > Subject: [PATCH] mm: also update the doc for __GFP_NOFAIL with order > 1 > > Obviously we only support order <= 1 __GFP_NOFAIL allocation and if > someone wants larger memory, they should consider using kvmalloc() > instead. > > Suggested-by: David Hildenbrand > Suggested-by: Michal Hocko > Signed-off-by: Barry Song LGTM. Thanks! > --- > include/linux/gfp_types.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h > index 4a1fa7706b0c..65db9349f905 100644 > --- a/include/linux/gfp_types.h > +++ b/include/linux/gfp_types.h > @@ -253,7 +253,8 @@ enum { > * used only when there is no reasonable failure policy) but it is > * definitely preferable to use the flag rather than opencode endless > * loop around allocator. > - * Using this flag for costly allocations is _highly_ discouraged. > + * Allocating pages from the buddy with __GFP_NOFAIL and order > 1 is > + * not supported. Please consider using kvmalloc() instead. > */ > #define __GFP_IO ((__force gfp_t)___GFP_IO) > #define __GFP_FS ((__force gfp_t)___GFP_FS) > -- > 2.34.1 > > > > > > > --- > > >  mm/page_alloc.c | 50 ++++++++++++++++++++++++------------------------- > > >  1 file changed, 25 insertions(+), 25 deletions(-) > > > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > > index c81ee5662cc7..e790b4227322 100644 > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -3033,12 +3033,6 @@ struct page *rmqueue(struct zone *preferred_zone, > > >  { > > >       struct page *page; > > > > > > -     /* > > > -      * We most definitely don't want callers attempting to > > > -      * allocate greater than order-1 page units with __GFP_NOFAIL. > > > -      */ > > > -     WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1)); > > > - > > >       if (likely(pcp_allowed_order(order))) { > > >               page = rmqueue_pcplist(preferred_zone, zone, order, > > >                                      migratetype, alloc_flags); > > > @@ -4175,6 +4169,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > >  { > > >       bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; > > >       bool can_compact = gfp_compaction_allowed(gfp_mask); > > > +     bool nofail = gfp_mask & __GFP_NOFAIL; > > >       const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; > > >       struct page *page = NULL; > > >       unsigned int alloc_flags; > > > @@ -4187,6 +4182,25 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > >       unsigned int zonelist_iter_cookie; > > >       int reserve_flags; > > > > > > +     if (unlikely(nofail)) { > > > +             /* > > > +              * We most definitely don't want callers attempting to > > > +              * allocate greater than order-1 page units with __GFP_NOFAIL. > > > +              */ > > > +             WARN_ON_ONCE(order > 1); > > > +             /* > > > +              * Also we don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM, > > > +              * otherwise, we may result in lockup. > > > +              */ > > > +             WARN_ON_ONCE(!can_direct_reclaim); > > > +             /* > > > +              * PF_MEMALLOC request from this context is rather bizarre > > > +              * because we cannot reclaim anything and only can loop waiting > > > +              * for somebody to do a work for us. > > > +              */ > > > +             WARN_ON_ONCE(current->flags & PF_MEMALLOC); > > > +     } > > > + > > >  restart: > > >       compaction_retries = 0; > > >       no_progress_loops = 0; > > > @@ -4404,29 +4418,15 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > >        * Make sure that __GFP_NOFAIL request doesn't leak out and make sure > > >        * we always retry > > >        */ > > > -     if (gfp_mask & __GFP_NOFAIL) { > > > +     if (unlikely(nofail)) { > > >               /* > > > -              * All existing users of the __GFP_NOFAIL are blockable, so warn > > > -              * of any new users that actually require GFP_NOWAIT > > > +              * Lacking direct_reclaim we can't do anything to reclaim memory, > > > +              * we disregard these unreasonable nofail requests and still > > > +              * return NULL > > >                */ > > > -             if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) > > > +             if (!can_direct_reclaim) > > >                       goto fail; > > > > > > -             /* > > > -              * PF_MEMALLOC request from this context is rather bizarre > > > -              * because we cannot reclaim anything and only can loop waiting > > > -              * for somebody to do a work for us > > > -              */ > > > -             WARN_ON_ONCE_GFP(current->flags & PF_MEMALLOC, gfp_mask); > > > - > > > -             /* > > > -              * non failing costly orders are a hard requirement which we > > > -              * are not prepared for much so let's warn about these users > > > -              * so that we can identify them and convert them to something > > > -              * else. > > > -              */ > > > -             WARN_ON_ONCE_GFP(costly_order, gfp_mask); > > > - > > >               /* > > >                * Help non-failing allocations by giving some access to memory > > >                * reserves normally used for high priority non-blocking > > > -- > > > 2.34.1 > > > > -- > > Michal Hocko > > SUSE Labs > > Thanks > Barry -- Michal Hocko SUSE Labs