Re: [PATCH 03/18] MM: use ->swap_rw for reads from SWP_FS_OPS swap-space

From: Mark Hemment
Date: Mon Dec 20 2021 - 07:16:43 EST


On Thu, 16 Dec 2021 at 23:54, NeilBrown <neilb@xxxxxxx> wrote:
>
> To submit an async read with ->swap_rw() we need to allocate
> a structure to hold the kiocb and other details. swap_readpage() cannot
> handle transient failure, so create a mempool to provide the structures.
>
> Signed-off-by: NeilBrown <neilb@xxxxxxx>
> ---
> mm/page_io.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------
> mm/swap.h | 1 +
> mm/swapfile.c | 5 +++++
> 3 files changed, 58 insertions(+), 6 deletions(-)
...
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f23d9ff21cf8..43539be38e68 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2401,6 +2401,11 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
> if (ret < 0)
> return ret;
> sis->flags |= SWP_ACTIVATED;
> + if ((sis->flags & SWP_FS_OPS) &&
> + sio_pool_init() != 0) {
> + destroy_swap_extents(sis);
> + return -ENOMEM;
> + }
> return ret;
> }

This code is called before 'swapon_mutex' is taken in the swapon code
path, so possible for multiple swapons to race here creating two (or
more) memory pools.

Mark