public inbox for linux-mtd@lists.infradead.org
 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>
Subject: Re: [PATCH 08/15] ubifs: Convert ubifs_write_begin() to use a folio
Date: Tue, 23 Jan 2024 12:27:57 +0800	[thread overview]
Message-ID: <bfff690c-e250-583a-eb74-7d117e0a0357@huawei.com> (raw)
In-Reply-To: <20240120230824.2619716-9-willy@infradead.org>

在 2024/1/21 7:08, Matthew Wilcox (Oracle) 写道:
> Save eight calls to compound_head() by using the new folio API.
> Remove a few assumptions that would break with large folios.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   fs/ubifs/file.c | 36 +++++++++++++++++-------------------
>   1 file changed, 17 insertions(+), 19 deletions(-)
> 

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 6302ce65e0b3..ef262499f228 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -428,7 +428,7 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   	pgoff_t index = pos >> PAGE_SHIFT;
>   	int err, appending = !!(pos + len > inode->i_size);
>   	int skipped_read = 0;
> -	struct page *page;
> +	struct folio *folio;
>   
>   	ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size);
>   	ubifs_assert(c, !c->ro_media && !c->ro_mount);
> @@ -437,13 +437,14 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   		return -EROFS;
>   
>   	/* Try out the fast-path part first */
> -	page = grab_cache_page_write_begin(mapping, index);
> -	if (unlikely(!page))
> -		return -ENOMEM;
> +	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
> +			mapping_gfp_mask(mapping));
> +	if (IS_ERR(folio))
> +		return PTR_ERR(folio);
>   
> -	if (!PageUptodate(page)) {
> +	if (!folio_test_uptodate(folio)) {
>   		/* The page is not loaded from the flash */
> -		if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE) {
> +		if (pos == folio_pos(folio) && len >= folio_size(folio)) {
>   			/*
>   			 * We change whole page so no need to load it. But we
>   			 * do not know whether this page exists on the media or
> @@ -453,29 +454,27 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   			 * media. Thus, we are setting the @PG_checked flag
>   			 * here.
>   			 */
> -			SetPageChecked(page);
> +			folio_set_checked(folio);
>   			skipped_read = 1;
>   		} else {
> -			err = do_readpage(page);
> +			err = do_readpage(&folio->page);
>   			if (err) {
> -				unlock_page(page);
> -				put_page(page);
> +				folio_unlock(folio);
> +				folio_put(folio);
>   				return err;
>   			}
>   		}
>   	}
>   
> -	err = allocate_budget(c, page, ui, appending);
> +	err = allocate_budget(c, &folio->page, ui, appending);
>   	if (unlikely(err)) {
>   		ubifs_assert(c, err == -ENOSPC);
>   		/*
>   		 * If we skipped reading the page because we were going to
>   		 * write all of it, then it is not up to date.
>   		 */
> -		if (skipped_read) {
> -			ClearPageChecked(page);
> -			ClearPageUptodate(page);
> -		}
> +		if (skipped_read)
> +			folio_clear_checked(folio);
>   		/*
>   		 * Budgeting failed which means it would have to force
>   		 * write-back but didn't, because we set the @fast flag in the
> @@ -487,8 +486,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   			ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
>   			mutex_unlock(&ui->ui_mutex);
>   		}
> -		unlock_page(page);
> -		put_page(page);
> +		folio_unlock(folio);
> +		folio_put(folio);
>   
>   		return write_begin_slow(mapping, pos, len, pagep);
>   	}
> @@ -499,9 +498,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
>   	 * with @ui->ui_mutex locked if we are appending pages, and unlocked
>   	 * otherwise. This is an optimization (slightly hacky though).
>   	 */
> -	*pagep = page;
> +	*pagep = &folio->page;
>   	return 0;
> -
>   }
>   
>   /**
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2024-01-23  4:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-20 23:08 [PATCH 00/15] ubifs folio conversion Matthew Wilcox (Oracle)
2024-01-20 23:08 ` [PATCH 01/15] ubifs: Set page uptodate in the correct place Matthew Wilcox (Oracle)
2024-01-22  7:22   ` Zhihao Cheng
2024-01-22 14:40     ` Matthew Wilcox
2024-01-23  2:36       ` Zhihao Cheng
2024-01-24  5:01         ` Matthew Wilcox
2024-01-20 23:08 ` [PATCH 02/15] ubifs: Convert from writepage to writepages Matthew Wilcox (Oracle)
2024-01-22 11:31   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 03/15] ubifs: Convert ubifs_writepage to use a folio Matthew Wilcox (Oracle)
2024-01-22  9:27   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 04/15] ubifs: Use a folio in do_truncation() Matthew Wilcox (Oracle)
2024-01-22  9:31   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 05/15] ubifs: Convert do_writepage() to take a folio Matthew Wilcox (Oracle)
2024-01-22 11:31   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 06/15] ubifs: Convert ubifs_vm_page_mkwrite() to use " Matthew Wilcox (Oracle)
2024-01-22 11:38   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 07/15] ubifs: Convert write_begin_slow() " Matthew Wilcox (Oracle)
2024-01-20 23:08 ` [PATCH 08/15] ubifs: Convert ubifs_write_begin() " Matthew Wilcox (Oracle)
2024-01-22 11:51   ` Zhihao Cheng
2024-01-22 14:43     ` Matthew Wilcox
2024-01-23  2:15       ` Zhihao Cheng
2024-01-23  3:07         ` Matthew Wilcox
2024-01-23  4:27           ` Zhihao Cheng
2024-01-23  4:27   ` Zhihao Cheng [this message]
2024-01-20 23:08 ` [PATCH 09/15] ubifs: Convert ubifs_write_end() " Matthew Wilcox (Oracle)
2024-01-23  4:39   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 10/15] ubifs: Convert do_readpage() to take " Matthew Wilcox (Oracle)
2024-01-22 12:09   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 11/15] ubifs: Convert allocate_budget() to work on " Matthew Wilcox (Oracle)
2024-01-22 11:52   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 12/15] ubifs: Convert cancel_budget() to take " Matthew Wilcox (Oracle)
2024-01-22 12:14   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 13/15] ubifs: Pass a folio into ubifs_bulk_read() and ubifs_do_bulk_read() Matthew Wilcox (Oracle)
2024-01-22 12:15   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 14/15] ubifs: Use a folio in ubifs_do_bulk_read() Matthew Wilcox (Oracle)
2024-01-22 12:17   ` Zhihao Cheng
2024-01-20 23:08 ` [PATCH 15/15] ubifs: Convert populate_page() to take a folio Matthew Wilcox (Oracle)
2024-01-22 12:22   ` Zhihao Cheng
2024-01-23  7:33 ` [PATCH 00/15] ubifs folio conversion Richard Weinberger
2024-01-24  5:01   ` Matthew Wilcox
2024-01-25  2:05     ` Zhihao Cheng
2024-02-15 20:46 ` Matthew Wilcox
2024-02-15 20:54   ` Richard Weinberger
2024-02-25 22:13     ` Richard Weinberger

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=bfff690c-e250-583a-eb74-7d117e0a0357@huawei.com \
    --to=chengzhihao1@huawei.com \
    --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