All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Richard Weinberger <richard@nod.at>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-mtd@lists.infradead.org
Subject: [PATCH v2 07/15] ubifs: Convert write_begin_slow() to use a folio
Date: Wed, 24 Jan 2024 17:52:50 +0000	[thread overview]
Message-ID: <20240124175302.1750912-8-willy@infradead.org> (raw)
In-Reply-To: <20240124175302.1750912-1-willy@infradead.org>

Update to new APIs, removing several calls to compound_head() and
including support for large folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ubifs/file.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 3c4a98476c23..cc4d2ec95b70 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -222,16 +222,16 @@ static int write_begin_slow(struct address_space *mapping,
 	pgoff_t index = pos >> PAGE_SHIFT;
 	struct ubifs_budget_req req = { .new_page = 1 };
 	int err, appending = !!(pos + len > inode->i_size);
-	struct page *page;
+	struct folio *folio;
 
 	dbg_gen("ino %lu, pos %llu, len %u, i_size %lld",
 		inode->i_ino, pos, len, inode->i_size);
 
 	/*
-	 * At the slow path we have to budget before locking the page, because
-	 * budgeting may force write-back, which would wait on locked pages and
-	 * deadlock if we had the page locked. At this point we do not know
-	 * anything about the page, so assume that this is a new page which is
+	 * At the slow path we have to budget before locking the folio, because
+	 * budgeting may force write-back, which would wait on locked folios and
+	 * deadlock if we had the folio locked. At this point we do not know
+	 * anything about the folio, so assume that this is a new folio which is
 	 * written to a hole. This corresponds to largest budget. Later the
 	 * budget will be amended if this is not true.
 	 */
@@ -243,42 +243,43 @@ static int write_begin_slow(struct address_space *mapping,
 	if (unlikely(err))
 		return err;
 
-	page = grab_cache_page_write_begin(mapping, index);
-	if (unlikely(!page)) {
+	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
+			mapping_gfp_mask(mapping));
+	if (IS_ERR(folio)) {
 		ubifs_release_budget(c, &req);
-		return -ENOMEM;
+		return PTR_ERR(folio);
 	}
 
-	if (!PageUptodate(page)) {
-		if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE)
-			SetPageChecked(page);
+	if (!folio_test_uptodate(folio)) {
+		if (pos == folio_pos(folio) && len >= folio_size(folio))
+			folio_set_checked(folio);
 		else {
-			err = do_readpage(page);
+			err = do_readpage(&folio->page);
 			if (err) {
-				unlock_page(page);
-				put_page(page);
+				folio_unlock(folio);
+				folio_put(folio);
 				ubifs_release_budget(c, &req);
 				return err;
 			}
 		}
 	}
 
-	if (PagePrivate(page))
+	if (folio->private)
 		/*
-		 * The page is dirty, which means it was budgeted twice:
+		 * The folio is dirty, which means it was budgeted twice:
 		 *   o first time the budget was allocated by the task which
-		 *     made the page dirty and set the PG_private flag;
+		 *     made the folio dirty and set the private field;
 		 *   o and then we budgeted for it for the second time at the
 		 *     very beginning of this function.
 		 *
-		 * So what we have to do is to release the page budget we
+		 * So what we have to do is to release the folio budget we
 		 * allocated.
 		 */
 		release_new_page_budget(c);
-	else if (!PageChecked(page))
+	else if (!folio_test_checked(folio))
 		/*
-		 * We are changing a page which already exists on the media.
-		 * This means that changing the page does not make the amount
+		 * We are changing a folio which already exists on the media.
+		 * This means that changing the folio does not make the amount
 		 * of indexing information larger, and this part of the budget
 		 * which we have already acquired may be released.
 		 */
@@ -301,7 +302,7 @@ static int write_begin_slow(struct address_space *mapping,
 			ubifs_release_dirty_inode_budget(c, ui);
 	}
 
-	*pagep = page;
+	*pagep = &folio->page;
 	return 0;
 }
 
-- 
2.43.0


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

  parent reply	other threads:[~2024-01-24 17:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 17:52 [PATCH v2 00/15] ubifs folio conversion Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 01/15] ubifs: Set page uptodate in the correct place Matthew Wilcox (Oracle)
2024-01-24 17:52   ` Matthew Wilcox (Oracle)
2024-01-25  1:40   ` Zhihao Cheng
2024-01-25  1:40     ` Zhihao Cheng
2024-01-24 17:52 ` [PATCH v2 02/15] ubifs: Convert from writepage to writepages Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 03/15] ubifs: Convert ubifs_writepage to use a folio Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 04/15] ubifs: Use a folio in do_truncation() Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 05/15] ubifs: Convert do_writepage() to take a folio Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 06/15] ubifs: Convert ubifs_vm_page_mkwrite() to use " Matthew Wilcox (Oracle)
2024-01-24 17:52 ` Matthew Wilcox (Oracle) [this message]
2024-01-25  1:46   ` [PATCH v2 07/15] ubifs: Convert write_begin_slow() " Zhihao Cheng
2024-01-24 17:52 ` [PATCH v2 08/15] ubifs: Convert ubifs_write_begin() " Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 09/15] ubifs: Convert ubifs_write_end() " Matthew Wilcox (Oracle)
2024-01-25  1:50   ` Zhihao Cheng
2024-01-24 17:52 ` [PATCH v2 10/15] ubifs: Convert do_readpage() to take " Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 11/15] ubifs: Convert allocate_budget() to work on " Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 12/15] ubifs: Convert cancel_budget() to take " Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 13/15] ubifs: Pass a folio into ubifs_bulk_read() and ubifs_do_bulk_read() Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 14/15] ubifs: Use a folio in ubifs_do_bulk_read() Matthew Wilcox (Oracle)
2024-01-24 17:52 ` [PATCH v2 15/15] ubifs: Convert populate_page() to take a folio Matthew Wilcox (Oracle)

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=20240124175302.1750912-8-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=linux-mtd@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.