Slashdot Mirror


Apps That Rely On Ext3's Commit Interval May Lose Data In Ext4

cooper writes "Heise Open posted news about a bug report for the upcoming Ubuntu 9.04 (Jaunty Jackalope) which describes a massive data loss problem when using Ext4 (German version): A crash occurring shortly after the KDE 4 desktop files had been loaded results in the loss of all of the data that had been created, including many KDE configuration files." The article mentions that similar losses can come from some other modern filesystems, too. Update: 03/11 21:30 GMT by T : Headline clarified to dispel the impression that this was a fault in Ext4.

27 of 830 comments (clear)

  1. Not a bug by casualsax3 · · Score: 5, Informative
    It's a consequence of not writing software properly. Relevant links later in the same comment thread for those who don't might otherwise miss them:

    https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/45

    https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/54

    1. Re:Not a bug by mbkennel · · Score: 5, Insightful

      I disagree. "Writing software properly" apparently means taking on a huge burden for simple operations.

      Quoting T'so:

      "The final solution, is we need properly written applications and desktop libraries. The proper way of doing this sort of thing is not to have hundreds of tiny files in private ~/.gnome2* and ~/.kde2* directories. Instead, the answer is to use a proper small database like sqllite for application registries, but fixed up so that it allocates and releases space for its database in chunks, and that it uses fdatawrite() instead of fsync() to guarantee that data is written on disk. If sqllite had been properly written so that it grabbed new space for its database storage in chunks of 16k or 64k, and released space when it was no longer needed in similar large chunks via truncate(), and if it used fdatasync() instead of fsync(), the performance problems with FireFox 3 wouldn't have taken place."

      In other words, if the programmer took on the burden of tons of work and complexity in order to replicate lots of the functionality of the file system and make it not the file system's problem, then it wouldn't be my problem.

      I personally think it should be perfectly OK to read and write hundreds of tiny files. Even thousands.

      File systems are nice. That's what Unix is about.

      I don't think programmers ought to be required to treat them like a pouty flake: "in some cases, depending on the whims of the kernel and entirely invisible moods, or the way the disk is mounted that you have no control over, stuff might or might not work."

    2. Re:Not a bug by Qzukk · · Score: 5, Interesting

      I personally think it should be perfectly OK to read and write hundreds of tiny files. Even thousands.

      It is perfectly OK to read and write thousands of tiny files. Unless the system is going to crash while you're doing it and you somehow want the magic computer fairy to make sure that the files are still there when you reboot it. In that case, you're going to have to always write every single block out to the disk, and slow everything else down to make sure no process gets an "unreasonable" expectation that their is safe until the drive catches up.

      Fortunately his patches will include an option to turn the magic computer fairy off.

      --
      If I have been able to see further than others, it is because I bought a pair of binoculars.
    3. Re:Not a bug by Anonymous Coward · · Score: 5, Informative

      Quoting T'so:

      "The final solution, is we need properly written applications and desktop libraries. The proper way of doing this sort of thing is not to have hundreds of tiny files in private ~/.gnome2* and ~/.kde2* directories. Instead, the answer is to use a proper small database like sqllite for application registries, but fixed up so that it allocates and releases space for its database in chunks, ...

      Linux reinvents windows registry?
      Who knows what they will come up with next.

    4. Re:Not a bug by Logic+and+Reason · · Score: 5, Insightful

      I personally think it should be perfectly OK to read and write hundreds of tiny files. Even thousands.

      To paraphrase https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/54 : You certainly can use tons of tiny files, but if you want to guarantee your data will still be there after a crash, you need to use fsync. And if that causes performance problems, then perhaps you should rethink how your application is doing things.

    5. Re:Not a bug by msuarezalvarez · · Score: 5, Insightful

      As an application developer, the last thing I want to worry about is whether or not the fraking filesystem is going to persist my data to disk.

      As an application developer, you are expected to know what the API does, in order to use it correctly. What Ext4 is doing is 100% respectful of the spec.

    6. Re:Not a bug by davecb · · Score: 5, Insightful

      It seems exceedingly odd that issuing a write for a non-zero-sized file and having it delayed causes the file to become zero-size before the new data is written.

      Generally when one is trying to maintain correctness one allocates space, places the data into it and only then links the space into place (paraphrased from from Barry Dwyer's "One more time - how to update a master file", Communications of the ACM, January 1981).

      I'd be inclined to delay the metadata update until after the data was written, as Mr. Tso notes was done in ext3. That's certainly what I did back in the days of CP/M, writing DSA-formated floppies (;-))

      --dave

      --
      davecb@spamcop.net
    7. Re:Not a bug by OeLeWaPpErKe · · Score: 5, Informative

      Let's not forget that the only consequence of delayed allocation is the write-out delay changing. Instead of data being "guaranteed" on disk in 5 seconds, that becomes 60 seconds.

      Oh dear God, someone inform the president ! Data that is NEVER guaranteed to be on disk according to spec is only guaranteed on disk after 60 seconds.

      You should not write your application to depend on filesystem-specific behavior. You should write them to the standard, and that means fsync(). No call to fsync, look it up in the documentation (man 2 write).

      The rest of what Ted T'so is saying is optimization, speeding up the boot time for gnome/kde, it is not necessary for correct workings.

      Please don't FUD.

      You know I'll look up the docs for you :

      (quote from man 2 write)

      NOTES
                    A successful return from write() does not make any guarantee that data has been committed to disk. In fact, on some buggy implementations, it does not even guarantee
                    that space has successfully been reserved for the data. The only way to be sure is to call fsync(2) after you are done writing all your data.

                    If a write() is interrupted by a signal handler before any bytes are written, then the call fails with the error EINTR; if it is interrupted after at least one byte has
                    been written, the call succeeds, and returns the number of bytes written.

      That brings up another point, almost nobody is ready for the second remark either (write might return after a partial write, necessitating a second call)

      So the normal case for a "reliable write" would be this code :

      size_t written = 0;
      int r = write(fd, &data, sizeof(data))
      while (r >= 0 && r + written sizeof(data)) {
              written += r;
              r = write(fd, &data, sizeof(data));
      }
      if (r 0) { // error handling code, at the very least looking at EIO, ENOSPC and EPIPE for network sockets
      }

      and *NOT*

      write(fd, data, sizeof(data)); // will probably work

      Just because programmers continuously use the second method (just check a few sf.net projects) doesn't make it the right method (and as there is *NO* way to fix write to make that call reliable in all cases you're going to have to shut up about it eventually)

      Hell, even firefox doesn't check for either EIO or ENOSPC and certainly doesn't handle either of them gracefully, at least not for downloads.

    8. Re:Not a bug by Profane+MuthaFucka · · Score: 5, Funny

      That would be smart, but only if the SQL database is encrypted too. It's theoretically possible to read a registry with an editor, and we can't have that. Also, we need a checksum on the registry. If the checksum is bad, we have to overwrite the registry with zeroes. Registries are monolithic, and we have to make sure that either it's good data, or NONE of it is good data. Otherwise the user would get confused.

      I am so excited about this that I'm going to start working on it just as soon as I get done rewriting all my userspace tools in TCL.

      --
      Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
  2. Don't worry by sakdoctor · · Score: 5, Funny

    Don't worry guys, I read the summary this time, and it only affects the German version of ext4.

  3. pr0n by Quintilian · · Score: 5, Funny

    Real reason for the bug report: Someone's angry and wants his porn back.

  4. Works as expected... by gweihir · · Score: 5, Insightful

    The problem here is that delaying writes speeds up things greatly but has this possible side-effect. For a shorter commit time, simply stay with ext3. You can also mount your filesystems "sync" for a dramatic performance hit, but no write delay at all.

    Anyways, with moderen filesystems data does not go to disk immediately, unless you take additional measures, like a call to fsync. This should be well known to anybody that develops software and is really not a surprise. It has been done like that on server OSes for a very long time. Also note that there is no loss of data older than the write delay period and this only happens on a system crash or power-failure.

    Bottom line: Nothing to see here, except a few people that do not understand technology and are now complaining that their expectations are not met.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    1. Re:Works as expected... by girlintraining · · Score: 5, Insightful

      Nothing to see here, except a few people that do not understand technology and are now complaining that their expectations are not met.

      You're right, there really is nothing to see here. Or rather, there's nothing left. As the article says, a large number of configuration files are opened and written to as KDE starts up. If KDE crashes and takes the OS with it (as it apparently does), those configuration files may be truncated or deleted entirely -- the commands to re-create and write them having never been sync'd to disk. As the startup of KDE takes longer than the write delay, it's entirely possible for this to seriously screw with the user.

      The two problems are:

      1. Bad application development. Don't delete and then re-create the same file. Use atomic operations that ensure that files you are reading/writing to/from will always be consistent. This can't be done by the Operating System, whatever the four color glossy told you.

      2. Bad Operating System development. If an application kills the kernel, it's usually the kernel's fault (drivers and other code operating in priviledged space is obviously not the kernel's fault) -- and this appears to be a crash initiated from code running in user space. Bad kernel, no cookie for you.

      --
      #fuckbeta #iamslashdot #dicemustdie
  5. Classic tradeoff by Otterley · · Score: 5, Insightful

    It's amazing how fast a filesystem can be if it makes no guarantees that your data will actually be on disk when the application writes it.

    Anyone who assumes modern filesystems are synchronous by default is deluded. If you need to guarantee your data is actually on disk, open the file with O_SYNC semantics. Otherwise, you take your chances.

    Moreover, there's no assertion that the filesystem was corrupt as a result of the crash. That would be a far more serious concern.

  6. Re:Exactly by TerranFury · · Score: 5, Insightful

    Meh, this is crap that happens only when the system crashes, and is pretty much unavoidable if you're doing a lot of caching in memory -- which, coincidentally, is what you need to do to maximize performance. This doesn't sound like the filesystem's "fault" or the application's "fault;" it's just the way things are. Everybody knows that if you don't cleanly unmount, most bets are off.

  7. Re:Exactly by gweihir · · Score: 5, Insightful

    The problem is not the many small files, but the missing disk sync. The many small files just make the issue more pbvous.

    True, with ext4 this is more likely to cause problems, but any delayed write can cause this type of issue when no explicit flush-to-disk is done. And lets face it: fsync/fdatasync are not really a secret to any competent developer.

    What however is a mistake, and a bad one, is making ext4 the default filesystem at this time. I say give it another half year, for exactly this type of problem.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  8. Re:Bull by Lord+Ender · · Score: 5, Funny

    In fact, there is no such thing as an OS bug! All good programmers should re-implement essential and basic operating system features in their user applications whenever they run into so-called "OS bugs." If you question this, you must be a bad programmer, obviously.

    --
    A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
  9. Re:Bull by wild_berry · · Score: 5, Insightful

    The journal isn't being written before the data. Nothing is written for periods between 45-120 seconds so as to batch up the writing to efficient lumps. The journal is there to make sure that the data on disk makes sense if a crash occurs.

    If your system crashes after a write hasn't hit the disk, you lose either way. Ext3 was set to write at most 5 seconds later. Ext4 is looser than that, but with associated performance benefits.

  10. Re:Bull by Anonymous Coward · · Score: 5, Informative

    This is NOT a bug. Read the POSIX documents.

    Filesystem metadata and file contents is NOT required to be synchronous and a sync is needed to ensure they are syncronised.

    It's just down to retarded programmers who assume they can truncate/rename files and any data pending writes will magically meet up a-la ext3 (which has a mount option which does not sync automatically btw).

    RTFPS (Read The Fine POSIX Spec).

  11. Re:Bull by pc486 · · Score: 5, Informative

    Ext3 doesn't write out immediately either. If the system crashes within the commit interval, you'll lose whatever data was written during that interval. That's only 5 seconds of data if you're lucky, much more data if you're unlucky. Ext4 simply made that commit interval and backend behavior different than what applications were expecting.

    All modern fs drivers, including ext3 and NTFS, do not write immediately to disk. If they did then system performance would really slow down to almost unbearable speeds (only about 100 syncs/sec on standard consumer magnetic drives). And sometimes the sync call will not occur since some hardware fakes syncs (RAID controllers often do this).

    POSIX doesn't define flushing behavior when writing and closing files. If your applications needs data to be in NV memory, use fsync. If it doesn't care, good. If it does care and it doesn't sync, it's a bad application and is flawed, plain and simple.

  12. Re:Theory doesn't matter; practice does by caerwyn · · Score: 5, Insightful

    This is the attitude that has the web stuck with IE.

    There's a standard out there called POSIX. It's just like an HTML or CSS standard. If everyone pays attention to it, everything works better. If you fail to pay attention to it for your bit (writing files or writing web pages), it's not *my* fault if my conforming implementation (implementing the writing or the rendering) doesn't magically fix your bugs.

    --
    The ringing of the division bell has begun... -PF
  13. Re:Bull by Anonymous Coward · · Score: 5, Insightful

    Bullshit. It is not a filesystem limitation. POSIX tells you what you can expect from file system calls. Data committed to disk as soon as an fwrite or fclose returns is not something you can or should expect. (And this is true of every OS I've used in the last 20 years.)

    A great many crap programmers think APIs ought to do what they'd like them to. But APIs don't. At best they do what they are specified to do.

  14. man 2 fsync by Nicolas+MONNET · · Score: 5, Informative

    The filesystem doesn't guarantee anything is written until you've called fsync and it has returned.

  15. Re:Bull by Anonymous Coward · · Score: 5, Insightful

    Does anyone else think that 150 second is a bit over the top in terms of writing to disk?

    I could understand one or two seconds as you speculate more data might come that needs to be written.

    5 seconds is a bit iffy, as with ext3.

    150 seconds? That's surely a bug.

  16. Re:Excuses are false. This is a severe flaw. by Tadu · · Score: 5, Informative

    KDE is *broken* to delete a file and expect it to still be there if it crashes before the write.

    Nope, it writes a new file and then renames it over the old file, as rename() says it is an atomic operation - you either have the old file or the new file. What happens with ext4 is that you get the new file except for its data. While that may be correct from a POSIX lawyer pont of view, it is still heavily undesirable.

  17. Re:Bull by BikeHelmet · · Score: 5, Insightful

    Ahh yes, I love developers like you. You assume your app is the only one running, and it must have full access to the entire IO bandwidth an HDD can provide.

    And then an antivirus program updates while Firefox is starting and a video is transcoding, and your program either slows to a crawl or crashes after 30 seconds of not receiving or being able to write any data.

    Recently I was playing Left4Dead when one of my HDDs in my RAID array died in a very audible way. All the drives spun down, then 3 of them came back online. IOPS went to zero for over 60 seconds. No data in or out to those devices!

    Interestingly, Ventrilo kept running fine. Left4Dead completely froze, but a minute or so after the 3 drives came back online, it unfroze. (CPU catching up?) All the while I was freaking out on Ventrilo, much to my friends' amusement.

    Pretty much everything else crashed, except for Portable Firefox... uTorrent crashed, but first it left corrupted files all over - appearing as undeletable folders, which require a format to remove.

    Time for a disk wipe. Thank you, shitty developers! Next time, use the API properly, and if you must have it written to disk, sync it immediately after you write!

  18. Re:Bull by vadim_t · · Score: 5, Insightful

    It's not going to happen immediately in any case. Some optimizations can only be done if you introduce a delay, and once introduced you have to deal with that there's a delay. Just because it's one second instead of a minute doesn't mean your computer can't crash in the precisely wrong moment.

    While I'm not an expert in filesystems, I'd expect writing a single file to be at least 4 writes: inode, data, update the directory the file is in, and a bitmap to show space allocation. If there's a journal add a write for the journal. Each of those will require a seek due to all of these things being in different places on the disk in most filesystems.

    So your 40 small files just turned into 400-500 seeks, which at 8ms each will take 1.6 to 2 seconds to complete.

    Now let's suppose we can batch things up. We need to write the inode and data for each file, and can do just one seek for the directory (the same for all), and the bitmap and journal can be updated in one operation. Now we're down to 2 writes per file, giving 80 seeks, plus 3 for metadata, giving 83 seeks, which can be done in 0.6 seconds.

    But what if we do delayed allocation and create the all the inodes and write all the data as one large contigous area? We're now down to 5 writes total, with a seek time of 40ms. The time needed to write the data can probably be disregarded, since modern disks easily write at 50MB/s, and those 40 files with metatata probably amount to less than 32K.

    And with some optimization, we just reduced the time it takes to write your 40 files to just 2% of the unoptimized time.

    You're not going to get this sort of improvement without some sort of delay. If you insist on a per-file write you'll get really, really awful performance on the sort of workload you're using as an example. And you can even see it in practice, just boot a DOS box, and do benchmarks with and without smartdrv. Running something like a virus scanner should show a huge difference in the presence of a cache.