mm/rmap: simplify PageAnonExclusive sanity checks when adding anon rmap
authorDavid Hildenbrand <david@redhat.com>
Wed, 13 Sep 2023 12:51:12 +0000 (14:51 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Oct 2023 17:32:27 +0000 (10:32 -0700)
commit132b180f06a74ddfc526709928036db3b7a1cf6d
tree334eadd59db3cfef2d05b32f05438bd8378aebf0
parenta1f34ee1de2c3a55bc2a6b9a38e1ecd2830dcc03
mm/rmap: simplify PageAnonExclusive sanity checks when adding anon rmap

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().

[david@redhat.com: update check for doubly-mapped page]
Link: https://lkml.kernel.org/r/d8e5a093-2e22-c14b-7e64-6da280398d9f@redhat.com
Link: https://lkml.kernel.org/r/20230913125113.313322-6-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/rmap.c