On Sat, 3 Aug 2024 00:20:31 +1200 Barry Song <21cnbao@xxxxxxxxx> wrote: > From: Chuanhua Han <hanchuanhua@xxxxxxxx> > > Currently, we have mTHP features, but unfortunately, without support for large > folio swap-ins, once these large folios are swapped out, they are lost because > mTHP swap is a one-way process. The lack of mTHP swap-in functionality prevents > mTHP from being used on devices like Android that heavily rely on swap. > > This patch introduces mTHP swap-in support. It starts from sync devices such > as zRAM. This is probably the simplest and most common use case, benefiting > billions of Android phones and similar devices with minimal implementation > cost. In this straightforward scenario, large folios are always exclusive, > eliminating the need to handle complex rmap and swapcache issues. > > It offers several benefits: > 1. Enables bidirectional mTHP swapping, allowing retrieval of mTHP after > swap-out and swap-in. Large folios in the buddy system are also > preserved as much as possible, rather than being fragmented due > to swap-in. > > 2. Eliminates fragmentation in swap slots and supports successful > THP_SWPOUT. > > w/o this patch (Refer to the data from Chris's and Kairui's latest > swap allocator optimization while running ./thp_swap_allocator_test > w/o "-a" option [1]): > > ... > > +static struct folio *alloc_swap_folio(struct vm_fault *vmf) > +{ > + struct vm_area_struct *vma = vmf->vma; > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > ... > > +#endif > + return vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vmf->address, false); > +} Generates an unused-variable warning with allnoconfig. Because vma_alloc_folio_noprof() was implemented as a macro instead of an inlined C function. Why do we keep doing this. Please check: From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Subject: mm-support-large-folios-swap-in-for-zram-like-devices-fix Date: Sat Aug 3 11:59:00 AM PDT 2024 fix unused var warning mm/memory.c: In function 'alloc_swap_folio': mm/memory.c:4062:32: warning: unused variable 'vma' [-Wunused-variable] 4062 | struct vm_area_struct *vma = vmf->vma; | ^~~ Cc: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx> Cc: Barry Song <v-songbaohua@xxxxxxxx> Cc: Chris Li <chrisl@xxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> Cc: Chuanhua Han <hanchuanhua@xxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Gao Xiang <xiang@xxxxxxxxxx> Cc: "Huang, Ying" <ying.huang@xxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Kairui Song <kasong@xxxxxxxxxxx> Cc: Kalesh Singh <kaleshsingh@xxxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Cc: Nhat Pham <nphamcs@xxxxxxxxx> Cc: Ryan Roberts <ryan.roberts@xxxxxxx> Cc: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> Cc: Yang Shi <shy828301@xxxxxxxxx> Cc: Yosry Ahmed <yosryahmed@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/memory.c~mm-support-large-folios-swap-in-for-zram-like-devices-fix +++ a/mm/memory.c @@ -4059,8 +4059,8 @@ static inline bool can_swapin_thp(struct static struct folio *alloc_swap_folio(struct vm_fault *vmf) { - struct vm_area_struct *vma = vmf->vma; #ifdef CONFIG_TRANSPARENT_HUGEPAGE + struct vm_area_struct *vma = vmf->vma; unsigned long orders; struct folio *folio; unsigned long addr; @@ -4128,7 +4128,8 @@ static struct folio *alloc_swap_folio(st fallback: #endif - return vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vmf->address, false); + return vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vmf->vma, + vmf->address, false); } _