From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
linux-xfs@vger.kernel.org, Wang Yugui <wangyugui@e16-tech.com>,
Dave Chinner <david@fromorbit.com>,
Christoph Hellwig <hch@infradead.org>,
"Darrick J . Wong" <djwong@kernel.org>
Subject: [PATCH 3/3] iomap: Copy larger chunks from userspace
Date: Sat, 20 May 2023 17:36:03 +0100 [thread overview]
Message-ID: <20230520163603.1794256-4-willy@infradead.org> (raw)
In-Reply-To: <20230520163603.1794256-1-willy@infradead.org>
If we have a large folio, we can copy in larger chunks than PAGE_SIZE.
Start at the maximum page cache size and shrink by half every time we
hit the "we are short on memory" problem.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/iomap/buffered-io.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 651af2d424ac..aa1268e708fb 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -775,6 +775,7 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len,
static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
{
loff_t length = iomap_length(iter);
+ size_t chunk = PAGE_SIZE << MAX_PAGECACHE_ORDER;
loff_t pos = iter->pos;
ssize_t written = 0;
long status = 0;
@@ -783,15 +784,13 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
do {
struct folio *folio;
- struct page *page;
- unsigned long offset; /* Offset into pagecache page */
- unsigned long bytes; /* Bytes to write to page */
+ size_t offset; /* Offset into folio */
+ unsigned long bytes; /* Bytes to write to folio */
size_t copied; /* Bytes copied from user */
- offset = offset_in_page(pos);
- bytes = min_t(unsigned long, PAGE_SIZE - offset,
- iov_iter_count(i));
again:
+ offset = pos & (chunk - 1);
+ bytes = min(chunk - offset, iov_iter_count(i));
status = balance_dirty_pages_ratelimited_flags(mapping,
bdp_flags);
if (unlikely(status))
@@ -821,11 +820,14 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
if (iter->iomap.flags & IOMAP_F_STALE)
break;
- page = folio_file_page(folio, pos >> PAGE_SHIFT);
+ offset = offset_in_folio(folio, pos);
+ if (bytes > folio_size(folio) - offset);
+ bytes = folio_size(folio) - offset;
+
if (mapping_writably_mapped(mapping))
- flush_dcache_page(page);
+ flush_dcache_folio(folio);
- copied = copy_page_from_iter_atomic(page, offset, bytes, i);
+ copied = copy_page_from_iter_atomic(&folio->page, offset, bytes, i);
status = iomap_write_end(iter, pos, bytes, copied, folio);
@@ -842,6 +844,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
*/
if (copied)
bytes = copied;
+ if (chunk > PAGE_SIZE)
+ chunk /= 2;
goto again;
}
pos += status;
--
2.39.2
next prev parent reply other threads:[~2023-05-20 16:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-20 16:36 [PATCH 0/3] Create large folios in iomap buffered write path Matthew Wilcox (Oracle)
2023-05-20 16:36 ` [PATCH 1/3] filemap: Allow __filemap_get_folio to allocate large folios Matthew Wilcox (Oracle)
2023-05-21 1:02 ` Wang Yugui
2023-05-21 1:56 ` Matthew Wilcox
2023-05-21 2:04 ` Wang Yugui
2023-05-21 3:39 ` Matthew Wilcox
2023-05-21 2:13 ` Dave Chinner
2023-05-21 3:38 ` Matthew Wilcox
2023-05-23 5:59 ` Christoph Hellwig
2023-05-23 12:17 ` Matthew Wilcox
2023-05-20 16:36 ` [PATCH 2/3] iomap: Create large folios in the buffered write path Matthew Wilcox (Oracle)
2023-05-20 16:36 ` Matthew Wilcox (Oracle) [this message]
2023-05-20 19:11 ` [PATCH 3/3] iomap: Copy larger chunks from userspace kernel test robot
2023-05-20 19:25 ` kernel test robot
2023-05-21 0:49 ` [PATCH 0/3] Create large folios in iomap buffered write path Wang Yugui
2023-05-21 0:59 ` Matthew Wilcox
2023-05-21 1:38 ` Wang Yugui
2023-05-21 2:49 ` Dave Chinner
2023-05-21 11:40 ` Wang Yugui
2023-05-31 4:34 ` Wang Yugui
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=20230520163603.1794256-4-willy@infradead.org \
--to=willy@infradead.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=wangyugui@e16-tech.com \
/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).