Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3919395pxv; Mon, 28 Jun 2021 16:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDNt3UOsU3mWgbG0Tq42MrVGcENLr1Qas2dgn5IYVHRAJHiR9sG2iO6DfwkzdilnTO1yU3 X-Received: by 2002:a05:6602:42:: with SMTP id z2mr1509161ioz.91.1624923612926; Mon, 28 Jun 2021 16:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624923612; cv=none; d=google.com; s=arc-20160816; b=J0RzT8A8sPC8V9b3d1/bJoS9TPJiDt2EjXEFk3XYM2/Xc8xVLxOKqHdR9QFXRJ4Wqa NPni0k1kxvJ37ZahrRLfiqFGdNsDNyMsn53UEcHlvUooqiIx8GWQjk6hh6UpyZiRoYN5 YVkpx7l9wVR3tqy13Etnl7f7gwXae4nPI5ISUdpmS2UXsmkxWN1WXUBneqYxHLzJCggE tUz3jX4cy5zn6/dvVMIj6ICiqFn15J6bF68XR9VF0gQLv/OFFix7EVhOgjpJ7p91Pw88 0EsPFk4GDcYT5zGh4wZyog3hpkAwLfe73XO57ZvsL2NqAzScQ5zTNnzhvRAFS6j/1W6M +LYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject; bh=m48qMgjFd44u9AsX6Xxpr8hL2WPkS4uTXdW/o7GG11A=; b=N2mkhEIsQgzOFKPs0dnpV/TTC1RBOK+C1C1w9qvNu30ehlBpMr4dGztj+AlmTAQHq2 B2lP5MQMsDkt9IonvYB3Z2vXkpz/fx3fvhs7KAY4AZQ2AqkN7TExifA2nS4uZZxs5t3h qwddaUZBKw8UAgBjsHrZ1RHP261+VOFjWBHFOrI2nzc11pCgLgmjVzIM7emiCnR/iMk7 A7CnDmQ105czQe/eLENB0H3PO3i7ojoW4abDWiYzqcpPPrGwUB8FoJsORs6xPRPwQ48t N8cDOWla6v/WtiGN34Uw8pU2uwIKV94A3lnKBBCYgrTMLyhj05IFIt9YOTsW1i1tEWGh IuAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w23si5259467ioc.3.2021.06.28.16.40.01; Mon, 28 Jun 2021 16:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233111AbhF1SP0 (ORCPT + 99 others); Mon, 28 Jun 2021 14:15:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:58316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbhF1SP0 (ORCPT ); Mon, 28 Jun 2021 14:15:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A0F061C6F; Mon, 28 Jun 2021 18:13:00 +0000 (UTC) Subject: [PATCH v2] mm/page_alloc: Return nr_populated when the array is full From: Chuck Lever To: mgorman@techsingularity.net Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org Date: Mon, 28 Jun 2021 14:12:59 -0400 Message-ID: <162490397938.1485.7782934829743772831.stgit@klimt.1015granger.net> User-Agent: StGit/1.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The SUNRPC consumer of __alloc_bulk_pages() legitimately calls it with a full array sometimes. In that case, the correct return code, according to the API contract, is to return the number of pages already in the array/list. Let's 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. Fixes: b3b64ebd3822 ("mm/page_alloc: do bulk array bounds check after checking populated elements") Signed-off-by: Chuck Lever --- mm/page_alloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ef2265f86b91..270719898b47 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5047,7 +5047,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, int nr_populated = 0; if (unlikely(nr_pages <= 0)) - return 0; + goto out; /* * Skip populated array elements to determine if any pages need @@ -5058,7 +5058,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, /* Already populated array? */ if (unlikely(page_array && nr_pages - nr_populated == 0)) - return 0; + goto out; /* Use the single page allocator for one page. */ if (nr_pages - nr_populated == 1) @@ -5068,7 +5068,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, gfp &= gfp_allowed_mask; alloc_gfp = gfp; if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &alloc_gfp, &alloc_flags)) - return 0; + goto out; gfp = alloc_gfp; /* Find an allowed local zone that meets the low watermark. */ @@ -5141,6 +5141,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, local_irq_restore(flags); +out: return nr_populated; failed_irq: @@ -5156,7 +5157,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, nr_populated++; } - return nr_populated; + goto out; } EXPORT_SYMBOL_GPL(__alloc_pages_bulk);