From patchwork Fri Aug 30 20:28:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13785530 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 25EF6CA1013 for ; Fri, 30 Aug 2024 20:29:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B08046B026B; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB8388D0008; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90ACD6B026D; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6AA0F6B026B for ; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CB48CA05BC for ; Fri, 30 Aug 2024 20:29:38 +0000 (UTC) X-FDA: 82510052436.12.4AAED17 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf09.hostedemail.com (Postfix) with ESMTP id DC560140021 for ; Fri, 30 Aug 2024 20:29:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iaycYqF0; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725049731; a=rsa-sha256; cv=none; b=ukcTCMSOH8e/b2tc7MTU8RpWydgtBKIj3LaMtcEOn0N01Ni6DiSwlIYWMjyWkU66+xycSa sGwQ4zPXDOQ2SehcTQbM8ntgGP58aAkVqZlTxPdhh42eCMNjQbvqcn2PcIV7g0IcU+rCOc feTJrhc89IGKsnVdDOfwLGpCcpBc3D0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iaycYqF0; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725049731; 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=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=fYaHoOD26aWlNbxY8bPSBVIONZirwGXg/oqs3SKxInFsM5Obpu2Zjghxj3mapZvANAYifU M3fEvfhtSFytrYSRi7FEG62LkdGHaLqaI8+9xziEzanEXZHqDmOHaC2QjAcclIUyXCKfmW 9eGYYIIx/o4w0TtYDYQT9Bd+Q06pLoI= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7148912a1ebso1459282b3a.0 for ; Fri, 30 Aug 2024 13:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725049775; x=1725654575; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=iaycYqF0mcn0FVMLx2TDe2macsblRm38yqBop5eOT2N7P/lGr86LfClxqFLkU++Tqj amnd8M+55hxJxAHzyMHbKwxayLxVytu0TakS7ra0+15JTUX9u7zVl9A1Xc4MdAieJu7P N/SGcK0auCYXCgbvCQRrUvg1x/ZjZc+v/sUfFj9iKnZAIbljRVbH0RTT8W7rJhejEDoc qpnpWOF57zdAvjPWsDdIKmAAHlLfS7UmGP8QyCqWrfE/eTNjb2MORc6uQXfYhtOU3We8 LnKoaCxVbmQJaIaXPIdgMmgTPL4ADuV2fAHd5GoxgwbD/zA2npp4/Tvv3UEqh3KEV++c lyOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725049775; x=1725654575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=PpijBizlA+xswwYsAmpYKYFKpeBLiIrCbyuUOcW778GFRBINbvDGRfjxebnOf7qWh0 Wt4Ug5L57rqr+O3vxiQ5Dk6iDE5/WKU3xdrbyiY2UTeN6NZQ96pk4c2hh5s5TTFQIVSN f1hvNfpD5QLgCKz+vksQc8Jt9NUTS+zj+Q+mfE7U3Ri31IQMfFZ/XJ1fWSDJbxxfIcDZ g9kjzNYtK740SFPiZqRbEhb3lecH+ZZoqyEHwYQ8557q/5zGjLiEPjzMb2R23p+i5MXC FK6uhETRMKPywQn8msw2zjSU11HpVoNCooINEqVgFfmirsKhY9vPXLPj04MjADBfnDVk tuaw== X-Forwarded-Encrypted: i=1; AJvYcCVSa8hfHfEYQhuYNryt+S6QB02QvRPGoXnJuwUWLw9p+CXFqZ/tE0pf09NQm9XuFpFmZvjtBTibew==@kvack.org X-Gm-Message-State: AOJu0Yyvcgy6PE7wv4ba0gdSKH0OsUFH47knkkZeIhJWgRoPB75+ibZk Hkwls7ckeuOTLtLZzEAilvyj5J9Qz/y68K9PmVm8ze8N6wbqOhW6 X-Google-Smtp-Source: AGHT+IG8y6GX/E7RigCSHufkr+GwgOj7KdtzlyA39qYM7vxl8g1/NMkb5KBYNwmdjJECo9kKMTCYSA== X-Received: by 2002:a05:6a00:124a:b0:705:9992:e7f2 with SMTP id d2e1a72fcca58-7173c1f7300mr1000751b3a.12.1725049775341; Fri, 30 Aug 2024 13:29:35 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e56d74eesm3257035b3a.147.2024.08.30.13.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 13:29:34 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux.dev Cc: david@redhat.com, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.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: [PATCH v4 3/3] mm: warn about illegal __GFP_NOFAIL usage in a more appropriate location and manner Date: Sat, 31 Aug 2024 08:28:23 +1200 Message-Id: <20240830202823.21478-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830202823.21478-1-21cnbao@gmail.com> References: <20240830202823.21478-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: zjmo8f3zyrshxy8ruw7jjmg4cew6ifxb X-Rspamd-Queue-Id: DC560140021 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725049776-583992 X-HE-Meta: U2FsdGVkX1+SUMOI9Zy3R3fzi2J7zTW//7mD/QOFzFT57lM24xGt/Wpzv9uIfbBz+fywwdk338czLUI6DyIweu5topt/TFurIZ/wUXvsSQr9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z9/9O/i/bbJ3SRrrUr354tmJmI/Ln39hu7iNnIKpIU7VRZXWzwwGEUPf3Qsq0t+YWEMuFaZP6ypG5d95Xq3mvwAaoFiPFi7P36CeT7ZmwK6vWtkmWzHIH9TafOqNziwXPhyyPPThQUH5E5RoQ6wkbcgJB7F4uJ/3KqyZb4zfvcSl41xa5o1rLhDIEVIQWRKThMW2dvZuApVw9UArFfwIbdh+DzqdoV9Jj+CBeKdYEgz1dW57a3q8yc9dxPkEcDl5z3xCXbMTq+T6n6Bespn1wO9qgFcOW2R8qDh45hEs6h9OmpZSixj6peUlR3Q4tnQJnGP08Qv2soBN2r1nBX1L3kXwQKWT1InzCA3Ppxdv4cHHdb+HFLnxRY/dAPqHIzUyEY= 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: 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 Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand Acked-by: Michal Hocko Signed-off-by: Barry Song --- 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