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 01/10] mm/ksm: reduce the flush action for ksm merging page
Date: Tue,  4 Jun 2024 12:24:43 +0800	[thread overview]
Message-ID: <20240604042454.2012091-2-alexs@kernel.org> (raw)
In-Reply-To: <20240604042454.2012091-1-alexs@kernel.org>

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

We can put off the flush action util a merging is realy coming. That
could reduce some unmerge page flushing.
BTW, flushing only do at arm, mips and few other archs.

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

diff --git a/mm/ksm.c b/mm/ksm.c
index f5138f43f0d2..97e5b41f8c4b 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -783,10 +783,7 @@ static struct page *get_mergeable_page(struct ksm_rmap_item *rmap_item)
 		goto out;
 	if (is_zone_device_page(page))
 		goto out_putpage;
-	if (PageAnon(page)) {
-		flush_anon_page(vma, page, addr);
-		flush_dcache_page(page);
-	} else {
+	if (!PageAnon(page)) {
 out_putpage:
 		put_page(page);
 out:
@@ -1473,8 +1470,8 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
  *
  * This function returns 0 if the pages were merged, -EFAULT otherwise.
  */
-static int try_to_merge_one_page(struct vm_area_struct *vma,
-				 struct page *page, struct page *kpage)
+static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page,
+				 struct ksm_rmap_item *rmap_item, struct page *kpage)
 {
 	pte_t orig_pte = __pte(0);
 	int err = -EFAULT;
@@ -1500,6 +1497,9 @@ static int try_to_merge_one_page(struct vm_area_struct *vma,
 			goto out_unlock;
 	}
 
+	flush_anon_page(vma, page, rmap_item->address);
+	flush_dcache_page(page);
+
 	/*
 	 * If this anonymous page is mapped only here, its pte may need
 	 * to be write-protected.  If it's mapped elsewhere, all of its
@@ -1550,7 +1550,7 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item,
 	if (!vma)
 		goto out;
 
-	err = try_to_merge_one_page(vma, page, kpage);
+	err = try_to_merge_one_page(vma, page, rmap_item, kpage);
 	if (err)
 		goto out;
 
@@ -2385,7 +2385,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
 		mmap_read_lock(mm);
 		vma = find_mergeable_vma(mm, rmap_item->address);
 		if (vma) {
-			err = try_to_merge_one_page(vma, page,
+			err = try_to_merge_one_page(vma, page, rmap_item,
 					ZERO_PAGE(rmap_item->address));
 			trace_ksm_merge_one_page(
 				page_to_pfn(ZERO_PAGE(rmap_item->address)),
@@ -2663,8 +2663,6 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (is_zone_device_page(*page))
 				goto next_page;
 			if (PageAnon(*page)) {
-				flush_anon_page(vma, *page, ksm_scan.address);
-				flush_dcache_page(*page);
 				rmap_item = get_next_rmap_item(mm_slot,
 					ksm_scan.rmap_list, ksm_scan.address);
 				if (rmap_item) {
-- 
2.43.0



  reply	other threads:[~2024-06-04  4:21 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 ` alexs [this message]
2024-06-04  8:07   ` [PATCH 01/10] mm/ksm: reduce the flush action for ksm merging page 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 ` [PATCH 10/10] m/ksm: use folio in ksm scan path alexs
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-2-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