From: "Darrick J. Wong" <djwong@kernel.org>
To: John Garry <john.g.garry@oracle.com>
Cc: brauner@kernel.org, cem@kernel.org, linux-xfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
ojaswin@linux.ibm.com, ritesh.list@gmail.com,
martin.petersen@oracle.com, tytso@mit.edu,
linux-ext4@vger.kernel.org
Subject: Re: [PATCH v3 05/12] iomap: Support SW-based atomic writes
Date: Thu, 27 Feb 2025 17:08:20 -0800 [thread overview]
Message-ID: <20250228010820.GB1124788@frogsfrogsfrogs> (raw)
In-Reply-To: <20250227180813.1553404-6-john.g.garry@oracle.com>
On Thu, Feb 27, 2025 at 06:08:06PM +0000, John Garry wrote:
> Currently atomic write support requires dedicated HW support. This imposes
> a restriction on the filesystem that disk blocks need to be aligned and
> contiguously mapped to FS blocks to issue atomic writes.
>
> XFS has no method to guarantee FS block alignment for regular,
> non-RT files. As such, atomic writes are currently limited to 1x FS block
> there.
>
> To deal with the scenario that we are issuing an atomic write over
> misaligned or discontiguous data blocks - and raise the atomic write size
> limit - support a SW-based software emulated atomic write mode. For XFS,
> this SW-based atomic writes would use CoW support to issue emulated untorn
> writes.
>
> It is the responsibility of the FS to detect discontiguous atomic writes
> and switch to IOMAP_DIO_ATOMIC_SW mode and retry the write. Indeed,
> SW-based atomic writes could be used always when the mounted bdev does
> not support HW offload, but this strategy is not initially expected to be
> used.
>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
Looks good now, thank you.
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> Documentation/filesystems/iomap/operations.rst | 16 ++++++++++++++--
> fs/iomap/direct-io.c | 4 +++-
> include/linux/iomap.h | 6 ++++++
> 3 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst
> index 82bfe0e8c08e..b9757fe46641 100644
> --- a/Documentation/filesystems/iomap/operations.rst
> +++ b/Documentation/filesystems/iomap/operations.rst
> @@ -525,8 +525,20 @@ IOMAP_WRITE`` with any combination of the following enhancements:
> conversion or copy on write), all updates for the entire file range
> must be committed atomically as well.
> Only one space mapping is allowed per untorn write.
> - Untorn writes must be aligned to, and must not be longer than, a
> - single file block.
> + Untorn writes may be longer than a single file block. In all cases,
> + the mapping start disk block must have at least the same alignment as
> + the write offset.
> +
> + * ``IOMAP_ATOMIC_SW``: This write is being issued with torn-write
> + protection via a software mechanism provided by the filesystem.
> + All the disk block alignment and single bio restrictions which apply
> + to IOMAP_ATOMIC_HW do not apply here.
> + SW-based untorn writes would typically be used as a fallback when
> + HW-based untorn writes may not be issued, e.g. the range of the write
> + covers multiple extents, meaning that it is not possible to issue
> + a single bio.
> + All filesystem metadata updates for the entire file range must be
> + committed atomically as well.
>
> Callers commonly hold ``i_rwsem`` in shared or exclusive mode before
> calling this function.
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index f87c4277e738..575bb69db00e 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -644,7 +644,9 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> iomi.flags |= IOMAP_OVERWRITE_ONLY;
> }
>
> - if (iocb->ki_flags & IOCB_ATOMIC)
> + if (dio_flags & IOMAP_DIO_ATOMIC_SW)
> + iomi.flags |= IOMAP_ATOMIC_SW;
> + else if (iocb->ki_flags & IOCB_ATOMIC)
> iomi.flags |= IOMAP_ATOMIC_HW;
>
> /* for data sync or sync, we need sync completion processing */
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index e7aa05503763..4fa716241c46 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -183,6 +183,7 @@ struct iomap_folio_ops {
> #define IOMAP_DAX 0
> #endif /* CONFIG_FS_DAX */
> #define IOMAP_ATOMIC_HW (1 << 9) /* HW-based torn-write protection */
> +#define IOMAP_ATOMIC_SW (1 << 10)/* SW-based torn-write protection */
>
> struct iomap_ops {
> /*
> @@ -434,6 +435,11 @@ struct iomap_dio_ops {
> */
> #define IOMAP_DIO_PARTIAL (1 << 2)
>
> +/*
> + * Use software-based torn-write protection.
> + */
> +#define IOMAP_DIO_ATOMIC_SW (1 << 3)
> +
> ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
> unsigned int dio_flags, void *private, size_t done_before);
> --
> 2.31.1
>
next prev parent reply other threads:[~2025-02-28 1:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 18:08 [PATCH v3 00/12] large atomic writes for xfs with CoW John Garry
2025-02-27 18:08 ` [PATCH v3 01/12] xfs: Pass flags to xfs_reflink_allocate_cow() John Garry
2025-02-28 1:19 ` Darrick J. Wong
2025-02-27 18:08 ` [PATCH v3 02/12] iomap: Rename IOMAP_ATOMIC -> IOMAP_ATOMIC_HW John Garry
2025-02-27 18:08 ` [PATCH v3 03/12] xfs: Switch atomic write size check in xfs_file_write_iter() John Garry
2025-02-27 18:08 ` [PATCH v3 04/12] xfs: Refactor xfs_reflink_end_cow_extent() John Garry
2025-02-27 18:08 ` [PATCH v3 05/12] iomap: Support SW-based atomic writes John Garry
2025-02-28 1:08 ` Darrick J. Wong [this message]
2025-02-27 18:08 ` [PATCH v3 06/12] iomap: Lift blocksize restriction on " John Garry
2025-02-27 18:08 ` [PATCH v3 07/12] xfs: Reflink CoW-based atomic write support John Garry
2025-02-27 18:08 ` [PATCH v3 08/12] xfs: Iomap SW-based " John Garry
2025-02-28 1:19 ` Darrick J. Wong
2025-03-01 19:44 ` kernel test robot
2025-02-27 18:08 ` [PATCH v3 09/12] xfs: Add xfs_file_dio_write_atomic() John Garry
2025-02-28 1:19 ` Darrick J. Wong
2025-02-28 7:45 ` John Garry
2025-02-28 15:39 ` Darrick J. Wong
2025-03-03 13:45 ` John Garry
2025-02-27 18:08 ` [PATCH v3 10/12] xfs: Commit CoW-based atomic writes atomically John Garry
2025-02-28 1:13 ` Darrick J. Wong
2025-02-27 18:08 ` [PATCH v3 11/12] xfs: Update atomic write max size John Garry
2025-02-27 18:08 ` [PATCH v3 12/12] xfs: Allow block allocator to take an alignment hint John Garry
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=20250228010820.GB1124788@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
/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