]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: add folio_test_lazyfree helper
authorVernon Yang <yanglincheng@kylinos.cn>
Sat, 21 Feb 2026 09:39:17 +0000 (17:39 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 5 Apr 2026 20:53:03 +0000 (13:53 -0700)
Add folio_test_lazyfree() function to identify lazy-free folios to improve
code readability.

Link: https://lkml.kernel.org/r/20260221093918.1456187-4-vernon2gm@gmail.com
Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Barry Song <baohua@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam Howlett <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Nico Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/page-flags.h
mm/rmap.c
mm/vmscan.c

index f7a0e4af0c734404ae738670c3aa7d67dd3820c3..415e9f2ef616b5ec6bc1bbf8ef60077e00f3caff 100644 (file)
@@ -724,6 +724,11 @@ static __always_inline bool folio_test_anon(const struct folio *folio)
        return ((unsigned long)folio->mapping & FOLIO_MAPPING_ANON) != 0;
 }
 
+static __always_inline bool folio_test_lazyfree(const struct folio *folio)
+{
+       return folio_test_anon(folio) && !folio_test_swapbacked(folio);
+}
+
 static __always_inline bool PageAnonNotKsm(const struct page *page)
 {
        unsigned long flags = (unsigned long)page_folio(page)->mapping;
index 8f08090d7eb9f28ab30829ff795954822914b9fc..5fd22ba59d35504585c1d6504d3062932dde6309 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -2060,7 +2060,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
                }
 
                if (!pvmw.pte) {
-                       if (folio_test_anon(folio) && !folio_test_swapbacked(folio)) {
+                       if (folio_test_lazyfree(folio)) {
                                if (unmap_huge_pmd_locked(vma, pvmw.address, pvmw.pmd, folio))
                                        goto walk_done;
                                /*
index 031c5c035a828203a398dfd08349ec98cf361fe3..d531040a3593c997573c69e83548fbaf17430e80 100644 (file)
@@ -963,8 +963,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
         * They could be mistakenly treated as file lru. So further anon
         * test is needed.
         */
-       if (!folio_is_file_lru(folio) ||
-           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
+       if (!folio_is_file_lru(folio) || folio_test_lazyfree(folio)) {
                *dirty = false;
                *writeback = false;
                return;
@@ -1508,7 +1507,7 @@ retry:
                        }
                }
 
-               if (folio_test_anon(folio) && !folio_test_swapbacked(folio)) {
+               if (folio_test_lazyfree(folio)) {
                        /* follow __remove_mapping for reference */
                        if (!folio_ref_freeze(folio, 1))
                                goto keep_locked;