On Sat, Dec 28, 2024 at 08:22:17PM -0500, Theodore Ts'o wrote:
Note that it's not a sync, but rather, under certain circumstances, we initiate writeback --- but we don't wait for it to complete before allowing the close(2) or rename(2) to complete. For close(2), we will initiate a writeback on a close if the file descriptor was opened using O_TRUNC and truncate took place to throw away the previous contents of the file. For rename(2), if you rename on top of a previously existing file, we will initiate the writeback right away. This was a tradeoff between safety and performance, and this was done because there was an awful lot of buggy applications out there which didn't use fsync, and the number of application programmers greatly outnumbered the file system programmer. This was a compromise that was discussed at a Linux Storage, File Systems, and Memory Management (LSF/MM) conference many years ago, and I think other file systems like btrfs and xfs had agreed in principle that this was a good thing to do --- but I can't speak to whether they actually implemented it.
xfs is actually where I first encountered this issue with dpkg. I think it was on an alpha system not long after xfs was released for linux, which was not necessarily the most stable combination. The machine crashed during a big dpkg run and on reboot the machine had quite a lot of empty files where it should have had executables and libraries. I think this was somewhat known in that time frame (1999/2000) but it was written off as xfs being buggy and I don't recall it getting a lot of attention. (Though I still run into people who insist xfs is prone to file corruption based on experiences like this from 25 years ago.) Also, xfs wasn't being used for / much, and was mostly found on the kind of systems that didn't lose power and with the kind of apps that either didn't care about partially written files or were more careful about how they wrote--so the number of people affected was pretty small. When ext starting exhibiting similar behavior it suddenly became a much bigger deal.