From: Julian Sun <sunjunchao2870@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Cc: hannes@cmpxchg.org, clm@meta.com, linux-kernel@vger.kernel.org,
willy@infradead.org, kirill@shutemov.name,
linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-xfs@vger.kernel.org, bfoster@redhat.com
Subject: Re: [PATCHSET v5 0/17] Uncached buffered IO
Date: Fri, 15 Nov 2024 12:01:23 +0800 [thread overview]
Message-ID: <8b47ebabf12a531f2fa24a7671df5e569b82adb7.camel@gmail.com> (raw)
In-Reply-To: <20241114152743.2381672-2-axboe@kernel.dk>
On Thu, 2024-11-14 at 08:25 -0700, Jens Axboe wrote:
> Hi,
>
> 5 years ago I posted patches adding support for RWF_UNCACHED, as a way
> to do buffered IO that isn't page cache persistent. The approach back
> then was to have private pages for IO, and then get rid of them once IO
> was done. But that then runs into all the issues that O_DIRECT has, in
> terms of synchronizing with the page cache.
>
> So here's a new approach to the same concent, but using the page cache
> as synchronization. That makes RWF_UNCACHED less special, in that it's
> just page cache IO, except it prunes the ranges once IO is completed.
>
> Why do this, you may ask? The tldr is that device speeds are only
> getting faster, while reclaim is not. Doing normal buffered IO can be
> very unpredictable, and suck up a lot of resources on the reclaim side.
> This leads people to use O_DIRECT as a work-around, which has its own
> set of restrictions in terms of size, offset, and length of IO. It's
> also inherently synchronous, and now you need async IO as well. While
> the latter isn't necessarily a big problem as we have good options
> available there, it also should not be a requirement when all you want
> to do is read or write some data without caching.
>
> Even on desktop type systems, a normal NVMe device can fill the entire
> page cache in seconds. On the big system I used for testing, there's a
> lot more RAM, but also a lot more devices. As can be seen in some of the
> results in the following patches, you can still fill RAM in seconds even
> when there's 1TB of it. Hence this problem isn't solely a "big
> hyperscaler system" issue, it's common across the board.
>
> Common for both reads and writes with RWF_UNCACHED is that they use the
> page cache for IO. Reads work just like a normal buffered read would,
> with the only exception being that the touched ranges will get pruned
> after data has been copied. For writes, the ranges will get writeback
> kicked off before the syscall returns, and then writeback completion
> will prune the range. Hence writes aren't synchronous, and it's easy to
> pipeline writes using RWF_UNCACHED. Folios that aren't instantiated by
> RWF_UNCACHED IO are left untouched. This means you that uncached IO
> will take advantage of the page cache for uptodate data, but not leave
> anything it instantiated/created in cache.
>
> File systems need to support this. The patches add support for the
> generic filemap helpers, and for iomap. Then ext4 and XFS are marked as
> supporting it. The last patch adds support for btrfs as well, lightly
> tested. The read side is already done by filemap, only the write side
> needs a bit of help. The amount of code here is really trivial, and the
> only reason the fs opt-in is necessary is to have an RWF_UNCACHED IO
> return -EOPNOTSUPP just in case the fs doesn't use either the generic
> paths or iomap. Adding "support" to other file systems should be
> trivial, most of the time just a one-liner adding FOP_UNCACHED to the
> fop_flags in the file_operations struct.
>
> Performance results are in patch 8 for reads and patch 10 for writes,
> with the tldr being that I see about a 65% improvement in performance
> for both, with fully predictable IO times. CPU reduction is substantial
> as well, with no kswapd activity at all for reclaim when using uncached
> IO.
>
> Using it from applications is trivial - just set RWF_UNCACHED for the
> read or write, using pwritev2(2) or preadv2(2). For io_uring, same
> thing, just set RWF_UNCACHED in sqe->rw_flags for a buffered read/write
> operation. And that's it.
>
> Patches 1..7 are just prep patches, and should have no functional
> changes at all. Patch 8 adds support for the filemap path for
> RWF_UNCACHED reads, patch 10 adds support for filemap RWF_UNCACHED
> writes, and patches 13..17 adds ext4, xfs/iomap, and btrfs support.
>
> Passes full xfstests and fsx overnight runs, no issues observed. That
> includes the vm running the testing also using RWF_UNCACHED on the host.
> I'll post fsstress and fsx patches for RWF_UNCACHED separately. As far
> as I'm concerned, no further work needs doing here. Once we're into
> the 6.13 merge window, I'll split up this series and aim to get it
> landed that way. There are really 4 parts to this - generic mm bits,
> ext4 bits, xfs bits, and btrfs bits.
>
> And git tree for the patches is here:
>
> https://git.kernel.dk/cgit/linux/log/?h=buffered-uncached.7
>
> fs/btrfs/bio.c | 4 +-
> fs/btrfs/bio.h | 2 +
> fs/btrfs/extent_io.c | 8 ++-
> fs/btrfs/file.c | 9 ++-
> fs/ext4/ext4.h | 1 +
> fs/ext4/file.c | 2 +-
> fs/ext4/inline.c | 7 +-
> fs/ext4/inode.c | 18 +++++-
> fs/ext4/page-io.c | 28 ++++----
> fs/iomap/buffered-io.c | 15 ++++-
> fs/xfs/xfs_aops.c | 7 +-
> fs/xfs/xfs_file.c | 3 +-
> include/linux/fs.h | 21 +++++-
> include/linux/iomap.h | 8 ++-
> include/linux/page-flags.h | 5 ++
> include/linux/pagemap.h | 14 ++++
> include/trace/events/mmflags.h | 3 +-
> include/uapi/linux/fs.h | 6 +-
> mm/filemap.c | 114 +++++++++++++++++++++++++++++----
> mm/readahead.c | 22 +++++--
> mm/swap.c | 2 +
> mm/truncate.c | 35 ++++++----
> 22 files changed, 271 insertions(+), 63 deletions(-)
>
> Since v3
> - Use foliop_is_uncached() in ext4 rather than do manual compares with
> foliop_uncached.
> - Add filemap_fdatawrite_range_kick() helper and use that in
> generic_write_sync() to kick off uncached writeback, rather than need
> every fs adding a call to generic_uncached_write().
> - Drop generic_uncached_write() helper, not needed anymore.
> - Skip folio_unmap_invalidate() if the folio is dirty.
> - Move IOMAP_F_UNCACHED to the internal iomap flags section, and add
> comment from Darrick to it as well.
> - Only kick uncached writeback in generic_write_sync() if
> iocb_is_dsync() isn't true.
> - Disable RWF_UNCACHED on dax mappings. They require more extensive
> invalidation, and as it isn't a likely use case, just disable it
> for now.
> - Update a few commit messages
>
Hi,
Hello, the simplicity and performance improvement of this patch series are
really impressive, and I have no comments on it.
I'm just curious about its use cases—under which scenarios should it be
used, and under which scenarios should it be avoided? I noticed that the
backing device you used for testing can provide at least 92GB/s read
performance and 115GB/s write performance. Does this mean that the higher
the performance of the backing device, the more noticeable the
optimization? How does this patch series perform on low-speed devices?
My understanding is that the performance issue this patch is trying to
address originates from the page cache being filled up, causing the current
IO to wait for write-back or reclamation, correct? From this perspective,
it seems that this would be suitable for applications that issue a large
amount of IO in a short period of time, and it might not be dependent on
the speed of the backing device?
Thanks,
--
Julian Sun <sunjunchao2870@gmail.com>
next prev parent reply other threads:[~2024-11-15 4:01 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 15:25 Jens Axboe
2024-11-14 15:25 ` [PATCH 01/17] mm/filemap: change filemap_create_folio() to take a struct kiocb Jens Axboe
2024-11-14 15:25 ` [PATCH 02/17] mm/readahead: add folio allocation helper Jens Axboe
2024-11-14 15:25 ` [PATCH 03/17] mm: add PG_uncached page flag Jens Axboe
2024-11-14 15:25 ` [PATCH 04/17] mm/readahead: add readahead_control->uncached member Jens Axboe
2024-11-14 15:25 ` [PATCH 05/17] mm/filemap: use page_cache_sync_ra() to kick off read-ahead Jens Axboe
2024-11-14 15:25 ` [PATCH 06/17] mm/truncate: add folio_unmap_invalidate() helper Jens Axboe
2024-11-14 15:25 ` [PATCH 07/17] fs: add RWF_UNCACHED iocb and FOP_UNCACHED file_operations flag Jens Axboe
2024-11-14 15:25 ` [PATCH 08/17] mm/filemap: add read support for RWF_UNCACHED Jens Axboe
2024-11-15 8:49 ` Kirill A. Shutemov
2024-11-15 15:01 ` Jens Axboe
2024-11-14 15:25 ` [PATCH 09/17] mm/filemap: drop uncached pages when writeback completes Jens Axboe
2024-11-14 15:25 ` [PATCH 10/17] mm/filemap: make buffered writes work with RWF_UNCACHED Jens Axboe
2024-11-18 8:42 ` Baokun Li
2024-11-18 14:49 ` Jens Axboe
2024-11-14 15:25 ` [PATCH 11/17] mm/filemap: add filemap_fdatawrite_range_kick() helper Jens Axboe
2024-11-14 15:25 ` [PATCH 12/17] mm: add FGP_UNCACHED folio creation flag Jens Axboe
2024-11-14 15:25 ` [PATCH 13/17] ext4: add RWF_UNCACHED write support Jens Axboe
2024-11-14 15:25 ` [PATCH 14/17] iomap: make buffered writes work with RWF_UNCACHED Jens Axboe
2024-12-12 5:50 ` Christoph Hellwig
2024-12-12 6:26 ` Darrick J. Wong
2024-12-12 6:31 ` Christoph Hellwig
2024-11-14 15:25 ` [PATCH 15/17] xfs: punt uncached write completions to the completion wq Jens Axboe
2024-11-14 15:25 ` [PATCH 16/17] xfs: flag as supporting FOP_UNCACHED Jens Axboe
2024-11-14 15:25 ` [PATCH 17/17] btrfs: add support for uncached writes Jens Axboe
2024-11-15 4:01 ` Julian Sun [this message]
2024-11-15 15:06 ` [PATCHSET v5 0/17] Uncached buffered IO Jens Axboe
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=8b47ebabf12a531f2fa24a7671df5e569b82adb7.camel@gmail.com \
--to=sunjunchao2870@gmail.com \
--cc=axboe@kernel.dk \
--cc=bfoster@redhat.com \
--cc=clm@meta.com \
--cc=hannes@cmpxchg.org \
--cc=kirill@shutemov.name \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--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