Re: [PATCH v2 2/6] shmem: return freed pages in shmem_free_swap

From: Matthew Wilcox
Date: Tue Sep 19 2023 - 10:56:17 EST


On Tue, Sep 19, 2023 at 01:55:47PM +0000, Daniel Gomez wrote:
> +++ b/mm/shmem.c
> @@ -846,16 +846,18 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap)
> /*
> * Remove swap entry from page cache, free the swap and its page cache.
> */
> -static int shmem_free_swap(struct address_space *mapping,
> +static long shmem_free_swap(struct address_space *mapping,
> pgoff_t index, void *radswap)
> {
> void *old;
>
> old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0);
> if (old != radswap)
> - return -ENOENT;
> + return 0;
> +
> free_swap_and_cache(radix_to_swp_entry(radswap));
> - return 0;
> +
> + return folio_nr_pages((struct folio *)radswap);
> }

Oh my goodness. I have led you astray; my apologies.

shmem_free_swap() is called when the 'folio' is NOT actually a folio.
It's an 'exceptional' / 'value' entry. We can't do this.

Do we encode the size of the swap entry in the swp_entry_t or do
we have to get that information from the XArray (which no longer
knows it after we've stored a NULL there)?