News for hackers. Stuff that matters.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by r1ch on Tuesday November 21, 2023 @10:25PM (#38374377)
We shipped a shader cache in the latest release of OBS and quickly had reports come in that the cached data was invalid. After investigating, the cache files were the correct size on disk but the contents were all zero. On a journaled file system this seems like it should be impossible, so the current guess is that some users have SSDs that are ignoring flushes and experience data corruption on crash / power loss.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by fulafel on Tuesday November 21, 2023 @11:48PM (#38374837)
I think this is typical behaviour with ext4 on Linux, if the application doesn't do fsync/fdatasync to flush the data to disk.

Depending on mount options, ext4fs does metadata journaling ensuring the FS itself is not borked, but not data journaling which would safeguard the file contents in event of unclean shutdown with pending writes in the caches.

The same phenomenon is at play when people complain that their log files contain NUL bytes after a crash. The file system metadata has been updated for the size of the file to fit the appended write, but the data itself was not written out yet.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Dylan16807 on Wednesday November 22, 2023 @12:40AM (#38375122)
The current default is data=ordered, which should prevent this problem if the hardware doesn't lie. The data doesn't go in the journal, but it has to be written before the journal is committed.

There was a point where ext3 defaulted to data=writeback, which can definitely give you files full of null bytes.

And data=journal exists but is overkill for this situation.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by charleshn on Wednesday November 22, 2023 @01:35AM (#38375555)
It's likely because of delayed allocations (delalloc): https://issuetracker.google.com/issues/172227346#comment6

because the only guarantee which data=ordered provides is the security guarantee that stale data won't be revealed.

Yes, it's bad and breaks prefix append consistency, and does not match the documentation...

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by fulafel on Wednesday November 22, 2023 @10:20AM (#38380405)
For more context, that's a comment from one of the ext4 main authors, Ted Ts'o. the other subsequent comment from him spells out the case more but sadly no spelled out NUL byte origin story I spotted from skimming.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by charleshn on Thursday November 30, 2023 @05:53PM (#38480392)
The original report [0] shows the corruption due to NUL bytes at the end of the file (see the hexdump). This comment [1] from Ted Ts'o details the exact chain of events leading to it.

[0] https://issuetracker.google.com/issues/172227346 [1] https://issuetracker.google.com/issues/172227346#comment8

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by consp on Wednesday November 22, 2023 @02:40AM (#38376165)
My only n=1 observation is that null values in logs occur on nvme, ssd and spinning rust. All ext4 with defaults. I do have the idea it occurs more on nvme drives though. But maybe my systems settings are just booked.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by altfredd on Wednesday November 22, 2023 @01:48AM (#38375682)
The "data" setting of ext filesystems isn't replacement for fsync().
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Dylan16807 on Wednesday November 22, 2023 @02:14AM (#38375943)
It's not a replacement but it can give you some guarantees.

Also fsync is a terrible API that should be replaced, but that's mostly a different topic.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by the8472 on Wednesday November 22, 2023 @05:32AM (#38377449)
At least on linux you can use io_uring to make fsync asynchronous. And you can initiate some preparatory flushing with sync_file_range and only do the final commit with fsync to cut down the latency.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by matja on Wednesday November 22, 2023 @05:10AM (#38377297)
> which should prevent this problem if the hardware doesn't lie.

Or, one can take the ZFS approach and assume the hardware often lies :)

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by worthless-trash on Wednesday November 22, 2023 @06:49AM (#38377976)
I do not know how zfs will overcome hardware lying. If its going to fetch data that is in the drives cache, how will it overcome the persistence problem ?
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by danarmak on Wednesday November 22, 2023 @07:07AM (#38378135)
It will at the very least notice that the read data does not match the stored checksum and not return the garbage data to the application. In redundant (raidz) setups it will then read the data from another disk, and update the faulty disk. In a non-redundant setup (or if enough disks are corrupted) it will signal an IO error.

An error is preferred to silently returning garbage data!

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by nolist_policy on Wednesday November 22, 2023 @07:41AM (#38378419)
The "zeroed-out file" problem is not about firmware lying though, it is about applications using fsync() wrongly or not at all. Look up the O_PONIES controversy.

Sure, due to their COW nature zfs and btrfs provide better behavior despite broken applications. But you can't solve persistence in the face of lying firmware.

Even thought zfs has some enhancements to not corrupt itself on such drives, if you run for example a database on top, all guarantees around commit go out the window.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Dylan16807 on Wednesday November 22, 2023 @01:19PM (#38382939)
"Renaming a file should always happen-after pending writes to that file" is not a big pony. I think it's a reasonable request even in the absence of fsync.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by nolist_policy on Wednesday November 22, 2023 @02:53PM (#38384243)
Well, for one rename() is not always meant to be durable. It can also be used for IPC, for example some mail servers use it to move mails between queues. Flushing before every rename is unexpected in that situation.

Fun fact: rename() is atomic with respect to running applications per POSIX, that the on-disk rename is also atomic is only incidental.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Dylan16807 on Wednesday November 22, 2023 @10:00PM (#38388709)
I'm not suggesting flushing for rename. If a file write and a rename happen shortly before power loss, and neither goes through, that's fine.

With this rule, three outcomes are acceptable: both occur, or neither occur, or just the file write happens. The unacceptable outcome is that just the rename happens.

("file write" here could mean a single write, or an open-write-close sequence, it doesn't particularly matter and I don't want to dig through old discussions in too much detail)

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by gumby on Wednesday November 22, 2023 @07:17AM (#38378215)
It can’t tell if the drive is lying to it.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by worthless-trash on Wednesday November 22, 2023 @08:45AM (#38379025)
This was my theory too, its not going to help in -these- situations. I can't see how.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by fulafel on Wednesday November 22, 2023 @12:21PM (#38382053)
As an aside, can you still get the bad checksum file contents with zfs? Eg if it's a big database with its own checksums you might want to run a db level recovery on it.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by matja on Wednesday November 22, 2023 @10:52AM (#38380847)
Actual file data ends up in the same transaction group (txg) as metadata if both are changed within the same txg commit (either flushed explicitly, due to recordsize/buffer limit being reached, or txg commit timeout - 5 seconds by default), so if there is a write barrier violation caused by hardware lies followed by an untimely loss of power, the checksums for the txg updates won't match and they get rolled-back until the last valid one when importing the pool - which doesn't end up zero'ing out extents of a file (like in xfs) or ending up with a zero file size (like on ext3/ext4).
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by lxgr on Wednesday November 22, 2023 @12:30AM (#38375074)
I don't think that's how it works: Flushing metadata before data would be a security concern (consider e.g. the metadata change of increasing a file's length due to an append before the data change itself), so file systems usually only ever do the opposite, which is safe.

Getting back zeroes after a metadata sync (which must follow a data sync) would accordingly be an indication of something weird having happened at the disk level: We'd expect to either see no data at all, or correct data, but not zeroes or any other file's or previously written stale data.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Filligree on Wednesday November 22, 2023 @12:41AM (#38375124)
The file isn't stored contiguously on disk, so that would depend on the implementation of the filesystem. Perhaps the size of the file can be changed, without extents necessarily being allocated to cover the new size?

I seem to vaguely recall an issue like that, for ext4 in particular. Of course it's possible in general for any filesystem that supports holes, but I don't think we can necessarily assume that the data is always written, and all the pointers to it also written, before the file-size gets updated.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by lxgr on Wednesday November 22, 2023 @12:49AM (#38375156)
At least for ext4 and actually written data (i.e. not ftruncate’d files), I believe zeroes should really not occur.

Both extents and the file size are metadata as far as I understand, which would be atomically updated through the journal.

Data can be written before metadata (in data=ordered mode):

> All data are forced directly out to the main file system prior to its metadata being committed to the journal.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Filligree on Wednesday November 22, 2023 @01:02AM (#38375245)
Is data=ordered the default?
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by lxgr on Wednesday November 22, 2023 @09:13AM (#38379409)
As far as I can tell it's always been on both ext3 and ext4, yes.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Dylan16807 on Wednesday November 22, 2023 @12:49AM (#38375162)
Ext3 will totally let you expose yourself to those security issues. I'm not sure about ext4.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by lxgr on Wednesday November 22, 2023 @12:53AM (#38375187)
Only in data=writeback mode, which is not the default in either ext3 or ext4.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by colanderman on Wednesday November 22, 2023 @08:36AM (#38378917)
The file's size could have been set by the application before copying data to it. This will result in a file which reads all zeroes.

Or if it were a hardware ordering fault, remember that SSD TRIM is typically used by modern filesystems to reclaim unused space. TRIMmed blocks read as zero.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by lxgr on Wednesday November 22, 2023 @09:12AM (#38379396)
> The file's size could have been set by the application before copying data to it. This will result in a file which reads all zeroes.

Hm, is that a common approach? I thought applications mostly use fallocate(2) for that if it's for performance reasons, which does not change the nominal file size.

Actually allocating zeroes sounds like it could be quite inefficient and confusing, but then again, fallocate is not portable POSIX.

> Or if it were a hardware ordering fault

That's what I suspect might be going on here.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by colanderman on Saturday November 25, 2023 @12:30AM (#38411449)
fseek to the (new) end and back. Avoids metadata updates on every write. Not sure how common it is but it does occur.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by fulafel on Wednesday November 22, 2023 @10:28AM (#38380531)
I think there could semi-reasonably be case for the zero bytes appearing if the fs knows there should be something written there, and the block is has been allocated, but no write yet. Then it's not compromising confidentiality to zero the allocated block when recovering the journal when the disk is mounted. But the zero byte origin doesn't seem to be spelled out anywhere so this is just off the cuff reasoning.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by bugfix on Tuesday November 21, 2023 @11:35PM (#38374760)
I had this exact experience with my workstation SSD (NTFS) after a short power loss while NPM was running. After I turned the computer back on, several files (package.json, package-lock.json and many others inside node_modules) had the correct size on disk but were filled with zeros.

I think the last time I had corrupted files after a power loss was in a FAT32 disk on Win98, but you'd usually get garbage data, not all zeros.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by wannacboatmovie on Tuesday November 21, 2023 @11:50PM (#38374853)
They may be pointing to unallocated space which on a SSD running TRIM would return all zeros. NTFS is an extremely resilient yet boring filesystem, I cannot remember the last time I had to run chkdsk even after an improper shutdown.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Sakos on Wednesday November 22, 2023 @04:48AM (#38377149)
As somebody who worked as a PC technician for a while until very recently, I've run chkdsk and had to repair errors on NTFS filesystems very, very, very often. It's almost an everyday thing. Anecdotal evidence is less than useful here.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by dspillett on Wednesday November 22, 2023 @05:13AM (#38377335)
So anecdotal evidence is not useful, as proven by your anecdotal evidence? :)

FWIW I've found NTFS and ext3/4 to be of similar reliability over the years, in general use and in the face of improper shutdown. Metadata journaling does a lot to preserve the filesystem in such circumstances. Most of the few significant problems I've had have been due to hardware issues, which few filesystems on their own will help you with.

It is worth noting that when you run tools like chkdsk or fsck, some of the issues reported and fixed are not data damaging, or structurally dangerous, or at least not immediately so. For instance free areas marked in such a way that makes them look used to the allocation algorithms.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by Sakos on Wednesday November 22, 2023 @05:46AM (#38377537)
There's a difference between your personal experience and my experience in a professional role handling multiple customer devices every day.

However, I'm also not making a statement about NTFS's reliability vs ext3/ext4. In the years that I worked in that position, I maybe dealt with Linux systems 3 times.

Reminder of the original statement:

> NTFS is an extremely resilient yet boring filesystem, I cannot remember the last time I had to run chkdsk even after an improper shutdown.

I never said anything about catastrophic failure of an NTFS filesystem. I have experienced that, but it was comparatively rare (still happened though). I have, however, have had to run chkdsk fairly often to correct errors. Sometimes user data was affected to some degree, but it was often a matter of system stability and getting Windows back to running without issues.

I still find that NTFS is reasonably resilient and have no qualms with it. I just want to push back against the idea that nothing ever goes wrong with NTFS, which was implied by your statement that you can't remember the last time you used chkdsk.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by dspillett on Wednesday November 22, 2023 @06:09AM (#38377694)
> not making a statement about NTFS's reliability vs ext3/ext4

I should have been a bit clearer there: I only mentioned those specific filesystems because those are the ones I have a lot of experience with, rather than intending to bang the drum for them (or one in favour of the other). I expect other much-tested journaled filesystems could be substituted into the same sentences.

> your original statement

GPP was not me.

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by dspillett on Wednesday November 22, 2023 @05:02AM (#38377236)
> but you'd usually get garbage data, not all zeros.

You are less likely to get garbage with an SSD in combination with a modern filesystem because of TRIM. Even if the SSD has not (yet) wiped the data, it knows that a block that is marked as unused can be retuned as a block of 0s without needing to check what is currently stored for that block.

Traditional drives had no such facility to have blocks marked as unused from their PoV, so they always performed the read and returned what they found which was most likely junk (old data from deleted files that would make sense in another context) though could also be a block of zeros (because that block hadn't been used since the drive had a full format or someone zeroed free-space).

Re:I tested four NVMe SSDs from four vendors – half lose FLU... by matja on Wednesday November 22, 2023 @05:00AM (#38377215)
Journaling filesystems (including NTFS, and ext3/ext4 using default mount options) typically only track file structure metadata in the journal, so that is WAI - the filesystem structure was not corrupted, but all bets are off when it comes to the contents of the files.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by chrismorgan on Wednesday November 22, 2023 @05:10AM (#38377295)
I lost Audacity projects due to BSODs on a Surface Book several times in ~2019: the *_data/**.au files were intact, each containing just a few seconds of audio; but the .aup XML file that maps them and contains whatever else makes up the project was all zeroed. My memory’s fuzzy, but I think it was something like exit sometimes triggering the BSOD, and save-on-exit corrupting consistently if it BSODed, and so the workaround was to remember to save first, and then if it BSODs you’re OK.
Re:I tested four NVMe SSDs from four vendors – half lose FLU... by agbrrw on Wednesday November 22, 2023 @05:20AM (#38377380)
>experience data corruption on crash / power loss

You mean on complete system crash, right? Your application crashing shouldn't lead to files being fulls of zeroes as long as you've already written everything out.