linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Oscar Salvador <osalvador@suse.de>
Subject: [PATCH 5/5] compaction: Use hugetlb_pfn_folio in isolate_migratepages_block
Date: Fri,  1 Mar 2024 21:47:10 +0000	[thread overview]
Message-ID: <20240301214712.2853147-6-willy@infradead.org> (raw)
In-Reply-To: <20240301214712.2853147-1-willy@infradead.org>

This is more efficient than calling page_folio() ourselves, and
removes a call to PageHuge() which we're trying to get rid of.
We do not hold the hugetlb_lock here, so the folio may be dissolved
under us, but we check for that in hugetlb_isolate_or_dissolve()
(which now takes a folio argument instead of converting to a folio
itself).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/hugetlb.h |  4 ++--
 mm/compaction.c         | 16 ++++++++--------
 mm/hugetlb.c            | 10 +++++-----
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 89f4b90eec68..436086a300f5 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -736,7 +736,7 @@ struct huge_bootmem_page {
 	struct hstate *hstate;
 };
 
-int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list);
+int hugetlb_isolate_or_dissolve(struct folio *folio, struct list_head *list);
 struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
 				unsigned long addr, int avoid_reserve);
 struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid,
@@ -1043,7 +1043,7 @@ static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
 	return NULL;
 }
 
-static inline int isolate_or_dissolve_huge_page(struct page *page,
+static inline int hugetlb_isolate_or_dissolve(struct folio *folio,
 						struct list_head *list)
 {
 	return -ENOMEM;
diff --git a/mm/compaction.c b/mm/compaction.c
index 807b58e6eb68..ad3430c22ede 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1001,17 +1001,18 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 			valid_page = page;
 		}
 
-		if (PageHuge(page)) {
+		folio = hugetlb_pfn_folio(low_pfn);
+		if (folio) {
 			/*
 			 * skip hugetlbfs if we are not compacting for pages
 			 * bigger than its order. THPs and other compound pages
 			 * are handled below.
 			 */
 			if (!cc->alloc_contig) {
-				const unsigned int order = compound_order(page);
+				const unsigned int order = folio_order(folio);
 
 				if (order <= MAX_PAGE_ORDER) {
-					low_pfn += (1UL << order) - 1;
+					low_pfn |= (1UL << order) - 1;
 					nr_scanned += (1UL << order) - 1;
 				}
 				goto isolate_fail;
@@ -1022,7 +1023,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				locked = NULL;
 			}
 
-			ret = isolate_or_dissolve_huge_page(page, &cc->migratepages);
+			ret = hugetlb_isolate_or_dissolve(folio, &cc->migratepages);
 
 			/*
 			 * Fail isolation in case isolate_or_dissolve_huge_page()
@@ -1032,17 +1033,16 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 /* Do not report -EBUSY down the chain */
 				if (ret == -EBUSY)
 					ret = 0;
-				low_pfn += compound_nr(page) - 1;
-				nr_scanned += compound_nr(page) - 1;
+				low_pfn += folio_nr_pages(folio) - 1;
+				nr_scanned += folio_nr_pages(folio) - 1;
 				goto isolate_fail;
 			}
 
-			if (PageHuge(page)) {
+			if (folio_test_hugetlb(folio)) {
 				/*
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				folio = page_folio(page);
 				low_pfn += folio_nr_pages(folio) - 1;
 				goto isolate_success_no_list;
 			}
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2e6ebedb75a8..7832b0730e80 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3160,16 +3160,16 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,
 	return ret;
 }
 
-int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)
+int hugetlb_isolate_or_dissolve(struct folio *folio, struct list_head *list)
 {
 	struct hstate *h;
-	struct folio *folio = page_folio(page);
 	int ret = -EBUSY;
 
 	/*
-	 * The page might have been dissolved from under our feet, so make sure
-	 * to carefully check the state under the lock.
-	 * Return success when racing as if we dissolved the page ourselves.
+	 * The folio might have been dissolved from under our feet,
+	 * so make sure to carefully check the state under the lock.
+	 * Return success when racing as if we dissolved the folio
+	 * ourselves.
 	 */
 	spin_lock_irq(&hugetlb_lock);
 	if (folio_test_hugetlb(folio)) {
-- 
2.43.0



  parent reply	other threads:[~2024-03-01 21:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 21:47 [PATCH 0/5] Remove some races around folio_test_hugetlb Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 1/5] hugetlb: Make folio_test_hugetlb safer to call Matthew Wilcox (Oracle)
2024-03-05  6:43   ` Oscar Salvador
2024-03-05  8:39   ` David Hildenbrand
2024-03-01 21:47 ` [PATCH 2/5] hugetlb: Add hugetlb_pfn_folio Matthew Wilcox (Oracle)
2024-03-05  6:58   ` Oscar Salvador
2024-03-01 21:47 ` [PATCH 3/5] memory-failure: Use hugetlb_pfn_folio Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 4/5] memory-failure: Reorganise get_huge_page_for_hwpoison() Matthew Wilcox (Oracle)
2024-03-01 21:47 ` Matthew Wilcox (Oracle) [this message]
2024-03-04  9:09 ` [PATCH 0/5] Remove some races around folio_test_hugetlb Miaohe Lin
2024-03-04 17:08   ` Matthew Wilcox
2024-03-06  7:58     ` Miaohe Lin
2024-03-07 21:16       ` Matthew Wilcox
2024-03-05  9:10 ` David Hildenbrand
2024-03-05 20:35   ` Matthew Wilcox
2024-03-06 15:18     ` David Hildenbrand
2024-03-07  4:31       ` Matthew Wilcox
2024-03-07  9:20         ` David Hildenbrand
2024-03-07 21:14           ` Matthew Wilcox
2024-03-07 21:38             ` David Hildenbrand
2024-03-08  4:31             ` Matthew Wilcox
2024-03-08  8:46               ` David Hildenbrand

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=20240301214712.2853147-6-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).