linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yin Fengwei <fengwei.yin@intel.com>
To: willy@infradead.org, linux-mm@kvack.org
Cc: dave.hansen@intel.com, tim.c.chen@intel.com,
	ying.huang@intel.com, fengwei.yin@intel.com
Subject: [RFC PATCH 1/2] rmap: Add function to handle entire folio rmap removing
Date: Mon,  6 Feb 2023 23:30:48 +0800	[thread overview]
Message-ID: <20230206153049.770556-2-fengwei.yin@intel.com> (raw)
In-Reply-To: <20230206153049.770556-1-fengwei.yin@intel.com>

Add folio_remove_entire_rmap(). It will handle the entire
folio rmap removing.

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
---
 mm/rmap.c | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index c07c4eef3df2..3ab67b33094b 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1394,6 +1394,32 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma,
 			nr_pages, vma, compound);
 }
 
+static void folio_remove_entire_rmap(struct folio *folio,
+					int *nr, int *nr_pmdmapped)
+{
+	bool last;
+	atomic_t *mapped = &folio->_nr_pages_mapped;
+
+	last = atomic_add_negative(-1, &folio->_entire_mapcount);
+	if (last) {
+		*nr = atomic_sub_return_relaxed(COMPOUND_MAPPED, mapped);
+		if (likely(*nr < COMPOUND_MAPPED)) {
+			*nr_pmdmapped = folio_nr_pages(folio);
+			*nr = *nr_pmdmapped - (*nr & FOLIO_PAGES_MAPPED);
+
+			/* Raced ahead of another remove and an add? */
+			if (unlikely(*nr < 0))
+				*nr = 0;
+		} else {
+			/* An add of COMPOUND_MAPPED raced ahead */
+			*nr = 0;
+		}
+	}
+
+	if (!folio_test_pmd_mappable(folio))
+		*nr_pmdmapped = 0;
+}
+
 /**
  * page_remove_rmap - take down pte mapping from a page
  * @page:	page to remove mapping from
@@ -1431,20 +1457,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma,
 	} else if (folio_test_pmd_mappable(folio)) {
 		/* That test is redundant: it's for safety or to optimize out */
 
-		last = atomic_add_negative(-1, &folio->_entire_mapcount);
-		if (last) {
-			nr = atomic_sub_return_relaxed(COMPOUND_MAPPED, mapped);
-			if (likely(nr < COMPOUND_MAPPED)) {
-				nr_pmdmapped = folio_nr_pages(folio);
-				nr = nr_pmdmapped - (nr & FOLIO_PAGES_MAPPED);
-				/* Raced ahead of another remove and an add? */
-				if (unlikely(nr < 0))
-					nr = 0;
-			} else {
-				/* An add of COMPOUND_MAPPED raced ahead */
-				nr = 0;
-			}
-		}
+		folio_remove_entire_rmap(folio, &nr, &nr_pmdmapped);
 	}
 
 	if (nr_pmdmapped) {
-- 
2.30.2



  reply	other threads:[~2023-02-06 15:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 15:30 [RFC PATCH 0/2] remove parameter 'compound' of add_file_rmap Yin Fengwei
2023-02-06 15:30 ` Yin Fengwei [this message]
2023-02-06 15:30 ` [RFC PATCH 2/2] rmap: remove parameter 'compound' from foeio_add_file_rmap_range() Yin Fengwei
2023-02-06 16:50   ` Matthew Wilcox
2023-02-07  2:44     ` Yin, Fengwei
2023-02-07  5:03       ` Matthew Wilcox
2023-02-07  5:35         ` Yin, Fengwei

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=20230206153049.770556-2-fengwei.yin@intel.com \
    --to=fengwei.yin@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=linux-mm@kvack.org \
    --cc=tim.c.chen@intel.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.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