|
|
Log in / Subscribe / Register

Atomic writes for ext4

By Jake Edge
April 10, 2025

LSFMM+BPF

Building on the discussion in the two previous sessions on untorn (or atomic) writes, for buffered I/O and for XFS using direct I/O, Ojaswin Mujoo remotely led a session on support for the feature on ext4. That took place in the combined storage and filesystem track at the 2025 Linux Storage, Filesystem, Memory Management, and BPF Summit. Part of the support for the feature is already in the upstream kernel, with more coming. But there are still some challenges that Mujoo wanted to discuss.

For ext4, a single filesystem block can be written atomically; that support was merged for 6.13, he said. There is work in progress on doing multi-block atomic writes in ext4. There are two main allocation challenges that need to be handled for multi-block, though: unaligned extents that do not match the hardware alignment requirements and ranges with mixed mappings, for example those that cover both unwritten data and hole sections.

The ext4 bigalloc feature eliminates the problem with unaligned extents because the cluster size for the filesystem can be set to, say, 16KB, so everything will be aligned on those boundaries. But it is a filesystem-wide setting, even if atomic writes are only needed for a few files, and it requires that any existing filesystem be reformatted to use the feature. Reformatting may not be desirable for all use cases, but multi-block writes with bigalloc is working now.

$ sudo subscribe today

Subscribe today and elevate your LWN privileges. You’ll have access to all of LWN’s high-quality articles as soon as they’re published, and help support LWN in the process. Act now and you can start with a free trial subscription.

Currently, without bigalloc, ext4 does not have a way to guarantee the needed alignment; if an atomic write is done on an unaligned extent, ext4 has no fallback, it simply returns an error to the user. In order to ensure the alignment, Mujoo is exploring a combination of extsize and forcealign. Extsize is a per-inode alignment "hint" to the allocator that is set with an ioctl() command; it will try to allocate all extents to the boundary specified, but can fail. The forcealign extended attribute can be set on a file that has an extsize specified in order to require that allocation alignment; it can be seen as a per-file bigalloc.

Luis Chamberlain said that he has done some analysis of ext4 using bigalloc with a 16KB cluster size and noticed that some writes are not aligned on 16KB boundaries; he wondered why that was. Ted Ts'o said that bigalloc guarantees that data blocks are aligned to the cluster size, but not metadata blocks, which are still 4KB-aligned. Journal updates, inode updates, and bitmap-allocation-block updates could all cause writes that are not aligned to the cluster size.

Chamberlain wondered if there was any way to support 16KB writes for ext4 metadata; Ts'o said that it would require ext4 support for filesystem block sizes larger than the page size. The buffered I/O path for ext4 would probably need to switch to using iomap, he said; the ext4 developers are interested in getting patches that make that switch and he understands that large-block-size support is fairly straightforward once that happens.

The idea is to not require any reformatting of the filesystem with extsize and forcealign, Mujoo said. That will require fallbacks for files that are not properly aligned when forcealign is set for them. A "compat" feature flag can be added that can be set on existing filesystems; that will allow older kernels to mount the filesystem. An ioctl() command can be added to fix files that are not properly aligned. The forcealign feature might also have use cases outside of atomic writes; for example, it might help with getting properly aligned blocks for use with a direct-access (DAX) filesystem.

The problem of mixed mappings affects both bigalloc and non-bigalloc ext4; avoiding atomic writes with mixed mappings should be the goal, but it may not always be met. If a mixed mapping is used for an atomic write, there are three solutions that he sees. The first is to return an error, which might be popular for those who do not want a fallback path. Another is to zero the holes and write them with the rest. Finally, ext4 can do something similar to what XFS is doing: write the data in a new place and atomically change the extent mappings. Ext4 has no infrastructure to support the XFS-like solution, however, so it would add complexity to the solution.

Mujoo described the roadmap for ext4 atomic-write support. The patch sets for multi-filesystem-block writes using bigalloc and for adding extsize and forcealign support to ext4 are being targeted for Linux 6.16. Subsequent features, including using extsize and forcealign for multi-block atomic writes, exploring an extent-swapping fallback, and enabling buffered atomic writes for ext4, will come later.

Chamberlain asked if the idea of using the multi-index feature of XArray had been evaluated as a means to more generically support atomic writes for all filesystems. Mujoo agreed that it would be nice to have VFS support for atomic writes that could be used by more filesystems, but has not really looked at that.


Index entries for this article
KernelAtomic I/O operations
KernelFilesystems/ext4
ConferenceStorage, Filesystem, Memory-Management and BPF Summit/2025


to post comments

CoW

Posted Apr 11, 2025 8:47 UTC (Fri) by josh (subscriber, #17465) [Link] (7 responses)

One more awesome feature becoming available for ext4.

Still hoping copy-on-write files became available someday. I'd love to be able to use those to efficiently guard against files being modified between hashing and transmission, without having to copy them into RAM.

CoW

Posted Apr 11, 2025 15:44 UTC (Fri) by tytso (✭ supporter ✭, #9993) [Link] (6 responses)

Many years ago, we roughly scoped out how we might be able to support reflink for ext4. The issue has always been finding someone with the time (and most likely, because it's non-trivial) corporate sponsorship to do the work.

Over 15 years ago, I participated with a company-wide study about whether there was a business case to investing in file system technologies --- and at the time, the conclusion was the ROI Just Wasn't There. What the enterprise customers of my employer at the time pay $$$ for are things like application servers and databases, and things like COW support doens't help with those use case (in fact; they tend to hurt --- COW file systems tend to have a way of turning off COW to improve database performance). In contrast, the Sun engineers didn't bother asking for product analysis from the sales folk or management, and just Went Ahead and Did It. Perhaps the business case for Sun customers were different, but Sun went out of business --- and my former employer is still around.

That being said, if some company wants to invest 2 or 3 SWE-years (of highly talented FS talent) to implement reflink support for ext4, I'm happy to work with them. But given that we live in a world where a CEO of a major social media company has said that he is laying off engineers to pay for more GPU's.... this might not be very likely.

CoW

Posted Apr 11, 2025 16:52 UTC (Fri) by intelfx (subscriber, #130118) [Link] (5 responses)

Sure. Only hyperscalers exist; nothing else matters.

I wonder if this means that we, the mere mortal worthless users, should simply use other filesystems whose development we can finance and influence (like ZFS, whose development is funded by people buying NAS boxes and small businesses who worry about data integrity, or bcachefs, whose development is funded on Patreon) rather than ext4, The Filesystem From The World Where Only Hyperscalers Exist.

CoW

Posted Apr 11, 2025 17:20 UTC (Fri) by tytso (✭ supporter ✭, #9993) [Link] (4 responses)

You should use whatever file system meets your needs. I'm not sure how much new features in ZFS is actually being funded by NAS manufacturers and small business, but if it meets your needs, use what works for you.

Ext4 is funded not just by hyperscalers; we get non-trivial contributions from companies like IBM, SuSE, Oracle, as well as a hobbyist or two. A lot of the initial ext4 work was funded by IBM, when I was a member of IBM Linux Technology Center. So I'm quite familiar with the neesd of enterprise users. And we've had features like ext4's Unicode casefolding that was funded by Steam for gaming.

In general, my attitude is "horses for courses". If for your use case, XFS is better, use XFS. If ZFS is better, and you're not worried about the GPL / CDDL license compatibility issues, then hey, use ZFS. Knock yourself out.

CoW

Posted Apr 11, 2025 17:31 UTC (Fri) by intelfx (subscriber, #130118) [Link] (3 responses)

Then what is the point of that very distinct derisiveness in the great-grandparent comment towards both users who happen to want $feature and competitors that happen to have $feature?

It's absolutely fine to say "this $feature can happen, but nobody wanted to fund/develop it so far", but what's the point of bringing up ZFS just to say "look at all those suckers who happen to have $feature, aren't they suckers?"

CoW

Posted Apr 11, 2025 19:08 UTC (Fri) by MrWim (subscriber, #47432) [Link] (2 responses)

FWIW I don’t see any derisiveness in that comment. The comment about business cases seems to be a lament rather than a jab.

CoW

Posted Apr 12, 2025 3:06 UTC (Sat) by tytso (✭ supporter ✭, #9993) [Link] (1 responses)

Indeed, I wasn't saying that it was the user of ZFS that were the suckers; they weren't the ones who made the decision to invest in that feature, after all.

What I was saying that companies that make investment decisions without consider the question of return on that investment have a tendency to not do well, and that's what happened to Sun. Which is actually quite a shame, because I have nothing but respect for the technical skills of the Solaris team. They had some really, super smart, super-talented engineers.

Unfortunately, Sun management, including their technical management, made enough mistakes (including assuming that the dot-Com boom would last forever), that Sun Microsystems wasn't able to continue as a going concern. And that's sad; sure, they open-sourced Solaris (with a weird license that was intentionally not GPL-compatible, but they at least did release it), and they did give the world DTrace and ZFS. But who knows what other technologies they could have come up with if Sun had been able to survive as a company, and the could have kept the Solaris team together?

This is *why* companies are well-advised to consider the business case, and return on investment, when considering what features to invest in. Its not enough that the feature is technically "cool".

CoW

Posted Apr 13, 2025 9:02 UTC (Sun) by cpitrat (subscriber, #116459) [Link]

Or build a startup during the boom, become a millionaire, pay generously some talented engineers to develop cool features in open source software and go bankrupt when the bubble bursts. Everybody wins: the nice fetures are here forever, you and some engineers had some good time and made some money and a VC enjoyed being virtually rich for some time.


Copyright © 2025, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds