Linux-EROFS Archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Chunhai Guo <guochunhai@vivo.com>, xiang@kernel.org
Cc: linux-erofs@lists.ozlabs.org, huyue2@coolpad.com
Subject: Re: [PATCH] erofs: do not use pagepool in z_erofs_gbuf_growsize()
Date: Tue, 2 Apr 2024 16:57:29 +0800	[thread overview]
Message-ID: <b904fbcd-653d-4548-b354-213f5c4563ea@linux.alibaba.com> (raw)
In-Reply-To: <20240402084031.2623314-1-guochunhai@vivo.com>



On 2024/4/2 16:40, Chunhai Guo wrote:
> Let's use alloc_pages_bulk_array() for simplicity and get rid of
> unnecessary pagepool.
> 
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
> ---
>   fs/erofs/zutil.c | 64 +++++++++++++++++++++++-------------------------
>   1 file changed, 30 insertions(+), 34 deletions(-)
> 
> diff --git a/fs/erofs/zutil.c b/fs/erofs/zutil.c
> index e13806681763..14440c0bf64e 100644
> --- a/fs/erofs/zutil.c
> +++ b/fs/erofs/zutil.c
> @@ -60,61 +60,57 @@ void z_erofs_put_gbuf(void *ptr) __releases(gbuf->lock)
>   int z_erofs_gbuf_growsize(unsigned int nrpages)
>   {
>   	static DEFINE_MUTEX(gbuf_resize_mutex);
> -	struct page *pagepool = NULL;
> -	int delta, ret, i, j;
> +	struct page **tmp_pages = NULL;
> +	struct z_erofs_gbuf *gbuf;
> +	void *ptr, *old_ptr;
> +	int last, i, j;
> +	int ret = 0;

no needed.

>   
>   	mutex_lock(&gbuf_resize_mutex);
> -	delta = nrpages - z_erofs_gbuf_nrpages;
> -	ret = 0;
>   	/* avoid shrinking gbufs, since no idea how many fses rely on */
> -	if (delta <= 0)
> +	if (nrpages <= z_erofs_gbuf_nrpages)
>   		goto out;

	if (nrpages <= z_erofs_gbuf_nrpages) {
		mutex_unlock(&gbuf_resize_mutex);
		return 0;
	}

since it's a fast side path, let's bail out this directly.

>   
> +	ret = -ENOMEM;

no needed.

>   	for (i = 0; i < z_erofs_gbuf_count; ++i) {
> -		struct z_erofs_gbuf *gbuf = &z_erofs_gbufpool[i];
> -		struct page **pages, **tmp_pages;
> -		void *ptr, *old_ptr = NULL;
> -
> -		ret = -ENOMEM;
> +		gbuf = &z_erofs_gbufpool[i];
>   		tmp_pages = kcalloc(nrpages, sizeof(*tmp_pages), GFP_KERNEL);
>   		if (!tmp_pages)
> -			break;
> -		for (j = 0; j < nrpages; ++j) {
> -			tmp_pages[j] = erofs_allocpage(&pagepool, GFP_KERNEL);
> -			if (!tmp_pages[j])
> -				goto free_pagearray;
> -		}
> +			goto out;
> +
> +		for (j = 0; j < gbuf->nrpages; ++j)
> +			tmp_pages[j] = gbuf->pages[j];
> +		do {
> +			last = j;
> +			j = alloc_pages_bulk_array(GFP_KERNEL, nrpages,
> +						   tmp_pages);
> +			if (last == j)
> +				goto out;
> +		} while (j != nrpages);
> +
>   		ptr = vmap(tmp_pages, nrpages, VM_MAP, PAGE_KERNEL);
>   		if (!ptr)
> -			goto free_pagearray;
> +			goto out;
>   
> -		pages = tmp_pages;
>   		spin_lock(&gbuf->lock);
> +		kfree(gbuf->pages);
> +		gbuf->pages = tmp_pages;
>   		old_ptr = gbuf->ptr;
>   		gbuf->ptr = ptr;
> -		tmp_pages = gbuf->pages;
> -		gbuf->pages = pages;
> -		j = gbuf->nrpages;
>   		gbuf->nrpages = nrpages;
>   		spin_unlock(&gbuf->lock);
> -		ret = 0;
> -		if (!tmp_pages) {
> -			DBG_BUGON(old_ptr);
> -			continue;
> -		}
> -
>   		if (old_ptr)
>   			vunmap(old_ptr);
> -free_pagearray:
> -		while (j)
> -			erofs_pagepool_add(&pagepool, tmp_pages[--j]);
> -		kfree(tmp_pages);
> -		if (ret)
> -			break;
>   	}
> +	ret = 0;
>   	z_erofs_gbuf_nrpages = nrpages;
> -	erofs_release_pages(&pagepool);
>   out:
> +	if (ret && tmp_pages) {

	if (i < z_erofs_gbuf_count && tmp_pages) {

> +		for (j = 0; j < nrpages; ++j)
> +			if (tmp_pages[j] && tmp_pages[j] != gbuf->pages[j])
> +				__free_page(tmp_pages[j]);
> +		kfree(tmp_pages);
> +	}
>   	mutex_unlock(&gbuf_resize_mutex);
>   	return ret;

	return i < z_erofs_gbuf_count ? -ENOMEM: 0;

Otherwise it looks good to me.

Thanks,
Gao Xiang

>   }

      reply	other threads:[~2024-04-02  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02  8:40 [PATCH] erofs: do not use pagepool in z_erofs_gbuf_growsize() Chunhai Guo via Linux-erofs
2024-04-02  8:57 ` Gao Xiang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b904fbcd-653d-4548-b354-213f5c4563ea@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=guochunhai@vivo.com \
    --cc=huyue2@coolpad.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).