Re: [RFC PATCH] madvise: make madvise_cold_or_pageout_pte_range() support large folio
From: Yin, Fengwei
Date: Fri Jul 14 2023 - 09:58:38 EST
On 7/14/2023 5:25 PM, David Hildenbrand wrote:
>
> (1) We're unmapping a single subpage, the compound_mapcount == 0
> and the total_mapcount > 0. If the subpage mapcount is now 0, add it
> to the deferred split queue.
>
> (2) We're unmapping a complete folio (PMD mapping / compound), the
> compound_mapcount is 0 and the total_mapcount > 0.
>
> (a) If total mapcount < folio_nr_pages, add it
> to the deferred split queue.
>
> (b) If total mapcount >= folio_nr_pages , we have to scan all subpage
> mapcounts. If any subpage mapcount == 0, add it to the deferred
> split queue.
>
>
> (b) is a bit nasty. It would happen when we fork() with a PMD-mapped THP, the parent splits the THP due to COW, and then our child unmaps or splits the PMD-mapped THP (unmap easily happening during exec()). Fortunately, we'd only scan once when unmapping the PMD.
>
>
> Getting rid of the subpage mapcount usage in (1) would mean that we have to do exactly what we do in (2). But then we'd need to ha handle (2) (B) differently as well.
>
> So, for 2 (b) we would either need some other heuristic, or we add it to the deferred split queue more frequently and let that one detect using an rmap walk "well, every subpage is still mapped, let's abort the split".
Or another option for 2 (b): don't add it to deferred split queue. We
know the folio in deferred list is mainly scanned when system needs to
reclaim memory.
Maybe it's better to let page reclaim choose the large folio here because
page reclaiming will call folio_referenced() which does rmap_walk()->pvmw().
And we can reuse rmap_walk() in folio_referenced() to detect whether there
are pages of folio are not mapped. If it's the case, we can split it then.
Comparing to deferred list, the advantage is that folio_referenced() doesn't
unmap page. While in deferred list, we need to add extra rmap_walk() to
check whether there is page not mapped.
Just a thought. I could miss something here. Thanks.
Regards
Yin, Fengwei