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 7B79CCD13CF for ; Mon, 2 Sep 2024 07:59:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B0DD8D009F; Mon, 2 Sep 2024 03:59:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0631C8D0098; Mon, 2 Sep 2024 03:59:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E43248D009F; Mon, 2 Sep 2024 03:59:02 -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 C1EC28D0098 for ; Mon, 2 Sep 2024 03:59:02 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 63B9E141A46 for ; Mon, 2 Sep 2024 07:59:02 +0000 (UTC) X-FDA: 82519047324.03.B2B8F2B Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf14.hostedemail.com (Postfix) with ESMTP id 4838D100003 for ; Mon, 2 Sep 2024 07:59:00 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=BXUX59EL; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf14.hostedemail.com: domain of mhocko@suse.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725263917; a=rsa-sha256; cv=none; b=UKmu0T5E3rvg2QCuovcgwwnPYfkWZpXXOtqvQ7/s7jCiNWQMf1Kl28ZQZ5aphaMURsVUjW 5VpE8BHR2ePdg5fSOnbhOQtBC60fTcDzovgDoc+ek1VdCOWZM1pVBh4+WCUyQC8omeuq0x 8lw12csEHro+087uQliYMCD8x+3yvZ4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=BXUX59EL; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf14.hostedemail.com: domain of mhocko@suse.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725263917; 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=vphCIwTaRUFU4blmExsrKpls/AaTUjrPE8gLIEy8J3k=; b=kShpgKHY5rcBDWLdBuLRW0xKebegHVg1CFAsaz7oVjZk9jJSB2RP5rNk/nOTSHfLJT6wkx dCfRP5Zx+Xc23h1edx/0s3txb+U04xTJqJMFPsgPU6cJPdJ0zThT8F+o6tUsGr7JuNOeJ3 9dz6hx/k+Qxym2C7vnciv5cPfQw0vHI= Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a866cea40c4so445869266b.0 for ; Mon, 02 Sep 2024 00:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1725263938; x=1725868738; 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=vphCIwTaRUFU4blmExsrKpls/AaTUjrPE8gLIEy8J3k=; b=BXUX59ELcNrDGsS1MP5VbY7zG6fSBPN0laC/UEhupS5xlP8S8d/oT/Ib9EhYJTUDye ld/e9/sRhjkWXMkBuiti/yi2YDSwykTnyadv7LK7R7eD8X4vmv9RsO2b4FU3sMnDvIXa CsRzjLDrGezqmIgqhj6WaAhV/Za0/NtKJB0j8P+dFoBEb4RcHwRjGeCjAjz1FZZ0IXfu mXTTv8GE83hb/oVl6wm071Jevfpn1eGpHl+xLGi71j+Pvw50l/d1Ohew+1gcTYCqY5b+ /ZohGwyz0u61hn6dGA8/CKd5JkkNC6V6GQKOSCKBdahEIWgM9jgb6ml7kL6U0z/MZreJ tQrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263938; x=1725868738; 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=vphCIwTaRUFU4blmExsrKpls/AaTUjrPE8gLIEy8J3k=; b=PnhOS/Qnb3PgD2yl2yanTpVnH5ellpQ16qI5tpdzw9sPFUKqfQCe6cB742w1gCU8Qo TnlNX3zRoUIvmwgkirRL6OgBJnJSmoyuC47oqRrf+v4GrZnEgv9fndS+uPThHAkfa7Cd +VQX6HE0+PU7C4Rt4CN9ZqAHS/6SfqsL614I2IlUvQPJS75W7GfrMYDvr1tGseLDkqjv Wn+mtCodPLG229VseSje5G515eIaEl3Y/TeRg7sU5qqmSir49FNzhx8I20+lbcfHrUdT yBktS64mUl7euHa7h2BD8w/209DHyD7pXptu9RfbOYboQneYwkEfnP4TF4F4YvWBj0Ou 3iXQ== X-Forwarded-Encrypted: i=1; AJvYcCXHz30j/uOKA+5bMLZraB9nwbB6+ikLC1W0XUYnUH/qEGgYan7lJ8egIq6y3l3V+5vKRKmTqIVMdw==@kvack.org X-Gm-Message-State: AOJu0Yww8QGUwdFltyY0auNq+pHF6dfAzpsmWDt9YUTi49vdhEedIxoJ VSwrlsRTZzK/sN5V9qVmkU3rbqXUlduqSB4lAFXp2d5bcLGNbq8bImoKJ32+qc4= X-Google-Smtp-Source: AGHT+IGOQxpkEzaJaHfH2XItf5G0tf2oHKzZYsIHrya04Evs+lCIYHbOKyrJgIkWiYuosAqx23TC5g== X-Received: by 2002:a17:907:7e92:b0:a86:7c6e:2bb9 with SMTP id a640c23a62f3a-a897f7892e8mr1115978666b.2.1725263938450; Mon, 02 Sep 2024 00:58:58 -0700 (PDT) Received: from localhost (109-81-82-19.rct.o2.cz. [109.81.82.19]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d8117sm529922366b.172.2024.09.02.00.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:58:58 -0700 (PDT) Date: Mon, 2 Sep 2024 09:58:56 +0200 From: Michal Hocko To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux.dev, david@redhat.com, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, laoar.shao@gmail.com Subject: Re: [PATCH v4 3/3] mm: warn about illegal __GFP_NOFAIL usage in a more appropriate location and manner Message-ID: References: <20240830202823.21478-1-21cnbao@gmail.com> <20240830202823.21478-4-21cnbao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240830202823.21478-4-21cnbao@gmail.com> X-Rspam-User: X-Rspamd-Queue-Id: 4838D100003 X-Rspamd-Server: rspam01 X-Stat-Signature: 5ws9ki45uwfk9aij1i4zwkhnw4ct39g5 X-HE-Tag: 1725263940-150320 X-HE-Meta: U2FsdGVkX1+g/GDmWZJchLpKdia8H1epMGO6yHTVKz/tCLzd5hdZd0rD9Fvq9hsISA7Ht/71lfPShGasLgBME2e6fDeq4hJtsikoJuRVKFZH+/tXEj3OSO9UpUT2SxLFtvBKlpjhn8BTqHRLs5GV0ih5Vcgoe1Uvbun0SsPuR9EfdR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ZhRnEPoouN0Te2Vwkvb/w5MR7yTIlX8lGyFgvTPuMDljjAUPgSXK1hb8UviEyMCYfeloTFy2PLdrEalP+d15epbFuK74NpJrA6yEjzDDIo7qxDrdV8BgiyJ3w9Vxj59H7Qfi36rKTRpkBfvzPoC+P2suTL6yG0PHxL5E73d+MwEme/FVU8sgbAT+vXQ6uQscTYgAEqHc8xWFl4zaWkY93TofVXYHP4oska0HIguuG792mFTFn2PZewIFvIjM0c4XGAo+pvm54zlpdrCYK9Jxhlilz3f3Pe 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 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. > --- > 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