Linux NFS development
 help / color / mirror / Atom feed
From: trondmy@kernel.org
To: linux-nfs@vger.kernel.org
Subject: [PATCH 04/17] NFS: Fix nfs_coalesce_size() to work with folios
Date: Sat,  7 Jan 2023 12:36:22 -0500	[thread overview]
Message-ID: <20230107173635.2025233-5-trondmy@kernel.org> (raw)
In-Reply-To: <20230107173635.2025233-4-trondmy@kernel.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

Use the helper folio_size() where appropriate.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/pagelist.c        | 28 +++++++++++++++++++---------
 include/linux/nfs_page.h | 15 +++++++++++++++
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 33b8d636dd78..30722cbcf5f4 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -1084,6 +1084,24 @@ static bool nfs_match_lock_context(const struct nfs_lock_context *l1,
 	return l1->lockowner == l2->lockowner;
 }
 
+static bool nfs_page_is_contiguous(const struct nfs_page *prev,
+				   const struct nfs_page *req)
+{
+	size_t prev_end = prev->wb_pgbase + prev->wb_bytes;
+
+	if (req_offset(req) != req_offset(prev) + prev->wb_bytes)
+		return false;
+	if (req->wb_pgbase == 0)
+		return prev_end == nfs_page_max_length(prev);
+	if (req->wb_pgbase == prev_end) {
+		struct folio *folio = nfs_page_to_folio(req);
+		if (folio)
+			return folio == nfs_page_to_folio(prev);
+		return req->wb_page == prev->wb_page;
+	}
+	return false;
+}
+
 /**
  * nfs_coalesce_size - test two requests for compatibility
  * @prev: pointer to nfs_page
@@ -1112,16 +1130,8 @@ static unsigned int nfs_coalesce_size(struct nfs_page *prev,
 		    !nfs_match_lock_context(req->wb_lock_context,
 					    prev->wb_lock_context))
 			return 0;
-		if (req_offset(req) != req_offset(prev) + prev->wb_bytes)
+		if (!nfs_page_is_contiguous(prev, req))
 			return 0;
-		if (req->wb_page == prev->wb_page) {
-			if (req->wb_pgbase != prev->wb_pgbase + prev->wb_bytes)
-				return 0;
-		} else {
-			if (req->wb_pgbase != 0 ||
-			    prev->wb_pgbase + prev->wb_bytes != PAGE_SIZE)
-				return 0;
-		}
 	}
 	return pgio->pg_ops->pg_test(pgio, prev, req);
 }
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h
index d2ddc9a594c5..192071a6e5f6 100644
--- a/include/linux/nfs_page.h
+++ b/include/linux/nfs_page.h
@@ -189,6 +189,21 @@ static inline struct page *nfs_page_to_page(const struct nfs_page *req,
 	return folio_page(folio, pgbase >> PAGE_SHIFT);
 }
 
+/**
+ * nfs_page_max_length - Retrieve the maximum possible length for a request
+ * @req: pointer to a struct nfs_page
+ *
+ * Returns the maximum possible length of a request
+ */
+static inline size_t nfs_page_max_length(const struct nfs_page *req)
+{
+	struct folio *folio = nfs_page_to_folio(req);
+
+	if (folio == NULL)
+		return PAGE_SIZE;
+	return folio_size(folio);
+}
+
 /*
  * Lock the page of an asynchronous request
  */
-- 
2.39.0


  reply	other threads:[~2023-01-07 17:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 17:36 [PATCH 00/17] Initial conversion of NFS basic I/O to use folios trondmy
2023-01-07 17:36 ` [PATCH 01/17] NFS: Fix for xfstests generic/208 trondmy
2023-01-07 17:36   ` [PATCH 02/17] NFS: Add basic functionality for tracking folios in struct nfs_page trondmy
2023-01-07 17:36     ` [PATCH 03/17] NFS: Support folios in nfs_generic_pgio() trondmy
2023-01-07 17:36       ` trondmy [this message]
2023-01-07 17:36         ` [PATCH 05/17] NFS: Add a helper to convert a struct nfs_page into an inode trondmy
2023-01-07 17:36           ` [PATCH 06/17] NFS: Convert the remaining pagelist helper functions to support folios trondmy
2023-01-07 17:36             ` [PATCH 07/17] NFS: Add a helper nfs_wb_folio() trondmy
2023-01-07 17:36               ` [PATCH 08/17] NFS: Convert buffered reads to use folios trondmy
2023-01-07 17:36                 ` [PATCH 09/17] NFS: Convert the function nfs_wb_page() " trondmy
2023-01-07 17:36                   ` [PATCH 10/17] NFS: Convert buffered writes " trondmy
2023-01-07 17:36                     ` [PATCH 11/17] NFS: Remove unused function nfs_wb_page() trondmy
2023-01-07 17:36                       ` [PATCH 12/17] NFS: Convert nfs_write_begin/end to use folios trondmy
2023-01-07 17:36                         ` [PATCH 13/17] NFS: Fix up nfs_vm_page_mkwrite() for folios trondmy
2023-01-07 17:36                           ` [PATCH 14/17] NFS: Clean up O_DIRECT request allocation trondmy
2023-01-07 17:36                             ` [PATCH 15/17] NFS: fix up nfs_release_folio() to try to release the page trondmy
2023-01-07 17:36                               ` [PATCH 16/17] NFS: Enable tracing of nfs_invalidate_folio() and nfs_launder_folio() trondmy
2023-01-07 17:36                                 ` [PATCH 17/17] NFS: Improve tracing of nfs_wb_folio() trondmy
2023-01-11 16:18                   ` [PATCH 09/17] NFS: Convert the function nfs_wb_page() to use folios Anna Schumaker

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=20230107173635.2025233-5-trondmy@kernel.org \
    --to=trondmy@kernel.org \
    --cc=linux-nfs@vger.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