LKML Archive mirror
 help / color / mirror / Atom feed
From: Chen Taotao <chentt10@chinatelecom.cn>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm/rmap: optimize folio_move_anon_rmap()
Date: Sun, 12 May 2024 20:35:55 +0800	[thread overview]
Message-ID: <20240512123555.8358-1-chentt10@chinatelecom.cn> (raw)

When a folio belongs exclusively to one process after a COW event,
folio_move_anon_rmap() always moves the folio into the anon_vma
belongs only to this process.

However, if the folio already belongs to the anon_vma of the this
process, we don't need to move it again. In this case, we first
check if the folio already belongs to the anna_vma of the this
process, and only move it if it does not.

The above changes may improve the performance of vm faults in some
scenarios, because the performance loss caused by WRITE_ONCE() is
much more than the performance loss caused by add a judgment.

Signed-off-by: Chen Taotao <chentt10@chinatelecom.cn>
---
 mm/rmap.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index 3746a5531018..5720cb78162d 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1216,12 +1216,15 @@ void folio_move_anon_rmap(struct folio *folio, struct vm_area_struct *vma)
 	VM_BUG_ON_VMA(!anon_vma, vma);
 
 	anon_vma += PAGE_MAPPING_ANON;
+
 	/*
-	 * Ensure that anon_vma and the PAGE_MAPPING_ANON bit are written
-	 * simultaneously, so a concurrent reader (eg folio_referenced()'s
-	 * folio_test_anon()) will not see one without the other.
+	 * If anon_vma != folio->mapping ensure that anon_vma and the
+	 * PAGE_MAPPING_ANON bit are writtensimultaneously, so a concurrent
+	 * reader (eg folio_referenced()'s folio_test_anon()) will not see
+	 * one without the other.
 	 */
-	WRITE_ONCE(folio->mapping, anon_vma);
+	if (anon_vma != folio->mapping)
+		WRITE_ONCE(folio->mapping, anon_vma);
 }
 
 /**
-- 
2.27.0


             reply	other threads:[~2024-05-12 12:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-12 12:35 Chen Taotao [this message]
2024-05-13 15:37 ` [PATCH] mm/rmap: optimize folio_move_anon_rmap() David Hildenbrand
2024-05-14  3:25   ` Anshuman Khandual

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=20240512123555.8358-1-chentt10@chinatelecom.cn \
    --to=chentt10@chinatelecom.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).