Skip to content

RFC ext4: Allocator changes for atomic write support with DIO

Ojaswin Mujoo linux-block linux-ext4 linux-fsdevel linux-xfs lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest7 patches 24 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7iomap: Don't fall back to buffered write if the write is atomicfs/iomap/direct-io.c+7 -19 replies
2/7ext4: Factor out size and start prediction from ext4_mb_normalize_request()fs/ext4/mballoc.c+56 -390 replies
3/7ext4: add aligned allocation support in mballocfs/ext4/ext4.h fs/ext4/mballoc.c include/trace/events/ext4.h+69 -70 replies
4/7ext4: allow inode preallocation for aligned allocfs/ext4/mballoc.c+107 -610 replies
5/7block: export blkdev_atomic_write_valid() and refactor apiblock/fops.c include/linux/blkdev.h+12 -82 replies
6/7ext4: Add aligned allocation support for atomic direct iofs/ext4/ext4.h fs/ext4/extents.c fs/ext4/file.c +2 more+170 -20 replies
7/7ext4: Support atomic write for statxfs/ext4/inode.c+36 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC 0/7] ext4: Allocator changes for atomic write support with DIO

This patch series builds on top of John Gary's atomic direct write patch series [1] and enables this support in ext4. This is a 2 step process:

1. Enable aligned allocation in ext4 mballoc. This allows us to allocate power-of-2 aligned physical blocks, which is needed for atomic writes.

2. Hook the direct IO path in ext4 to use aligned allocation to obtain physical blocks at a given alignment, which is needed for atomic IO. If for any reason we are not able to obtain blocks at given alignment we fail the atomic write.

Currently this RFC does not impose any restrictions for atomic and non-atomic allocations to any inode, which also leaves policy decisions to user-space as much as possible. So, for example, the user space can:

* Do an atomic direct IO at any alignment and size provided it satisfies underlying device constraints. The only restriction for now is that it should be power of 2 len and atleast of FS block size.

* Do any combination of non atomic and atomic writes on the same file in any order. As long as the user space is passing the RWF_ATOMIC flag to pwritev2() it is guaranteed to do an atomic IO (or fail if not possible).

There are some TODOs on the allocator side which are remaining like...

1. Fallback to original request size when normalized request size (due to preallocation) allocation is not possible.
2. Testing some edge cases.

But since all the basic test scenarios were covered, hence we wanted to get this RFC out for discussion on atomic write support for DIO in ext4.

Further points for discussion -

1. We might need an inode flag to identify that the inode has blocks/extents atomically allocated. So that other userspace tools do not move the blocks of the inode for e.g. during resize/fsck etc.
a. Should inode be marked as atomic similar to how we have IS_DAX(inode) implementation? Any thoughts?

2. Should there be support for open flags like O_ATOMIC. So that in case if user wants to do only atomic writes to an open fd, then all writes can be considered atomic.

3. Do we need to have any feature compat flags for FS? (IMO) It doesn't look like since say if there are block allocations done which were done atomically, it should not matter to FS w.r.t compatibility.

4. Mostly aligned allocations are required when we don't have data=journal mode. So should we return -EIO with data journalling mode for DIO request?

Script to test using pwritev2() can be found here:
https://gist.github.com/OjaswinM/e67accee3cbb7832bd3f1a9543c01da9

Regards,
ojaswin

[1] https://lore.kernel.org/linux-fsdevel/[email protected]

Ojaswin Mujoo (7):
iomap: Don't fall back to buffered write if the write is atomic
ext4: Factor out size and start prediction from
ext4_mb_normalize_request()
ext4: add aligned allocation support in mballoc
ext4: allow inode preallocation for aligned alloc
block: export blkdev_atomic_write_valid() and refactor api
ext4: Add aligned allocation support for atomic direct io
ext4: Support atomic write for statx

 block/fops.c                |  18 ++-
 fs/ext4/ext4.h              |  10 +-
 fs/ext4/extents.c           |  14 ++
 fs/ext4/file.c              |  49 ++++++
 fs/ext4/inode.c             | 142 ++++++++++++++++-
 fs/ext4/mballoc.c           | 302 +++++++++++++++++++++++++-----------
 fs/iomap/direct-io.c        |   8 +-
 include/linux/blkdev.h      |   2 +
 include/trace/events/ext4.h |   2 +
 9 files changed, 442 insertions(+), 105 deletions(-)
Signature · 1 line
2.39.3