[PATCH v6 34/39] mm: eliminate VMA_SPECIAL_FLAGS usage when hugetlb explicitly tested
Lorenzo Stoakes (ARM)
ljs at kernel.org
Tue Oct 13 08:05:14 PDT 2026
It is now an invariant that VMA_IO_BIT is not set by mm-managed mappings,
so each existing VMA_SPECIAL_FLAGS test need only test for
VMA_DONTEXPAND_BIT, VMA_PFNMAP_BIT and VMA_MIXEDMAP_BIT.
This is precisely a test for a fixed or non-mm-managed mapping.
Update a number of callsites which already explicitly handle hugetlb
mappings.
vma_supports_mlock(), ksm_compatible() and should_skip_vma() explicitly
check for non-mm-managed or fixed mappings, i.e. for !vma_is_mm_backed(),
with hugetlb having already been excluded separately.
So update those to check for mm-backed (and add comments for the retained
droppable checks).
No functional change intended.
Reviewed-by: Zi Yan <ziy at nvidia.com>
Acked-by: David Hildenbrand (Arm) <david at kernel.org>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs at kernel.org>
---
mm/internal.h | 3 ++-
mm/ksm.c | 5 +++--
mm/vmscan.c | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/mm/internal.h b/mm/internal.h
index b5f7be8f65d8..03f2bb4c30b7 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1112,8 +1112,9 @@ static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
static inline bool vma_supports_mlock(const struct vm_area_struct *vma)
{
- if (vma_test_any_mask(vma, VMA_SPECIAL_FLAGS))
+ if (!vma_is_mm_backed(vma))
return false;
+ /* Core mm may discard droppable memory at any time. */
if (vma_test_single_mask(vma, VMA_DROPPABLE))
return false;
if (vma_is_dax(vma) || vma_is_hugetlb(vma))
diff --git a/mm/ksm.c b/mm/ksm.c
index 624f37975e12..df4c5199f625 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -747,9 +747,10 @@ static bool ksm_compatible(const struct file *file, vma_flags_t vma_flags)
if (vma_flags_test_any(&vma_flags, VMA_SHARED_BIT, VMA_MAYSHARE_BIT,
VMA_HUGETLB_BIT))
return false;
- if (vma_flags_test_single_mask(&vma_flags, VMA_DROPPABLE))
+ if (!vma_flags_is_mm_backed(&vma_flags))
return false;
- if (vma_flags_test_any_mask(&vma_flags, VMA_SPECIAL_FLAGS))
+ /* Core mm may discard droppable memory at any time. */
+ if (vma_flags_test_single_mask(&vma_flags, VMA_DROPPABLE))
return false;
if (file_is_dax(file))
return false;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 12ed3388ee41..aecb157bc379 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3477,7 +3477,7 @@ static int should_skip_vma(unsigned long start, unsigned long end, struct mm_wal
if (!vma_has_recency(vma))
return true;
- if (vma->vm_flags & (VM_LOCKED | VM_SPECIAL))
+ if (vma_test(vma, VMA_LOCKED_BIT) || !vma_is_mm_backed(vma))
return true;
if (vma == get_gate_vma(vma->vm_mm))
--
2.55.0
More information about the kvm-riscv
mailing list