Re: [PATCH 7/7] mm, swap: simplify folio swap allocation

From: Kairui Song
Date: Sat Feb 15 2025 - 01:41:04 EST


On Sat, Feb 15, 2025 at 4:13 AM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
>
> On Sat, Feb 15, 2025 at 01:57:09AM +0800, Kairui Song wrote:
> > @@ -1648,20 +1639,20 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
> > if (list_empty(&info->swaplist))
> > list_add(&info->swaplist, &shmem_swaplist);
> >
> > - if (add_to_swap_cache(folio, swap,
> > - __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN,
> > - NULL) == 0) {
> > + if (folio_alloc_swap(folio, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
>
> add_to_swap_cache() returns 0 on success or -errno.
>
> folio_alloc_swap returns true on success.
>
> That would seem to indicate you should change the polarity of this test?

I think I already did? It was (add_to_swap_cache(...) == 0), now it's
(folio_alloc_swap(...))

>
> Or should folio_alloc_swap() return an errno? Is there value in
> distinguishing why we couldn't alloc swap (ENOMEM vs ENOSPC, perhaps?)
>

Good idea, return an error value might be more helpful in the future,
will update this part.