From 00948a240eb83d0409bc3b1426d087e64e791e36 Mon Sep 17 00:00:00 2001 From: Kefeng Wang Date: Tue, 14 Oct 2025 19:33:47 +0800 Subject: [PATCH] mm: mprotect: always skip dma pinned folio in prot_numa_skip() Patch series "mm: some optimizations for prot numa", v2. This patch (of 3): If the folio (even not CoW folio) is dma pinned, it can't be migrated due to the elevated reference count. So always skip a pinned folio to avoid wasting cycles when folios are migrated. Link: https://lkml.kernel.org/r/20251014113349.2618158-1-wangkefeng.wang@huawei.com Link: https://lkml.kernel.org/r/20251014113349.2618158-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang Reviewed-by: Sidhartha Kumar Acked-by: David Hildenbrand Reviewed-by: Lance Yang Reviewed-by: Barry Song Reviewed-by: Dev Jain Acked-by: Zi Yan Reviewed-by: Lorenzo Stoakes Cc: Baolin Wang Cc: Liam Howlett Cc: Ryan Roberts Signed-off-by: Andrew Morton --- mm/mprotect.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 988c366137d5..056986d9076a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -136,9 +136,12 @@ static bool prot_numa_skip(struct vm_area_struct *vma, unsigned long addr, if (folio_is_zone_device(folio) || folio_test_ksm(folio)) goto skip; - /* Also skip shared copy-on-write pages */ - if (is_cow_mapping(vma->vm_flags) && - (folio_maybe_dma_pinned(folio) || folio_maybe_mapped_shared(folio))) + /* Also skip shared copy-on-write folios */ + if (is_cow_mapping(vma->vm_flags) && folio_maybe_mapped_shared(folio)) + goto skip; + + /* Folios are pinned and can't be migrated */ + if (folio_maybe_dma_pinned(folio)) goto skip; /* -- 2.51.0