linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: alexs@kernel.org
To: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	izik.eidus@ravellosystems.com, willy@infradead.org,
	aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com,
	david@redhat.com
Cc: "Alex Shi (tencent)" <alexs@kernel.org>
Subject: [PATCH 10/10] m/ksm: use folio in ksm scan path
Date: Tue,  4 Jun 2024 12:24:52 +0800	[thread overview]
Message-ID: <20240604042454.2012091-11-alexs@kernel.org> (raw)
In-Reply-To: <20240604042454.2012091-1-alexs@kernel.org>

From: "Alex Shi (tencent)" <alexs@kernel.org>

Now we could safely use folio in ksm_do_scan path to save a few compound
checks. The 'page' still used since follow_page function still no folio
version.

Signed-off-by: Alex Shi (tencent) <alexs@kernel.org>
---
 mm/ksm.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index dc2b5e6a9659..57904b3b18dc 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2304,7 +2304,7 @@ static void stable_tree_append(struct ksm_rmap_item *rmap_item,
  * @page: the page that we are searching identical page to.
  * @rmap_item: the reverse mapping into the virtual address of this page
  */
-static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_item)
+static void cmp_and_merge_page(struct folio *folio, struct ksm_rmap_item *rmap_item)
 {
 	struct mm_struct *mm = rmap_item->mm;
 	struct ksm_rmap_item *tree_rmap_item;
@@ -2314,9 +2314,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
 	unsigned int checksum;
 	int err;
 	bool max_page_sharing_bypass = false;
-	struct folio *folio;
 
-	folio = page_folio(page);
 	stable_node = folio_stable_node(folio);
 	if (stable_node) {
 		if (stable_node->head != &migrate_nodes &&
@@ -2518,12 +2516,12 @@ static unsigned int skip_age(rmap_age_t age)
 }
 
 /*
- * Determines if a page should be skipped for the current scan.
+ * Determines if a folio should be skipped for the current scan.
  *
- * @page: page to check
- * @rmap_item: associated rmap_item of page
+ * @folio: folio to check
+ * @rmap_item: associated rmap_item of folio
  */
-static bool should_skip_rmap_item(struct page *page,
+static bool should_skip_rmap_item(struct folio *folio,
 				  struct ksm_rmap_item *rmap_item)
 {
 	rmap_age_t age;
@@ -2536,7 +2534,7 @@ static bool should_skip_rmap_item(struct page *page,
 	 * will essentially ignore them, but we still have to process them
 	 * properly.
 	 */
-	if (PageKsm(page))
+	if (folio_test_ksm(folio))
 		return false;
 
 	age = rmap_item->age;
@@ -2566,7 +2564,7 @@ static bool should_skip_rmap_item(struct page *page,
 	return true;
 }
 
-static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
+static struct ksm_rmap_item *scan_get_next_rmap_item(struct folio **folio)
 {
 	struct mm_struct *mm;
 	struct ksm_mm_slot *mm_slot;
@@ -2655,36 +2653,41 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
 			ksm_scan.address = vma->vm_end;
 
 		while (ksm_scan.address < vma->vm_end) {
+			struct page *page;
+
 			if (ksm_test_exit(mm))
 				break;
-			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page)) {
+			page = follow_page(vma, ksm_scan.address, FOLL_GET);
+			if (IS_ERR_OR_NULL(page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
 
-			VM_WARN_ON(PageTail(*page));
-			nr = compound_nr(*page);
-			if (is_zone_device_page(*page))
+			*folio = page_folio(page);
+			VM_WARN_ON(PageTail(page));
+			nr = folio_nr_pages(*folio);
+
+			if (folio_is_zone_device(*folio))
 				goto next_page;
-			if (PageAnon(*page)) {
+
+			if (folio_test_anon(*folio)) {
 				rmap_item = get_next_rmap_item(mm_slot,
 					ksm_scan.rmap_list, ksm_scan.address);
 				if (rmap_item) {
 					ksm_scan.rmap_list = &rmap_item->rmap_list;
 
-					if (should_skip_rmap_item(*page, rmap_item))
+					if (should_skip_rmap_item(*folio, rmap_item))
 						goto next_page;
 
 					ksm_scan.address += nr * PAGE_SIZE;
 				} else
-					put_page(*page);
+					folio_put(*folio);
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
 next_page:
-			put_page(*page);
+			folio_put(*folio);
 			ksm_scan.address += nr * PAGE_SIZE;
 			cond_resched();
 		}
@@ -2755,16 +2758,16 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
 static void ksm_do_scan(unsigned int scan_npages)
 {
 	struct ksm_rmap_item *rmap_item;
-	struct page *page;
+	struct folio *folio;
 	unsigned int npages = scan_npages;
 
 	while (npages-- && likely(!freezing(current))) {
 		cond_resched();
-		rmap_item = scan_get_next_rmap_item(&page);
+		rmap_item = scan_get_next_rmap_item(&folio);
 		if (!rmap_item)
 			return;
-		cmp_and_merge_page(page, rmap_item);
-		put_page(page);
+		cmp_and_merge_page(folio, rmap_item);
+		folio_put(folio);
 	}
 
 	ksm_pages_scanned += scan_npages - npages;
-- 
2.43.0



  parent reply	other threads:[~2024-06-04  4:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04  4:24 [PATCH 00/10] use folio in ksm alexs
2024-06-04  4:24 ` [PATCH 01/10] mm/ksm: reduce the flush action for ksm merging page alexs
2024-06-04  8:07   ` David Hildenbrand
2024-06-04 10:26     ` Alex Shi
2024-06-04 10:45       ` David Hildenbrand
2024-06-04 13:02         ` Alex Shi
2024-06-05  7:26           ` David Hildenbrand
2024-06-05  9:10             ` Alex Shi
2024-06-05  9:14               ` David Hildenbrand
2024-06-05  9:49                 ` Alex Shi
2024-06-05 10:00                   ` David Hildenbrand
2024-06-04  4:24 ` [PATCH 02/10] mm/ksm: skip subpages of compound pages alexs
2024-06-04  8:12   ` David Hildenbrand
2024-06-04 10:31     ` Alex Shi
2024-06-04 10:43       ` David Hildenbrand
2024-06-04 13:10         ` Alex Shi
2024-06-04 13:14           ` David Hildenbrand
2024-06-05  3:58             ` Alex Shi
2024-06-05  7:40               ` David Hildenbrand
2024-06-05  3:52   ` Matthew Wilcox
2024-06-05  6:14     ` Alex Shi
2024-06-05  7:47       ` David Hildenbrand
2024-06-05 21:12         ` Matthew Wilcox
2024-06-06  7:11           ` David Hildenbrand
2024-06-04  4:24 ` [PATCH 03/10] mm/ksm: use folio in try_to_merge_one_page alexs
2024-06-04  8:19   ` David Hildenbrand
2024-06-05  3:38     ` Alex Shi
2024-06-04  4:24 ` [PATCH 04/10] mm/ksm: add identical_folio func alexs
2024-06-04  8:25   ` David Hildenbrand
2024-06-04  4:24 ` [PATCH 05/10] mm/ksm: use folio in stable_tree_search alexs
2024-06-04  4:24 ` [PATCH 06/10] mm/ksm: remove page_stable_node alexs
2024-06-04  4:24 ` [PATCH 07/10] mm/ksm: use folio in unstable_tree_search_insert alexs
2024-06-04  4:24 ` [PATCH 08/10] mm/ksm: use folio in try_to_merge_xx serie funcs alexs
2024-06-04  4:24 ` [PATCH 09/10] mm/ksm: calc_checksum for folio alexs
2024-06-04 13:18   ` David Hildenbrand
2024-06-05  3:44     ` Alex Shi
2024-06-05  7:53       ` David Hildenbrand
2024-06-04  4:24 ` alexs [this message]
2024-06-04 13:28 ` [PATCH 00/10] use folio in ksm David Hildenbrand
2024-06-05  3:46   ` Alex Shi

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=20240604042454.2012091-11-alexs@kernel.org \
    --to=alexs@kernel.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrisw@sous-sol.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=izik.eidus@ravellosystems.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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