linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yanfei Xu <yanfei.xu@windriver.com>
To: akpm@linux-foundation.org, mgorman@techsingularity.net
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] mm/page_alloc: avoid counting event if no successful allocation
Date: Fri,  9 Jul 2021 18:28:55 +0800	[thread overview]
Message-ID: <20210709102855.55058-2-yanfei.xu@windriver.com> (raw)
In-Reply-To: <20210709102855.55058-1-yanfei.xu@windriver.com>

While the nr_populated is non-zero, however the nr_account might be
zero if allocating fails. In this case, not to count event can save
some cycles.

And this commit extract the check of "page_array" from a while
statement to avoid unnecessary checks for it.

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
 mm/page_alloc.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e9fd57ca4c1c..e25d508b85e9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5235,16 +5235,18 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(nr_pages <= 0))
 		return 0;
 
-	/*
-	 * Skip populated array elements to determine if any pages need
-	 * to be allocated before disabling IRQs.
-	 */
-	while (page_array && nr_populated < nr_pages && page_array[nr_populated])
-		nr_populated++;
+	if (page_array) {
+		/*
+		 * Skip populated array elements to determine if any pages need
+		 * to be allocated before disabling IRQs.
+		 */
+		while (nr_populated < nr_pages && page_array[nr_populated])
+			nr_populated++;
 
-	/* Already populated array? */
-	if (unlikely(page_array && nr_pages - nr_populated == 0))
-		return nr_populated;
+		/* Already populated array? */
+		if (unlikely(nr_pages - nr_populated == 0))
+			return nr_populated;
+	}
 
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
@@ -5319,9 +5321,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 
 	local_unlock_irqrestore(&pagesets.lock, flags);
 
-	__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
-	zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
-
+	if (likely(nr_account)) {
+		__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
+		zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	}
 	return nr_populated;
 
 failed_irq:
-- 
2.27.0



  reply	other threads:[~2021-07-09 10:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 10:28 [PATCH 1/2] mm/page_alloc: correct return value when failing at preparing Yanfei Xu
2021-07-09 10:28 ` Yanfei Xu [this message]
2021-07-09 12:26   ` [PATCH 2/2] mm/page_alloc: avoid counting event if no successful allocation Mel Gorman
2021-07-10 11:31     ` Xu, Yanfei
2021-07-09 12:22 ` [PATCH 1/2] mm/page_alloc: correct return value when failing at preparing Mel Gorman
2021-07-10  6:58   ` Xu, Yanfei
2021-07-13 12:14     ` Mel Gorman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210709102855.55058-2-yanfei.xu@windriver.com \
    --to=yanfei.xu@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox