News for hackers. Stuff that matters.
Re:Fast Commits for Ext4 by severino on Friday January 15, 2021 @06:35PM (#25798114)
I don't know if I got this correctly:

> When we look at the fsync() and fdatasync() man pages, we see that those system calls only guarantee to write data linked to the given file descriptor. With ext4, as a side effect of the filesystem structure, all pending data and metadata for all file descriptors will be flushed instead. This creates a lot of I/O traffic that is unneeded to satisfy any given fsync() or fdatasync() call

Does it mean that, under ext4, a call to fsync is essentially the same as a call to sync(2)?

Re:Fast Commits for Ext4 by jldugger on Friday January 15, 2021 @09:05PM (#25799232)
Yes, this was a source of many problems when firefox moved its history and bookmarking engine to sqlite (I think) which used fsync for consistency guarentees. Leading to situations where making a bookmight might cause your entire computer to pause as disk writes spin up.
Re:Fast Commits for Ext4 by JNRowe on Saturday January 16, 2021 @12:22AM (#25800269)
Looks like Firefox 3¹, all the way back in 2008! There is a good description of fixes and workarounds on LWN².

¹ http://shaver.off.net/diary/2008/05/25/fsyncers-and-curvebal...

² https://lwn.net/Articles/328363/

Re:Fast Commits for Ext4 by jbritton on Friday January 15, 2021 @07:58PM (#25798780)
Last year I had a problem where I had a function that was logging and a sync() call in another process was blocking the logging for greater than 10 seconds and this caused a timeout aborting the operation my code was performing. I have now moved all logging into a queue that logs on its own thread. This was a gotcha I never anticipated.
Re:Fast Commits for Ext4 by wahern on Friday January 15, 2021 @09:45PM (#25799513)
Unless you have infinite memory, at some point you want a task to slow down, block, or whatever in the face of resource exhaustion.

It's not a bad idea to maintain a local buffer that gives you a certain amount of cushion. I recently helped a team resolve the exact problem you had, with a similar solution. But excessive, unnecessary use of non-pageable memory is one of the things which induce early I/O contention, causing these stalls to begin with. (Consider an overloaded or errant process generating and buffering a lot of logging noise, precisely because the overtaxed system is under heavy I/O contention.)

To reiterate: you want backpressure, which means that you want a process which is exhausting limited resources to slow down or block. And you want that to transitively slow down or block upstream requests. Too many developers don't understand this and insert hacks to solve their immediate problem (e.g. closing a ticket complaining about intermittent SLA latency misses) without appreciating the broader issues, which at the end of the day just contributes to these problems.

One of the alternatives people attempt is to insert a gazillion knobs to permit dedicated resource allocation. But now you just have two problems, the second being figuring out what the magic values should be--a never ending and often intractable problem. This rarely ends well except for highly specialized tasks--e.g. a dedicated DB administrator who spends all day attending to and tuning a database instance.

That said, in the old days you mounted /var (and if you were super fancy, /var/log) on different disks to minimize unrelated I/O contention.

Re:Fast Commits for Ext4 by wscott on Saturday January 16, 2021 @06:09AM (#25801526)
Yes. I consider it one of my worst bugs in the Linux kernel and in big servers you pretty much can't have any programs that call fsync() because it will cripple your performance.

That paragraph caused a whiplash of emotions while reading, "Cool!!!... what???? Ug."

Re:Fast Commits for Ext4 by severino on Saturday January 16, 2021 @07:51AM (#25801895)
Yes, however when you're running a DBMS in your server, I guess it will be doing fsync() all the time. I wonder, if other filesystems like XFS or ZFS have a different behavior here, how much performance gain for a typical database load they can achieve in comparison to ext4.
Re:Fast Commits for Ext4 by AdamJacobMuller on Friday January 15, 2021 @06:59PM (#25798307)
No, it might sync some metadata for other files, but it won't sync their data.
Re:Fast Commits for Ext4 by danudey on Friday January 15, 2021 @07:36PM (#25798623)
Are you certain? The quote actually says:

> With ext4, as a side effect of the filesystem structure, *all pending data and metadata for all file descriptors* will be flushed instead.

Is the article mistaken?

Re:Fast Commits for Ext4 by jradd on Friday January 15, 2021 @08:45PM (#25799100)
manpage suggests the article is not mistaken. `max_batch_time=0` disables batch processing synchronous write operations. the default is 15ms.

It seems like a good idea for client filesystem to mount synchronously for data integrity. I'm not aware of i/o being a factor here.

Of course this doesn't prevent applications mishandling of file objects.

Re:Fast Commits for Ext4 by jradd on Friday January 15, 2021 @09:06PM (#25799236)
no, the fsync call remains the same as it does in ext3 and most filesystems.

However in ext4 there is no need to call sync unless you disable batch processing of synchronous writes.

Re:Fast Commits for Ext4 by gautamcgoel on Friday January 15, 2021 @07:05PM (#25798369)
Realistically, when can we expect this on fresh installs of Debian or Fedora? Will desktop users notice a perceptible performance gain when performing operations on large files?
Re:Fast Commits for Ext4 by viraptor on Friday January 15, 2021 @09:22PM (#25799355)
Not that far for Fedora since they're already on 5.9 and if you opt in for the kernel stabilisation COPR, you can have it today: https://fedoraproject.org/wiki/Test_Day:2021-01-04_Kernel_5....
Re:Fast Commits for Ext4 by danieldk on Saturday January 16, 2021 @03:04AM (#25800866)
Correction: Fedora has already rolled out 5.10 on Fedora 33.
Re:Fast Commits for Ext4 by cat199 on Friday January 15, 2021 @10:01PM (#25799604)
not sure how it relates to fedora, but article also points out you need to mkfs to build a new structure and the patch to build it hasn't hit ext2progs mainline yet
Re:Fast Commits for Ext4 by mrlonglong on Sunday January 17, 2021 @03:32PM (#25814646)
Is there no other way to convert existing ext4 filesystems to use the new structures?
Re:Fast Commits for Ext4 by LeoPanthera on Friday January 15, 2021 @07:44PM (#25798689)
Fedora has switched to btrfs, but you can still choose your own preferred filesystem at install, just as you have always been able to.
Re:Fast Commits for Ext4 by throw7 on Friday January 15, 2021 @09:22PM (#25799358)
That's just the desktop "spin", albeit that is the default download. Personally, it's gonna be some time before I'd switch to btrfs if ever.
Re:Fast Commits for Ext4 by gautamcgoel on Friday January 15, 2021 @09:25PM (#25799377)
Why is that?
Re:Fast Commits for Ext4 by throw7 on Friday January 15, 2021 @09:42PM (#25799483)
For me personally, I am waiting for ENOSPC to be 100% solved and understood. It may or may not be (maybe it's theoretically impossible to solve who knows), but until then I'm content with what I have now.
Re:Fast Commits for Ext4 by the8472 on Saturday January 16, 2021 @03:51AM (#25801042)
> I am waiting for ENOSPC to be 100% solved and understood

It's understood, there's no black magic. When there's not enough contiguous space to perform a metadata copy (it's a copy on write filesystem, no in-place overwrites!) then it returns an error, even if there's still some free but fragmented space or some free space in the data block groups. A rebalance when metadata blockgroup total size diverges significantly from actual use should solve this.

For small filesystems there also is the option to choose mixed block groups, then there won't be the situation where there's still free space in the data groups while the metadata groups are full.

Re:Fast Commits for Ext4 by cozzyd on Friday January 15, 2021 @08:09PM (#25798862)
i mean, my Fedora system will be on ext4 for a while since I don't wipe anew with every upgrade...
Re:Fast Commits for Ext4 by sroussey on Friday January 15, 2021 @03:29PM (#25795948)
Curious how this change set would affect MySQL or postgresql?
Re:Fast Commits for Ext4 by cbhl on Friday January 15, 2021 @03:51PM (#25796265)
Do folks typically turn on journaling at the filesystem layer when running a database?

The database itself contains journaling, so one might choose to run with data=writeback or even directly against the block device if they were concerned about performance.

Re:Fast Commits for Ext4 by jabberwcky on Friday January 15, 2021 @04:45PM (#25796960)
You definitely need both, these are two completely different kinds of journalling:

- Filesystem journalling is making robust changes to the data structures describing directories, files, and where files live, in units of atomic filesystem operations. For example, the filesystem journal may record "CREATE FILE", which translates to "update directory entry 1234 in directory block 5678, then allocate and initialize extent descriptor 9999, then write an inode at array entry 74234"

- Database journalling is making robust changes to the data structures describing the actual file contents, in units of atomic logical application operations. For example, a DB journal may record "INSERT ROW", which translates to "update block 123 of this index file, and 234 of this data file", application-specific relationships like that cannot be captured by the filesystem on UNIX.

(Note: NTFS is transactional on Windows. It's entirely possible to correlate independent writes and make them atomic, so on Windows at least, in theory a DB could exist without a separate journal. I don't know if this is used in practice). Even if it were in use, it places severe limits on the kinds of concurrency optimizations a database system could otherwise perform, because all of that stuff moves behind the curtain of the OS interfaces.

Re:Fast Commits for Ext4 by the8472 on Saturday January 16, 2021 @10:10AM (#25802657)
data=writeback does not disable the journal completely. It only removes ordering of the data writes relative to the metadata journaling. The metadata journaling itself remains active.

You can create the file, preallocate space, fsync the inode and the directory to ensure that it will be visible after a crash and then begin using the allocated space as a journal. Then you only have to fdatasync or sync_file_range whatever part of your journal needs to be persisted and those syncs can now be unordered relative to the filesystem's metadata journal without risk of data loss.

So data=writeback can be used safely, but you have to be very very careful about getting the syscall sequence right. Most applications implemented with sufficient paranoia and so are better served by stricter ordering modes and auto_da_alloc.

Re:Fast Commits for Ext4 by comboy on Friday January 15, 2021 @03:58PM (#25796362)
I don't think that those who read the manual do: https://www.postgresql.org/docs/13/wal-intro.html (unless they care about quick crash recovery)
Re:Fast Commits for Ext4 by kureikain on Friday January 15, 2021 @06:36PM (#25798122)
Is this why many database yield better performance with XFS vx Ext4.
Re:Fast Commits for Ext4 by drran on Saturday January 16, 2021 @03:19AM (#25800911)
After power loss without FS journal, your database may not have files to work with.
Re:Fast Commits for Ext4 by fulafel on Saturday January 16, 2021 @07:39AM (#25801856)
It's on by default in ext4.
Re:Fast Commits for Ext4 by jldugger on Friday January 15, 2021 @03:59PM (#25796384)
Probably not much -- the main win is not having to fsync files unrelated to your work, which is great for desktops which run multiple unrelated tasks (browser, terminals, rss readers, email clients, steam/game updates, package downloads). But I have to imagine SQL databases are typically run on systems dedicated to that singular task.
Re:Fast Commits for Ext4 by danudey on Friday January 15, 2021 @07:42PM (#25798683)
On the other hand, DBs call fsync() very often, which would presumably trigger this frequent "stop the world, write the data" behaviour vastly more than otherwise, which could make your I/O very stuttery.

My solution has always been to just add a RAID controller with a battery-backed write cache, and then to disable barriers on ext4 and switch to journal=writeback. The data gets written to the cache "instantly", meaning less risk of data corruption (either at DB or filesystem level) from crashes or power outages. Saves having to worry about any of this sort of stuff.

Re:Fast Commits for Ext4 by jldugger on Friday January 15, 2021 @09:03PM (#25799211)
> On the other hand, DBs call fsync() very often, which would presumably trigger this frequent "stop the world, write the data" behaviour vastly more than otherwise, which could make your I/O very stuttery.

But that's because they want to stop the world and write the data. Or more specically write the data they wrote. The issue is that more data is getting written than POSIX deems required, and that's the perf hit.

Depending on your usecase, libeatmydata or battery backed RAID can help, but I'd feel a bit skeptical of 'we want to lie about fsync() to our DB' for many workloads.

Re:Fast Commits for Ext4 by ape4 on Friday January 15, 2021 @05:54PM (#25797641)
ext4 is getting better just as Fedora has moved to Btrfs
Re:Fast Commits for Ext4 by kzrdude on Friday January 15, 2021 @06:50PM (#25798233)
ext4 and btrfs are continuously developing.
Re:Fast Commits for Ext4 by type0 on Friday January 15, 2021 @07:21PM (#25798510)
You still have the option to use ext4, can't imagine they will stop supporting it
Re:Fast Commits for Ext4 by throwawaygulf on Friday January 15, 2021 @07:43PM (#25798687)
>Fedora has moved to Btrfs

(Sigh)... Another reason to move away from Fedora.

Re:Fast Commits for Ext4 by LanternLight83 on Friday January 15, 2021 @09:08PM (#25799249)
Funnily enough, BTRFS and ZRAM out-of-the-box are the reasons I moved to Fedora for all but my main Gentoo/ZFS system. To each their own c:

Would you mind sharing what other features you've found pushing you away from Fedora and why? For my part, I'll admit, BTRFS and ZRAM both work against hibernation out-of-the-box, which is my most major gripe.

Re:Fast Commits for Ext4 by cmurf on Friday January 15, 2021 @09:35PM (#25799430)
Neither Btrfs nor zram-based swap, inhibit hibernation. There is a kernel lockdown policy that inhibits hibernation when UEFI Secure Boot is enabled.

Since the hibernation image is neither encrypted nor signed, it's a potential attack vector to subvert the UEFI Secure Boot mechanism. Because UEFI Secure Boot systems are common (Windows hardware certification requires it exist and be enabled by default), it was decided to, by default, save the space on disk for disk-based swap and use zram-based swap instead.

It is straight forward to create a disk-based partition during installation, and it is configured to support hibernation, while still remaining subject to the lockdown policy.

Re:Fast Commits for Ext4 by Dylan16807 on Friday January 15, 2021 @09:43PM (#25799494)
Well why isn't it encrypted or signed?
Re:Fast Commits for Ext4 by cmurf on Saturday January 16, 2021 @02:43AM (#25800802)
The work is incomplete. https://lkml.org/lkml/2019/7/10/601
Re:Fast Commits for Ext4 by loeg on Friday January 15, 2021 @09:21PM (#25799346)
The Fedora installer has let you choose between ext4 (and ext3 before it), XFS, and BtrFS for like, more than a decade? This should not really influence your distro choice one way or another.
Re:Fast Commits for Ext4 by throwawaygulf on Saturday January 16, 2021 @04:28PM (#25805672)
It's defaulting to btrfs, which is a poor decision. If Fedora is making such poor decisions on basic things like default filesystems, that gives me more than enough influence to chose one way or another.

They were all aboard with Stratis, but here we are, btrfs moving back in.

Re:Fast Commits for Ext4 by mixmastamyk on Saturday January 30, 2021 @01:55PM (#25971817)
The point of fedora is to be on the bleeding edge and get things tested for blue hat. If this is a problem, choose another distro.
Re:Fast Commits for Ext4 by bartvk on Saturday January 16, 2021 @02:57AM (#25800841)
Since you have a new account, I'm just pointing out that shallow dismissals are mentioned in the guidelines (link at the bottom of each page).
Re:Fast Commits for Ext4 by gautamcgoel on Saturday January 16, 2021 @01:09AM (#25800475)
Can you elaborate why your disenchanted with Fedora? I'm considering jumping to Debian myself.
Re:Fast Commits for Ext4 by quotemstr on Friday January 15, 2021 @05:27PM (#25797370)
> One of the things that I did discuss with Harshad was using some hueristics, where if there are two "unrelated" applications (e.g., different session id, or process group leader, or different uid, etc. --- details to be determined layer), we would not entangele writes to unrelated files via fsync(2), while forcing files written by the same application to share fate with one another even if only file is fsync'ed.

Ugh. This is why we can't have nice things. I really don't want the kernel's filesystem performance to depend on the number of different UIDs writing to the filesystem. That is insanity!

Ted Ts'o is just wrong here: performance should take priority over preserving the behavior of applications that rely on non-contractual implementation details of the Linux kernel. fsync should sync only the indicated file, and that's that. We can add a mount option to let users opt into the older, safer behavior, but we shouldn't suffer for essentially an eternity because somewhere, someone might have written an application that depends on an ext4 implementation detail.

Re:Fast Commits for Ext4 by anarazel on Friday January 15, 2021 @06:11PM (#25797836)
I think you have to see that in the light of all the complaints about data loss when people moved from ext3 to ext4. Ted IIRC pushed back against that with arguments like yours, but eventually gave up (leading to a heuristic for detecting such cases, cf the auto_da_alloc mount option).
Re:Fast Commits for Ext4 by quotemstr on Friday January 15, 2021 @06:36PM (#25798117)
Back then, people could point to specific examples of applications that depended on the sync-on-rename feature. What specific examples is he able to cite now? The entire discussion seems like a discussion of hypotheticals.
Re:Fast Commits for Ext4 by nfoz on Friday January 15, 2021 @08:05PM (#25798828)
I'm not seeing your quoted text in the article. Am I missing something?
Re:Fast Commits for Ext4 by The_rationalist on Friday January 15, 2021 @03:58PM (#25796361)
Re:Fast Commits for Ext4 by dis-sys on Saturday January 16, 2021 @06:26AM (#25801586)
maybe it is too early to ask, but is there any realistic benchmarks on this new feature?