The folio_referenced() is used to test whether a folio was referenced during
reclaim. Moreover, ZONE_DEVICE folios are controlled by their device driver,
have a lifetime tied to that driver, and are never placed on the LRU list.
That means we should never try to reclaim ZONE_DEVICE folios, so add a warning
to catch this unexpected behavior in folio_referenced() to avoid confusion,
as discussed in the previous thread[1].
[1] https://lore.kernel.org/all/16fb7985-ec0f-4b56-91e7-404c5114f899@kernel.org/
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/rmap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/rmap.c b/mm/rmap.c
index bff8f222004e..be785dfc9336 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1065,6 +1065,7 @@ int folio_referenced(struct folio *folio, int is_locked,
.invalid_vma = invalid_folio_referenced_vma,
};
+ VM_WARN_ON_FOLIO(folio_is_zone_device(folio), folio);
*vm_flags = 0;
if (!pra.mapcount)
return 0;
--
2.47.3
On 2026-02-24 at 12:56 +1100, Baolin Wang <baolin.wang@linux.alibaba.com> wrote... > The folio_referenced() is used to test whether a folio was referenced during > reclaim. Moreover, ZONE_DEVICE folios are controlled by their device driver, > have a lifetime tied to that driver, and are never placed on the LRU list. > That means we should never try to reclaim ZONE_DEVICE folios, so add a warning > to catch this unexpected behavior in folio_referenced() to avoid confusion, > as discussed in the previous thread[1]. Agree with this so one you've handled Rik's comment feel free to add: Reviewed-by: Alistair Popple <apopple@nvidia.com> > [1] https://lore.kernel.org/all/16fb7985-ec0f-4b56-91e7-404c5114f899@kernel.org/ > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> > --- > mm/rmap.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/rmap.c b/mm/rmap.c > index bff8f222004e..be785dfc9336 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1065,6 +1065,7 @@ int folio_referenced(struct folio *folio, int is_locked, > .invalid_vma = invalid_folio_referenced_vma, > }; > > + VM_WARN_ON_FOLIO(folio_is_zone_device(folio), folio); > *vm_flags = 0; > if (!pra.mapcount) > return 0; > -- > 2.47.3 > >
On Tue, 2026-02-24 at 09:56 +0800, Baolin Wang wrote: > > diff --git a/mm/rmap.c b/mm/rmap.c > index bff8f222004e..be785dfc9336 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1065,6 +1065,7 @@ int folio_referenced(struct folio *folio, int > is_locked, > .invalid_vma = invalid_folio_referenced_vma, > }; > > + VM_WARN_ON_FOLIO(folio_is_zone_device(folio), folio); > *vm_flags = 0; > if (!pra.mapcount) > return 0; Should be a VM_WARN_ON_ONCE_FOLIO so we do not cause a softlockup if we try to print information about a million ZONE_DEVICE pages? -- All Rights Reversed.
On 2/24/26 10:38 AM, Rik van Riel wrote: > On Tue, 2026-02-24 at 09:56 +0800, Baolin Wang wrote: >> >> diff --git a/mm/rmap.c b/mm/rmap.c >> index bff8f222004e..be785dfc9336 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -1065,6 +1065,7 @@ int folio_referenced(struct folio *folio, int >> is_locked, >> .invalid_vma = invalid_folio_referenced_vma, >> }; >> >> + VM_WARN_ON_FOLIO(folio_is_zone_device(folio), folio); >> *vm_flags = 0; >> if (!pra.mapcount) >> return 0; > > Should be a VM_WARN_ON_ONCE_FOLIO so we do not cause > a softlockup if we try to print information about a > million ZONE_DEVICE pages? Yes, sounds reasonable. Will do in next version. Thanks for reviewing.
On 2/24/26 06:49, Baolin Wang wrote: > > > On 2/24/26 10:38 AM, Rik van Riel wrote: >> On Tue, 2026-02-24 at 09:56 +0800, Baolin Wang wrote: >>> >>> diff --git a/mm/rmap.c b/mm/rmap.c >>> index bff8f222004e..be785dfc9336 100644 >>> --- a/mm/rmap.c >>> +++ b/mm/rmap.c >>> @@ -1065,6 +1065,7 @@ int folio_referenced(struct folio *folio, int >>> is_locked, >>> .invalid_vma = invalid_folio_referenced_vma, >>> }; >>> + VM_WARN_ON_FOLIO(folio_is_zone_device(folio), folio); >>> *vm_flags = 0; >>> if (!pra.mapcount) >>> return 0; >> >> Should be a VM_WARN_ON_ONCE_FOLIO so we do not cause >> a softlockup if we try to print information about a >> million ZONE_DEVICE pages? > > Yes, sounds reasonable. Will do in next version. Thanks for reviewing. Feel free to add my Acked-by: David Hildenbrand (Arm) <david@kernel.org> to that. -- Cheers, David
© 2016 - 2026 Red Hat, Inc.