[RFC PATCH v4 06/27] mm/mlock: skip mlock for managed-memory folios

Gregory Price
2026-02-22T08:49:18Z

Private node folios are managed by device drivers and should not be
mlocked. The existing folio_is_zone_device check is already correctly
placed to handle this - simply extend it for private nodes.

Signed-off-by: Gregory Price <gourry@gourry.net>
---
mm/mlock.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index 2f699c3497a5..c56159253e45 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -25,6 +25,7 @@
#include <linux/memcontrol.h>
#include <linux/mm_inline.h>
#include <linux/secretmem.h>
+#include <linux/node_private.h>

#include "internal.h"

@@ -366,7 +367,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr,
if (is_huge_zero_pmd(*pmd))
goto out;
folio = pmd_folio(*pmd);
- if (folio_is_zone_device(folio))
+ if (unlikely(folio_is_private_managed(folio)))
goto out;
if (vma->vm_flags & VM_LOCKED)
mlock_folio(folio);
@@ -386,7 +387,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr,
if (!pte_present(ptent))
continue;
folio = vm_normal_folio(vma, addr, ptent);
- if (!folio || folio_is_zone_device(folio))
+ if (!folio || unlikely(folio_is_private_managed(folio)))
continue;

step = folio_mlock_step(folio, pte, addr, end);
--
2.53.0