Re: [PATCH -mm] mm, swap, frontswap: Fix THP swap if frontswap enabled

From: Minchan Kim
Date: Tue Feb 06 2018 - 09:14:41 EST


Hi Sergey,

On Tue, Feb 06, 2018 at 06:48:22PM +0900, Sergey Senozhatsky wrote:
> Hello,
>
> On (02/06/18 01:02), Minchan Kim wrote:
> [..]
> > Can't we simple do like that if you want to make it simple and rely on someone
> > who makes frontswap THP-aware later?
> >
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index 42fe5653814a..4bf1725407aa 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -934,7 +934,11 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
> >
> > /* Only single cluster request supported */
> > WARN_ON_ONCE(n_goal > 1 && cluster);
> > +#ifdef CONFIG_FRONTSWAP
>
> Wouldn't #ifdef CONFIG_THP_SWAP be better? frontswap_enabled() is 'false'
> on CONFIG_FRONTSWAP configs, should be compiled out anyway.

Agree.

>
> > + /* Now, frontswap doesn't support THP page */
> > + if (frontswap_enabled() && cluster)
> > + return;
> > +#endif
> > avail_pgs = atomic_long_read(&nr_swap_pages) / nr_pages;
> > if (avail_pgs <= 0)
> > goto noswap;
>
> Looks interesting. Technically, can be done earlier - in get_swap_page(),
> can't it? get_swap_page() has the PageTransHuge(page) && CONFIG_THP_SWAP
> condition checks. Can add frontswap dependency there. Something like
>
> if (PageTransHuge(page)) {
> if (IS_ENABLED(CONFIG_THP_SWAP))
> + if (!frontswap_enabled())
> get_swap_pages(1, true, &entry);
> return entry;
> }

Looks better but it introduces frontswap thing to swap_slots.c while
all frontswap works in swapfile.c.