Replace direct uses of FOLIO_MAPPING_ANON in external modules with helper functions in preparation for ANON_VMA_LAZY. Signed-off-by: tao --- fs/proc/page.c | 6 ++---- include/linux/page-flags.h | 15 ++++++++++++--- include/linux/pagemap.h | 2 +- mm/gup.c | 6 ++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index f9b2c2c906cd..93ddfda9fa1d 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -148,7 +148,6 @@ u64 stable_page_flags(const struct page *page) const struct folio *folio; struct page_snapshot ps; unsigned long k; - unsigned long mapping; bool is_anon; u64 u = 0; @@ -163,8 +162,7 @@ u64 stable_page_flags(const struct page *page) folio = &ps.folio_snapshot; k = folio->flags.f; - mapping = (unsigned long)folio->mapping; - is_anon = mapping & FOLIO_MAPPING_ANON; + is_anon = folio_test_anon(folio); /* * pseudo flags for the well known (anonymous) memory mapped pages @@ -173,7 +171,7 @@ u64 stable_page_flags(const struct page *page) u |= 1 << KPF_MMAP; if (is_anon) { u |= 1 << KPF_ANON; - if (mapping & FOLIO_MAPPING_KSM) + if (!PageAnonNotKsm(page)) u |= 1 << KPF_KSM; } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index c0cc43118877..50c80a1e2c7c 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -720,15 +720,20 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted) #define FOLIO_MAPPING_ANON_VMA_LAZY FOLIO_MAPPING_ANON_KSM #define FOLIO_MAPPING_FLAGS (FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM) -static __always_inline bool folio_test_anon(const struct folio *folio) +static __always_inline bool mapping_is_anon(unsigned long mapping) { #ifdef CONFIG_ANON_VMA_LAZY - return ((unsigned long)folio->mapping & FOLIO_MAPPING_FLAGS) != 0; + return (mapping & FOLIO_MAPPING_FLAGS) != 0; #else - return ((unsigned long)folio->mapping & FOLIO_MAPPING_ANON) != 0; + return (mapping & FOLIO_MAPPING_ANON) != 0; #endif } +static __always_inline bool folio_test_anon(const struct folio *folio) +{ + return mapping_is_anon((unsigned long)folio->mapping); +} + static __always_inline bool folio_test_lazyfree(const struct folio *folio) { return folio_test_anon(folio) && !folio_test_swapbacked(folio); @@ -738,7 +743,11 @@ static __always_inline bool PageAnonNotKsm(const struct page *page) { unsigned long flags = (unsigned long)page_folio(page)->mapping; +#ifdef CONFIG_ANON_VMA_LAZY + return (flags & FOLIO_MAPPING_FLAGS) != FOLIO_MAPPING_KSM; +#else return (flags & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_ANON; +#endif } static __always_inline bool PageAnon(const struct page *page) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 31a848485ad9..746939872ac4 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -507,7 +507,7 @@ static inline pgoff_t mapping_align_index(const struct address_space *mapping, static inline bool mapping_large_folio_support(const struct address_space *mapping) { /* AS_FOLIO_ORDER is only reasonable for pagecache folios */ - VM_WARN_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON, + VM_WARN_ONCE(mapping_is_anon((unsigned long)mapping), "Anonymous mapping always supports large folio"); return mapping_max_folio_order(mapping) > 0; diff --git a/mm/gup.c b/mm/gup.c index ad9ded39609c..69dda325b082 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2740,7 +2740,6 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) bool reject_file_backed = false; struct address_space *mapping; bool check_secretmem = false; - unsigned long mapping_flags; /* * If we aren't pinning then no problematic write can occur. A long term @@ -2792,9 +2791,8 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) return false; /* Anonymous folios pose no problem. */ - mapping_flags = (unsigned long)mapping & FOLIO_MAPPING_FLAGS; - if (mapping_flags) - return mapping_flags & FOLIO_MAPPING_ANON; + if (mapping_is_anon((unsigned long)mapping)) + return true; /* * At this point, we know the mapping is non-null and points to an -- 2.17.1