diff mbox series

[v5,1/2] filemap: add helper mapping_max_folio_size()

Message ID 20240521114939.2541461-1-xu.yang_2@nxp.com (mailing list archive)
State New
Headers show
Series [v5,1/2] filemap: add helper mapping_max_folio_size() | expand

Commit Message

Xu Yang May 21, 2024, 11:49 a.m. UTC
Add mapping_max_folio_size() to get the maximum folio size for this
pagecache mapping.

Fixes: 5d8edfb900d5 ("iomap: Copy larger chunks from userspace")
Cc: stable@vger.kernel.org
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

---
Changes in v4:
 - split the mapping_max_folio_size() from v3
 - adjust mapping_max_folio_size() comment
 - add Rb tag
Changes in v5:
 - add fix tag and stable list
---
 include/linux/pagemap.h | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

Comments

Christian Brauner May 21, 2024, 2:22 p.m. UTC | #1
On Tue, 21 May 2024 19:49:38 +0800, Xu Yang wrote:
> Add mapping_max_folio_size() to get the maximum folio size for this
> pagecache mapping.
> 
> 

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/2] filemap: add helper mapping_max_folio_size()
      https://git.kernel.org/vfs/vfs/c/0c31d63eebdd
[2/2] iomap: fault in smaller chunks for non-large folio mappings
      https://git.kernel.org/vfs/vfs/c/63ba6f07d115
Ritesh Harjani (IBM) May 24, 2024, 6:21 a.m. UTC | #2
Christian Brauner <brauner@kernel.org> writes:

> On Tue, 21 May 2024 19:49:38 +0800, Xu Yang wrote:
>> Add mapping_max_folio_size() to get the maximum folio size for this
>> pagecache mapping.
>> 
>> 
>
> Applied to the vfs.fixes branch of the vfs/vfs.git tree.
> Patches in the vfs.fixes branch should appear in linux-next soon.
>
> Please report any outstanding bugs that were missed during review in a
> new review to the original patch series allowing us to drop it.
>
> It's encouraged to provide Acked-bys and Reviewed-bys even though the
> patch has now been applied. If possible patch trailers will be updated.

iomap_write_iter() prefaults in userspace buffer chunk bytes (order
MAX_PAGECACHE_ORDER) at a time.
However, the iomap_write_begin() function only handles writes for
PAGE_SIZE bytes at a time for mappings which does not support large
folios. Hence, this causes unnecessary loops of prefaults in
iomap_write_iter() -> fault_in_iov_iter_readable(), causing performance
hits for block device mappings.

This patch fixes iomap_write_iter() to prefault in PAGE_SIZE chunk
bytes.

I guess this change will then go back to v6.6 when large folios got added to iomap.

Looks good to me. Please feel free add - 
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

>
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs.fixes
>
> [1/2] filemap: add helper mapping_max_folio_size()
>       https://git.kernel.org/vfs/vfs/c/0c31d63eebdd
> [2/2] iomap: fault in smaller chunks for non-large folio mappings
>       https://git.kernel.org/vfs/vfs/c/63ba6f07d115
Christoph Hellwig May 24, 2024, 8:03 a.m. UTC | #3
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Matthew Wilcox May 24, 2024, 12:17 p.m. UTC | #4
On Tue, May 21, 2024 at 07:49:38PM +0800, Xu Yang wrote:
> Add mapping_max_folio_size() to get the maximum folio size for this
> pagecache mapping.
> 
> Fixes: 5d8edfb900d5 ("iomap: Copy larger chunks from userspace")
> Cc: stable@vger.kernel.org
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
diff mbox series

Patch

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c5e33e2ca48a..d43cf36bb68b 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -346,6 +346,19 @@  static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
 	m->gfp_mask = mask;
 }
 
+/*
+ * There are some parts of the kernel which assume that PMD entries
+ * are exactly HPAGE_PMD_ORDER.  Those should be fixed, but until then,
+ * limit the maximum allocation order to PMD size.  I'm not aware of any
+ * assumptions about maximum order if THP are disabled, but 8 seems like
+ * a good order (that's 1MB if you're using 4kB pages)
+ */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#define MAX_PAGECACHE_ORDER	HPAGE_PMD_ORDER
+#else
+#define MAX_PAGECACHE_ORDER	8
+#endif
+
 /**
  * mapping_set_large_folios() - Indicate the file supports large folios.
  * @mapping: The file.
@@ -372,6 +385,14 @@  static inline bool mapping_large_folio_support(struct address_space *mapping)
 		test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags);
 }
 
+/* Return the maximum folio size for this pagecache mapping, in bytes. */
+static inline size_t mapping_max_folio_size(struct address_space *mapping)
+{
+	if (mapping_large_folio_support(mapping))
+		return PAGE_SIZE << MAX_PAGECACHE_ORDER;
+	return PAGE_SIZE;
+}
+
 static inline int filemap_nr_thps(struct address_space *mapping)
 {
 #ifdef CONFIG_READ_ONLY_THP_FOR_FS
@@ -530,19 +551,6 @@  static inline void *detach_page_private(struct page *page)
 	return folio_detach_private(page_folio(page));
 }
 
-/*
- * There are some parts of the kernel which assume that PMD entries
- * are exactly HPAGE_PMD_ORDER.  Those should be fixed, but until then,
- * limit the maximum allocation order to PMD size.  I'm not aware of any
- * assumptions about maximum order if THP are disabled, but 8 seems like
- * a good order (that's 1MB if you're using 4kB pages)
- */
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-#define MAX_PAGECACHE_ORDER	HPAGE_PMD_ORDER
-#else
-#define MAX_PAGECACHE_ORDER	8
-#endif
-
 #ifdef CONFIG_NUMA
 struct folio *filemap_alloc_folio(gfp_t gfp, unsigned int order);
 #else