linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <willy@infradead.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <ying.huang@intel.com>,
	<david@redhat.com>, Zi Yan <ziy@nvidia.com>,
	Mike Kravetz <mike.kravetz@oracle.com>, <hughd@google.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH v2 6/8] mm: migrate: use a folio in add_page_for_migration()
Date: Mon, 21 Aug 2023 19:56:22 +0800	[thread overview]
Message-ID: <20230821115624.158759-7-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20230821115624.158759-1-wangkefeng.wang@huawei.com>

Use a folio in add_page_for_migration() to save compound_head() calls.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate.c | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index b715cd59bdec..73572d5a5cd4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2057,6 +2057,7 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p,
 	struct vm_area_struct *vma;
 	unsigned long addr;
 	struct page *page;
+	struct folio *folio;
 	int err;
 	bool isolated;
 
@@ -2079,45 +2080,42 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p,
 	if (!page)
 		goto out;
 
-	if (is_zone_device_page(page))
-		goto out_putpage;
+	folio = page_folio(page);
+	if (folio_is_zone_device(folio))
+		goto out_putfolio;
 
 	err = 0;
-	if (page_to_nid(page) == node)
-		goto out_putpage;
+	if (folio_nid(folio) == node)
+		goto out_putfolio;
 
 	err = -EACCES;
 	if (page_mapcount(page) > 1 && !migrate_all)
-		goto out_putpage;
+		goto out_putfolio;
 
-	if (PageHuge(page)) {
+	if (folio_test_hugetlb(folio)) {
 		if (PageHead(page)) {
-			isolated = isolate_hugetlb(page_folio(page), pagelist);
+			isolated = isolate_hugetlb(folio, pagelist);
 			err = isolated ? 1 : -EBUSY;
 		}
 	} else {
-		struct page *head;
-
-		head = compound_head(page);
-		isolated = isolate_lru_page(head);
+		isolated = folio_isolate_lru(folio);
 		if (!isolated) {
 			err = -EBUSY;
-			goto out_putpage;
+			goto out_putfolio;
 		}
 
 		err = 1;
-		list_add_tail(&head->lru, pagelist);
-		mod_node_page_state(page_pgdat(head),
-			NR_ISOLATED_ANON + page_is_file_lru(head),
-			thp_nr_pages(head));
+		list_add_tail(&folio->lru, pagelist);
+		node_stat_mod_folio(folio,
+			NR_ISOLATED_ANON + folio_is_file_lru(folio),
+			folio_nr_pages(folio));
 	}
-out_putpage:
+out_putfolio:
 	/*
-	 * Either remove the duplicate refcount from
-	 * isolate_lru_page() or drop the page ref if it was
-	 * not isolated.
+	 * Either remove the duplicate refcount from folio_isolate_lru()
+	 * or drop the folio ref if it was not isolated.
 	 */
-	put_page(page);
+	folio_put(folio);
 out:
 	mmap_read_unlock(mm);
 	return err;
-- 
2.41.0



  parent reply	other threads:[~2023-08-21 11:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 11:56 [PATCH v2 0/8] mm: migrate: more folio conversion and unify Kefeng Wang
2023-08-21 11:56 ` [PATCH v2 1/8] mm: migrate: remove PageTransHuge check in numamigrate_isolate_page() Kefeng Wang
2023-08-21 12:38   ` Matthew Wilcox
2023-08-21 12:52     ` Kefeng Wang
2023-08-21 14:41       ` Kefeng Wang
2023-08-25  3:51     ` Kefeng Wang
2023-08-21 11:56 ` [PATCH v2 2/8] mm: migrate: remove THP mapcount " Kefeng Wang
2023-08-22  2:22   ` Huang, Ying
2023-08-21 11:56 ` [PATCH v2 3/8] mm: migrate: convert numamigrate_isolate_page() to numamigrate_isolate_folio() Kefeng Wang
2023-08-28 14:03   ` Zi Yan
2023-08-21 11:56 ` [PATCH v2 4/8] mm: migrate: use a folio in migrate_misplaced_page() Kefeng Wang
2023-08-28 14:10   ` Zi Yan
2023-08-29  0:49     ` Huang, Ying
2023-08-29  2:10       ` Matthew Wilcox
2023-08-30  9:45         ` Kefeng Wang
2023-08-21 11:56 ` [PATCH v2 5/8] mm: migrate: use __folio_test_movable() Kefeng Wang
2023-08-28 14:11   ` Zi Yan
2023-08-21 11:56 ` Kefeng Wang [this message]
2023-08-28 14:13   ` [PATCH v2 6/8] mm: migrate: use a folio in add_page_for_migration() Zi Yan
2023-08-21 11:56 ` [PATCH v2 7/8] mm: migrate: remove PageHead() check for HugeTLB " Kefeng Wang
2023-08-28 14:15   ` Zi Yan
2023-08-21 11:56 ` [PATCH v2 8/8] mm: migrate: remove isolated variable " Kefeng Wang
2023-08-28 14:18   ` Zi Yan

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=20230821115624.158759-7-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.com \
    --cc=ziy@nvidia.com \
    /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