Re: [PATCH 09/10] MM: submit multipage write for SWP_FS_OPS swap-space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2022/3/30 7:49, NeilBrown wrote:
> swap_writepage() is given one page at a time, but may be called repeatedly
> in succession.
> For block-device swapspace, the blk_plug functionality allows the
> multiple pages to be combined together at lower layers.
> That cannot be used for SWP_FS_OPS as blk_plug may not exist - it is
> only active when CONFIG_BLOCK=y.  Consequently all swap reads over NFS
> are single page reads.
> 
> With this patch we pass a pointer-to-pointer via the wbc.
> swap_writepage can store state between calls - much like the pointer
> passed explicitly to swap_readpage.  After calling swap_writepage() some
> number of times, the state will be passed to swap_write_unplug() which
> can submit the combined request.
> 
> Reviewed-by: Christoph Hellwig <hch@xxxxxx>
> Signed-off-by: NeilBrown <neilb@xxxxxxx>
...
>  
>  static int swap_writepage_fs(struct page *page, struct writeback_control *wbc)
>  {
> -	struct swap_iocb *sio;
> +	struct swap_iocb *sio = NULL;
>  	struct swap_info_struct *sis = page_swap_info(page);
>  	struct file *swap_file = sis->swap_file;
> -	struct address_space *mapping = swap_file->f_mapping;
> -	struct iov_iter from;
> -	int ret;
> +	loff_t pos = page_file_offset(page);
>  
>  	set_page_writeback(page);
>  	unlock_page(page);
> -	sio = mempool_alloc(sio_pool, GFP_NOIO);
> -	init_sync_kiocb(&sio->iocb, swap_file);
> -	sio->iocb.ki_complete = sio_write_complete;
> -	sio->iocb.ki_pos = page_file_offset(page);
> -	sio->bvec[0].bv_page = page;
> -	sio->bvec[0].bv_len = PAGE_SIZE;
> -	sio->bvec[0].bv_offset = 0;
> -	iov_iter_bvec(&from, WRITE, &sio->bvec[0], 1, PAGE_SIZE);
> -	ret = mapping->a_ops->swap_rw(&sio->iocb, &from);
> -	if (ret != -EIOCBQUEUED)
> -		sio_write_complete(&sio->iocb, ret);
> -	return ret;
> +	if (wbc->swap_plug)
> +		sio = *wbc->swap_plug;
> +	if (sio) {
> +		if (sio->iocb.ki_filp != swap_file ||
> +		    sio->iocb.ki_pos + sio->pages * PAGE_SIZE != pos) {
> +			swap_write_unplug(sio);
> +			sio = NULL;
> +		}
> +	}
> +	if (!sio) {
> +		sio = mempool_alloc(sio_pool, GFP_NOIO);
> +		init_sync_kiocb(&sio->iocb, swap_file);
> +		sio->iocb.ki_complete = sio_write_complete;
> +		sio->iocb.ki_pos = pos;
> +		sio->pages = 0;
> +	}
> +	sio->bvec[sio->pages].bv_page = page;
> +	sio->bvec[sio->pages].bv_len = PAGE_SIZE;

Many thanks for your patch. And sorry for late responding and newbie question. Does swap_writepage_fs
support transhuge page now? We could come across transhuge page here. But bv_len == PAGE_SIZE and pages
== 1 is assumed here. Do we need something like below:

sio->bvec[sio->pages].bv_len = thp_size(page);
sio->pages += thp_nr_pages(page);

Thanks! :)

> +	sio->bvec[sio->pages].bv_offset = 0;
...
> .
> 




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux