linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Richard Weinberger <richard@nod.at>
Cc: <linux-mtd@lists.infradead.org>, <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 2/4] ubifs: Convert ubifs_writepage to use a folio
Date: Wed, 7 Jun 2023 22:48:12 +0800	[thread overview]
Message-ID: <d5286cf4-6d86-db9e-13e9-0d0bb1229493@huawei.com> (raw)
In-Reply-To: <20230605165029.2908304-3-willy@infradead.org>

在 2023/6/6 0:50, Matthew Wilcox (Oracle) 写道:
> We still pass the page down to do_writepage(), but ubifs_writepage()
> itself is now large folio safe.  It also contains far fewer hidden calls
> to compound_head().
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   fs/ubifs/file.c | 39 +++++++++++++++++----------------------
>   1 file changed, 17 insertions(+), 22 deletions(-)
> 
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 8bb4cb9d528f..1c7a99c36906 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -1006,21 +1006,18 @@ static int do_writepage(struct page *page, int len)
>   static int ubifs_writepage(struct folio *folio, struct writeback_control *wbc,
>   		void *data)
>   {
> -	struct page *page = &folio->page;
> -	struct inode *inode = page->mapping->host;
> +	struct inode *inode = folio->mapping->host;
>   	struct ubifs_info *c = inode->i_sb->s_fs_info;
>   	struct ubifs_inode *ui = ubifs_inode(inode);
>   	loff_t i_size =  i_size_read(inode), synced_i_size;
> -	pgoff_t end_index = i_size >> PAGE_SHIFT;
> -	int err, len = i_size & (PAGE_SIZE - 1);
> -	void *kaddr;
> +	int err, len = folio_size(folio);
>   
>   	dbg_gen("ino %lu, pg %lu, pg flags %#lx",
> -		inode->i_ino, page->index, page->flags);
> -	ubifs_assert(c, PagePrivate(page));
> +		inode->i_ino, folio->index, folio->flags);
> +	ubifs_assert(c, folio->private != NULL);
>   
> -	/* Is the page fully outside @i_size? (truncate in progress) */
> -	if (page->index > end_index || (page->index == end_index && !len)) {
> +	/* Is the folio fully outside @i_size? (truncate in progress) */
> +	if (folio_pos(folio) >= i_size) {
>   		err = 0;
>   		goto out_unlock;
>   	}
> @@ -1029,9 +1026,9 @@ static int ubifs_writepage(struct folio *folio, struct writeback_control *wbc,
>   	synced_i_size = ui->synced_i_size;
>   	spin_unlock(&ui->ui_lock);
>   
> -	/* Is the page fully inside @i_size? */
> -	if (page->index < end_index) {
> -		if (page->index >= synced_i_size >> PAGE_SHIFT) {
> +	/* Is the folio fully inside i_size? */
> +	if (folio_pos(folio) + len < i_size) {

if (folio_pos(folio) + len <= i_size) ?

> +		if (folio_pos(folio) >= synced_i_size) {
>   			err = inode->i_sb->s_op->write_inode(inode, NULL);
>   			if (err)
>   				goto out_redirty;
> @@ -1044,20 +1041,18 @@ static int ubifs_writepage(struct folio *folio, struct writeback_control *wbc,
>   			 * with this.
>   			 */
>   		}
> -		return do_writepage(page, PAGE_SIZE);
> +		return do_writepage(&folio->page, len);
>   	}
>   
>   	/*
> -	 * The page straddles @i_size. It must be zeroed out on each and every
> +	 * The folio straddles @i_size. It must be zeroed out on each and every
>   	 * writepage invocation because it may be mmapped. "A file is mapped
>   	 * in multiples of the page size. For a file that is not a multiple of
>   	 * the page size, the remaining memory is zeroed when mapped, and
>   	 * writes to that region are not written out to the file."
>   	 */
> -	kaddr = kmap_atomic(page);
> -	memset(kaddr + len, 0, PAGE_SIZE - len);
> -	flush_dcache_page(page);
> -	kunmap_atomic(kaddr);
> +	folio_zero_segment(folio, offset_in_folio(folio, i_size), len);
> +	len = offset_in_folio(folio, i_size);
>   
>   	if (i_size > synced_i_size) {
>   		err = inode->i_sb->s_op->write_inode(inode, NULL);
> @@ -1065,16 +1060,16 @@ static int ubifs_writepage(struct folio *folio, struct writeback_control *wbc,
>   			goto out_redirty;
>   	}
>   
> -	return do_writepage(page, len);
> +	return do_writepage(&folio->page, len);
>   out_redirty:
>   	/*
> -	 * redirty_page_for_writepage() won't call ubifs_dirty_inode() because
> +	 * folio_redirty_for_writepage() won't call ubifs_dirty_inode() because
>   	 * it passes I_DIRTY_PAGES flag while calling __mark_inode_dirty(), so
>   	 * there is no need to do space budget for dirty inode.
>   	 */
> -	redirty_page_for_writepage(wbc, page);
> +	folio_redirty_for_writepage(wbc, folio);
>   out_unlock:
> -	unlock_page(page);
> +	folio_unlock(folio);
>   	return err;
>   }
>   
> 


  reply	other threads:[~2023-06-07 14:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 16:50 [PATCH 0/4] ubifs: Convert writeback to use folios Matthew Wilcox (Oracle)
2023-06-05 16:50 ` [PATCH 1/4] ubifs: Convert from writepage to writepages Matthew Wilcox (Oracle)
2023-06-06 14:37   ` Zhihao Cheng
2023-06-07 14:11     ` Zhihao Cheng
2023-06-05 16:50 ` [PATCH 2/4] ubifs: Convert ubifs_writepage to use a folio Matthew Wilcox (Oracle)
2023-06-07 14:48   ` Zhihao Cheng [this message]
2023-06-05 16:50 ` [PATCH 3/4] ubifs: Use a folio in do_truncation() Matthew Wilcox (Oracle)
2023-06-05 17:05   ` Matthew Wilcox
2023-06-08 14:31     ` Zhihao Cheng
2023-06-05 16:50 ` [PATCH 4/4] ubifs: Convert do_writepage() to take a folio Matthew Wilcox (Oracle)
2023-06-05 19:28   ` kernel test robot
2023-06-05 21:37   ` Richard Weinberger
2023-06-06  3:22     ` Matthew Wilcox
2023-06-06  6:13       ` Richard Weinberger
2023-06-06 12:32         ` Matthew Wilcox
2023-06-06 13:41           ` Richard Weinberger
2023-06-05 23:29   ` kernel test robot
2023-06-08 15:09   ` Zhihao Cheng

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=d5286cf4-6d86-db9e-13e9-0d0bb1229493@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=willy@infradead.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 NNTP newsgroup(s).