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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1B1FC11F67 for ; Tue, 13 Jul 2021 15:21:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7645360C3E for ; Tue, 13 Jul 2021 15:21:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7645360C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE4536B008C; Tue, 13 Jul 2021 11:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 934926B009D; Tue, 13 Jul 2021 11:21:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F9796B009B; Tue, 13 Jul 2021 11:21:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 363056B0095 for ; Tue, 13 Jul 2021 11:21:04 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 368A281BCDBD for ; Tue, 13 Jul 2021 15:21:03 +0000 (UTC) X-FDA: 78357927606.27.C874BA4 Received: from outbound-smtp46.blacknight.com (outbound-smtp46.blacknight.com [46.22.136.58]) by imf16.hostedemail.com (Postfix) with ESMTP id B7C29F0000A7 for ; Tue, 13 Jul 2021 15:21:02 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp46.blacknight.com (Postfix) with ESMTPS id 7E08BFAE74 for ; Tue, 13 Jul 2021 16:21:01 +0100 (IST) Received: (qmail 14885 invoked from network); 13 Jul 2021 15:21:01 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.17.255]) by 81.17.254.9 with ESMTPA; 13 Jul 2021 15:21:01 -0000 From: Mel Gorman To: Andrew Morton Cc: Desmond Cheong Zhi Xi , Zhang Qiang , Yanfei Xu , Chuck Lever , Jesper Dangaard Brouer , Matteo Croce , Linux-MM , LKML , Mel Gorman Subject: [PATCH 3/4] mm/page_alloc: Further fix __alloc_pages_bulk() return value Date: Tue, 13 Jul 2021 16:20:59 +0100 Message-Id: <20210713152100.10381-4-mgorman@techsingularity.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713152100.10381-1-mgorman@techsingularity.net> References: <20210713152100.10381-1-mgorman@techsingularity.net> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B7C29F0000A7 X-Stat-Signature: 7geg4psocnwzc76rjo9qodraoir61xwg Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.58 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net; dmarc=none X-HE-Tag: 1626189662-376706 Content-Transfer-Encoding: quoted-printable 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: From: Chuck Lever The author of commit b3b64ebd3822 ("mm/page_alloc: do bulk array bounds check after checking populated elements") was possibly confused by the mixture of return values throughout the function. The API contract is clear that the function "Returns the number of pages on the list or array." It does not list zero as a unique return value with a special meaning. Therefore zero is a plausible return value only if @nr_pages is zero or less. Clean up the return logic to make it clear that the returned value is always the total number of pages in the array/list, not the number of pages that were allocated during this call. The only change in behavior with this patch is the value returned if prepare_alloc_pages() fails. To match the API contract, the number of pages currently in the array/list is returned in this case. The call site in __page_pool_alloc_pages_slow() also seems to be confused on this matter. It should be attended to by someone who is familiar with that code. [mel@techsingularity.net: Return nr_populated if 0 pages are requested] Signed-off-by: Chuck Lever Acked-by: Jesper Dangaard Brouer Signed-off-by: Mel Gorman --- mm/page_alloc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 803414ce9264..c66f1e6204c2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5221,9 +5221,6 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int pre= ferred_nid, unsigned int alloc_flags =3D ALLOC_WMARK_LOW; int nr_populated =3D 0, nr_account =3D 0; =20 - if (unlikely(nr_pages <=3D 0)) - return 0; - /* * Skip populated array elements to determine if any pages need * to be allocated before disabling IRQs. @@ -5231,9 +5228,13 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int pr= eferred_nid, while (page_array && nr_populated < nr_pages && page_array[nr_populated= ]) nr_populated++; =20 + /* No pages requested? */ + if (unlikely(nr_pages <=3D 0)) + goto out; + /* Already populated array? */ if (unlikely(page_array && nr_pages - nr_populated =3D=3D 0)) - return nr_populated; + goto out; =20 /* Use the single page allocator for one page. */ if (nr_pages - nr_populated =3D=3D 1) @@ -5255,7 +5256,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int pre= ferred_nid, gfp &=3D gfp_allowed_mask; alloc_gfp =3D gfp; if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &alloc_g= fp, &alloc_flags)) - return nr_populated; + goto out; gfp =3D alloc_gfp; =20 /* Find an allowed local zone that meets the low watermark. */ @@ -5323,6 +5324,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int pre= ferred_nid, __count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account); zone_statistics(ac.preferred_zoneref->zone, zone, nr_account); =20 +out: return nr_populated; =20 failed_irq: @@ -5338,7 +5340,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int pre= ferred_nid, nr_populated++; } =20 - return nr_populated; + goto out; } EXPORT_SYMBOL_GPL(__alloc_pages_bulk); =20 --=20 2.26.2