linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chris Li <chrisl@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>,
	 Kemeng Shi <shikemeng@huaweicloud.com>
Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com,
	 mgorman@techsingularity.net, Michal Hocko <mhocko@suse.com>,
	 david@redhat.com, willy@infradead.org, linux-mm@kvack.org,
	 Namhyung Kim <namhyung@google.com>,
	Greg Thelen <gthelen@google.com>,
	 linux-kernel@vger.kernel.org, Chris Li <chrisl@kernel.org>
Subject: [PATCH RFC 2/2] mm/page_alloc: free_pcppages_bulk clean up
Date: Thu, 17 Aug 2023 23:05:24 -0700	[thread overview]
Message-ID: <20230817-free_pcppages_bulk-v1-2-c14574a9f80c@kernel.org> (raw)
In-Reply-To: <20230817-free_pcppages_bulk-v1-0-c14574a9f80c@kernel.org>

This patch does not have functional change. Just pure clean up.

It removes the pindex_max and pindex_min and replaces it with a simpler
loop.

It uses for_each_entry_safe_reverse() to replace the loop over
list_last_entry(). It produces slightly better machine code.

Signed-off-by: Chris Li <chrisl@kernel.org>
---
 mm/page_alloc.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 347cb93081a02..d64d0f5ec70b4 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1209,11 +1209,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 					int pindex)
 {
 	unsigned long flags;
-	int min_pindex = 0;
-	int max_pindex = NR_PCP_LISTS - 1;
 	unsigned int order;
 	bool isolated_pageblocks;
-	struct page *page;
+	int i;
 
 	/* Ensure requested pindex is drained first. */
 	pindex = pindex - 1;
@@ -1221,31 +1219,18 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 	spin_lock_irqsave(&zone->lock, flags);
 	isolated_pageblocks = has_isolate_pageblock(zone);
 
-	while (count > 0) {
+	for (i = 0; i < NR_PCP_LISTS; i++, pindex++) {
 		struct list_head *list;
 		int nr_pages;
+		struct page *page, *next;
 
-		/* Remove pages from lists in a round-robin fashion. */
-		do {
-			if (++pindex > max_pindex)
-				pindex = min_pindex;
-			list = &pcp->lists[pindex];
-			if (!list_empty(list))
-				break;
-
-			if (pindex == max_pindex)
-				max_pindex--;
-			if (pindex == min_pindex)
-				min_pindex++;
-		} while (1);
-
+		if (pindex == NR_PCP_LISTS)
+			pindex = 0;
+		list = pcp->lists + pindex;
 		order = pindex_to_order(pindex);
 		nr_pages = 1 << order;
-		do {
-			int mt;
-
-			page = list_last_entry(list, struct page, pcp_list);
-			mt = get_pcppage_migratetype(page);
+		list_for_each_entry_safe_reverse(page, next, list, lru) {
+			int mt = get_pcppage_migratetype(page);
 
 			/* must delete to avoid corrupting pcp list */
 			list_del(&page->pcp_list);
@@ -1260,9 +1245,12 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 
 			__free_one_page(page, page_to_pfn(page), zone, order, mt, FPI_NONE);
 			trace_mm_page_pcpu_drain(page, order, mt);
-		} while (count > 0 && pcp->count > 0 && !list_empty(list));
-	}
 
+			if (count <= 0 || pcp->count <= 0)
+				goto out;
+		}
+	}
+out:
 	spin_unlock_irqrestore(&zone->lock, flags);
 }
 

-- 
2.42.0.rc1.204.g551eb34607-goog



  parent reply	other threads:[~2023-08-18  6:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  6:05 [PATCH RFC 0/2] mm/page_alloc: free_pcppages_bulk safeguard Chris Li
2023-08-18  6:05 ` [PATCH RFC 1/2] mm/page_alloc: safeguard free_pcppages_bulk Chris Li
2023-08-18  6:05 ` Chris Li [this message]
2023-08-24  6:28   ` [PATCH RFC 2/2] mm/page_alloc: free_pcppages_bulk clean up kernel test robot
2023-08-24 15:25     ` Chris Li
2023-08-21 10:32 ` [PATCH RFC 0/2] mm/page_alloc: free_pcppages_bulk safeguard Mel Gorman
2023-08-22  1:27   ` Kemeng Shi
2023-08-22 21:14     ` Chris Li
2023-08-22 21:19       ` Alexei Starovoitov
2023-08-22 21:29         ` Chris Li
2023-08-22 21:35           ` Alexei Starovoitov
2023-08-22 21:46             ` Chris Li
2023-08-22 17:48   ` Chris Li
2023-08-22 18:28     ` Matthew Wilcox
2023-08-22 18:57     ` Alexei Starovoitov
2023-08-22 21:34       ` Chris Li
2023-08-22 21:37         ` Alexei Starovoitov

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=20230817-free_pcppages_bulk-v1-2-c14574a9f80c@kernel.org \
    --to=chrisl@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=gthelen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=namhyung@google.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=willy@infradead.org \
    /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