From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Kravetz <mike.kravetz@oracle.com>,
Muchun Song <muchun.song@linux.dev>
Subject: [PATCH v1 5/6] mm/rmap: simplify PageAnonExclusive sanity checks when adding anon rmap
Date: Wed, 13 Sep 2023 14:51:12 +0200 [thread overview]
Message-ID: <20230913125113.313322-6-david@redhat.com> (raw)
In-Reply-To: <20230913125113.313322-1-david@redhat.com>
Let's sanity-check PageAnonExclusive vs. mapcount in page_add_anon_rmap()
and hugepage_add_anon_rmap() after setting PageAnonExclusive simply by
re-reading the mapcounts.
We can stop initializing the "first" variable in page_add_anon_rmap()
and no longer need an atomic_inc_and_test() in hugepage_add_anon_rmap().
While at it, switch to VM_WARN_ON_FOLIO().
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/rmap.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 489c142d073b..10d477a0991f 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1199,7 +1199,7 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
atomic_t *mapped = &folio->_nr_pages_mapped;
int nr = 0, nr_pmdmapped = 0;
bool compound = flags & RMAP_COMPOUND;
- bool first = true;
+ bool first;
/* Is page being mapped by PTE? Is this its first map to be added? */
if (likely(!compound)) {
@@ -1228,9 +1228,6 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
}
}
- VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page);
- VM_BUG_ON_PAGE(!first && PageAnonExclusive(page), page);
-
if (nr_pmdmapped)
__lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr_pmdmapped);
if (nr)
@@ -1252,6 +1249,8 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
}
if (flags & RMAP_EXCLUSIVE)
SetPageAnonExclusive(page);
+ VM_WARN_ON_FOLIO(page_mapcount(page) > 1 && PageAnonExclusive(page),
+ folio);
mlock_vma_folio(folio, vma, compound);
}
@@ -2532,15 +2531,14 @@ void hugepage_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
unsigned long address, rmap_t flags)
{
struct folio *folio = page_folio(page);
- int first;
VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
- first = atomic_inc_and_test(&folio->_entire_mapcount);
- VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page);
- VM_BUG_ON_PAGE(!first && PageAnonExclusive(page), page);
+ atomic_inc(&folio->_entire_mapcount);
if (flags & RMAP_EXCLUSIVE)
SetPageAnonExclusive(page);
+ VM_WARN_ON_FOLIO(folio_entire_mapcount(folio) > 1 &&
+ PageAnonExclusive(page), folio);
}
void hugepage_add_new_anon_rmap(struct folio *folio,
--
2.41.0
next prev parent reply other threads:[~2023-09-13 12:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 12:51 [PATCH v1 0/6] Anon rmap cleanups David Hildenbrand
2023-09-13 12:51 ` [PATCH v1 1/6] mm/rmap: drop stale comment in page_add_anon_rmap and hugepage_add_anon_rmap() David Hildenbrand
2023-09-13 12:51 ` [PATCH v1 2/6] mm/rmap: move SetPageAnonExclusive out of __page_set_anon_rmap() David Hildenbrand
2023-09-13 14:32 ` Matthew Wilcox
2023-09-13 14:34 ` David Hildenbrand
2023-09-13 12:51 ` [PATCH v1 3/6] mm/rmap: move folio_test_anon() check out of __folio_set_anon() David Hildenbrand
2023-09-13 12:51 ` [PATCH v1 4/6] mm/rmap: warn on new PTE-mapped folios in page_add_anon_rmap() David Hildenbrand
2023-09-13 12:51 ` David Hildenbrand [this message]
2023-09-18 9:59 ` [PATCH v1 5/6] mm/rmap: simplify PageAnonExclusive sanity checks when adding anon rmap David Hildenbrand
2023-09-13 12:51 ` [PATCH v1 6/6] mm/rmap: pass folio to hugepage_add_anon_rmap() David Hildenbrand
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=20230913125113.313322-6-david@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
/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