Re: [PATCH 3/4] mm/madvise: skip zone device folios in cold/pageout PMD range

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups dev.linux.lists.damon,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <anSUb_KvuBEMnAMq@lucifer>
On Tue, Jul 28, 2026 at 03:47:13PM -0400, Gregory Price wrote:
> madvise_cold_or_pageout_pte_range() resolves the folio backing a PMD
> via pmd_folio() and ages or reclaims it without checking for zone
> device memory.
>
> The surrounding guards do not cover every zone device case:
>
>   - can_madv_lru_vma() excludes VM_PFNMAP and VM_HUGETLB VMAs
>     (so device DAX is filtered)
>
>   - !pmd_present() branch above rejects device-private and
>     migration entries, which are non-present.
>
>   - A present zone device PMD - e.g. a device-coherent THP - is
>     not filtered by any of these, nor by pmd_folio() (unlike
>     vm_normal_page_pmd(), it performs no special/pfnmap check),
>     and would be aged or paged out here.
>
> Skip ZONE_DEVICE folios explicitly during MADV_COLD/PAGEOUT.
>
> Signed-off-by: Gregory Price (Meta) <[email protected]>

LGTM so:

Reviewed-by: Lorenzo Stoakes (ARM) <[email protected]>

> ---
>  mm/madvise.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 07a21ca31bad..ffd6a68320a8 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -395,6 +395,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
>
>  		folio = pmd_folio(orig_pmd);
>
> +		if (folio_is_zone_device(folio))
> +			goto huge_unlock;
> +
>  		/* Do not interfere with other mappings of this folio */
>  		if (folio_maybe_mapped_shared(folio))
>  			goto huge_unlock;
> --
> 2.55.0
>

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.