mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	<linux-um@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	"Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com>
Subject: Re: [PATCH] fs/hostfs: Replace kmap() with kmap_local_page()
Date: Fri, 30 Dec 2022 15:50:16 -0800	[thread overview]
Message-ID: <Y695OHrq+UmvVeez@iweiny-desk3> (raw)
In-Reply-To: <20221013161700.11631-1-fmdefrancesco@gmail.com>

On Thu, Oct 13, 2022 at 06:17:00PM +0200, Fabio M. De Francesco wrote:
> The use of kmap() is being deprecated in favor of kmap_local_page().
> 
> There are two main problems with kmap(): (1) It comes with an overhead as
> the mapping space is restricted and protected by a global lock for
> synchronization and (2) it also requires global TLB invalidation when the
> kmap’s pool wraps and it might block when the mapping space is fully
> utilized until a slot becomes available.
> 
> With kmap_local_page() the mappings are per thread, CPU local, can take
> page faults, and can be called from any context (including interrupts).
> It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore,
> the tasks can be preempted and, when they are scheduled to run again, the
> kernel virtual addresses are restored and still valid.
> 
> Therefore, replace kmap() with kmap_local_page() in hostfs_kern.c, it
> being the only file with kmap() call sites currently left in fs/hostfs.
> 
> Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com>
> Suggested-by: Ira Weiny <ira.weiny@intel.com>

What can we do to move this patch along?

I'm not an expert but it looks ok to me.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
> 
> These changes are not tested in a 32 bits VM as I use to do with other more
> problematic conversions. Mere code inspection makes me reasonably think
> that the rules of local mappings are not violated by this conversion.
> 
> Furthermore, I have no idea how to test this code. If maintainers think
> that tests are absolutely necessary, any hints about how to perform them
> would be greatly appreciated.
> 
>  fs/hostfs/hostfs_kern.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
> index 07881b76d42f..0c9f89352601 100644
> --- a/fs/hostfs/hostfs_kern.c
> +++ b/fs/hostfs/hostfs_kern.c
> @@ -412,7 +412,7 @@ static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
>  	if (page->index >= end_index)
>  		count = inode->i_size & (PAGE_SIZE-1);
>  
> -	buffer = kmap(page);
> +	buffer = kmap_local_page(page);
>  
>  	err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
>  	if (err != count) {
> @@ -428,9 +428,9 @@ static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
>  	err = 0;
>  
>   out:
> -	kunmap(page);
> -
> +	kunmap_local(buffer);
>  	unlock_page(page);
> +
>  	return err;
>  }
>  
> @@ -441,7 +441,7 @@ static int hostfs_read_folio(struct file *file, struct folio *folio)
>  	loff_t start = page_offset(page);
>  	int bytes_read, ret = 0;
>  
> -	buffer = kmap(page);
> +	buffer = kmap_local_page(page);
>  	bytes_read = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
>  			PAGE_SIZE);
>  	if (bytes_read < 0) {
> @@ -458,8 +458,9 @@ static int hostfs_read_folio(struct file *file, struct folio *folio)
>  
>   out:
>  	flush_dcache_page(page);
> -	kunmap(page);
> +	kunmap_local(buffer);
>  	unlock_page(page);
> +
>  	return ret;
>  }
>  
> @@ -484,9 +485,9 @@ static int hostfs_write_end(struct file *file, struct address_space *mapping,
>  	unsigned from = pos & (PAGE_SIZE - 1);
>  	int err;
>  
> -	buffer = kmap(page);
> +	buffer = kmap_local_page(page);
>  	err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied);
> -	kunmap(page);
> +	kunmap_local(buffer);
>  
>  	if (!PageUptodate(page) && err == PAGE_SIZE)
>  		SetPageUptodate(page);
> -- 
> 2.37.3
> 

      reply	other threads:[~2022-12-30 23:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13 16:17 Fabio M. De Francesco
2022-12-30 23:50 ` Ira Weiny [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=Y695OHrq+UmvVeez@iweiny-desk3 \
    --to=ira.weiny@intel.com \
    --cc=anirudh.venkataramanan@intel.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    /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

all inboxes | Powered by JetHome®