4 ms·
Isnt the point of the article that these file systems are trying to implement something like this, with journals and write logs, and such as implementation deta
by simonh 6y ago
Isnt the point of the article that these file systems are trying to implement something like this, with journals and write logs, and such as implementation details, but these have failure modes and bugs that mean these mechanisms can still give unexpected results. Its like saying, well software just shouldnt have bugs or be vulnerable to side effects.
Of course it is possible to mitigate these issues more than most file systems do, but at the cost of reduced space or performance efficiency. Thats what using a further abstraction like SQLite buys you, but its not for free. Thats why all the FS as database efforts in the early 2000s like Longhorn failed.
- josephg 6y agoThe point of the article is how if you want the filesystem API to write data safely, you need to jump through a lot of hoops. (Which, spoilers: most developers don't do. And even developers who try really hard often get it wrong because the APIs are so awful and poorly documented. Hence the ever present spectre of data corruption.) According to the article, if I use ext4 with journaling and have a file with "a foo" and write "bar" at position 2, possible resulting states are: "a foo", "a boo", "a bao" or "a bar". This is the best scenario - without journaling, I can also end up with uninitialized junk. The authors of the filesystem APIs consider this to be correct behaviour. But I can't think of any use case for this nonsense behaviour. Real data, in every file on your computer is structured. And structured files simply can't handle this kind of data corruption. Maybe this API has slightly higher throughput, but by the time you've peppered your code with fsync() calls to make it correct, you've killed performance. And working around that takes whole philosophies of threading and thousands of lines of code. I want that write call to either complete completely or fail completely. Actually, I want more than that - for a bunch of successive write calls touching multiple files to collectively succeed together or fail together. Which is not what the article is saying. > Its like saying, well software just shouldnt have bugs The kernel shouldn't have bugs in its filesystem. We don't tolerate bugs in the scheduler, or in OpenSSL or in the CPU. If Postgres randomly corrupted its database every month or two, we would fix the bug. Or call it broken and use something else. If SQLite can implement transactions on top of the current filesystem APIs, then obviously its possible to put that behaviour in the kernel. And in the kernel, that code would be easier to optimize, and would be useful everywhere. If it was a simple bug, we would fix it. The problem is that the bug is that we have the wrong abstraction. Why do we have the current filesystem API? The story I heard is it was written by some intern at Berkeley decades ago who thought it would be neat to have files and network streams use the same API. We know more now, and its past time to fix the mistake. > Thats why all the FS as database efforts in the early 2000s like Longhorn failed. I don't buy the cynicism. Just because microsoft overengineered longhorn (and successfully shipped TxF btw), doesn't mean the problem is unsolvable.
- BlueTemplar 6y agoAbstraction has a cost, and there are no guarantees that if implemented, the resulting performance would be considered acceptable. (It's even possible that many have already tried, and failed.) Of course this doesn't mean that we shouldn't try again and again. But we also have to realize that even if we're successful, this doesn't mean that the solution won't be left completely forgotten, as long as 'good enough' systems exist. (See the other threads for examples.)
- josephg 6y agoThats fine. Disks are so fast now that I would trade away 50% of the filesystem's performance for correctness in 95% of the software I use. (Eg my code editor, git, compiler, etc). Except I bet in a good implementation the actual performance cost of transactions would be negligible anyway. Especially on top of something like ZFS. And legacy software can just keep using the current unreliable APIs with all the performance that entails anyway.
- the8472 6y ago> According to the article, if I use ext4 with journaling and have a file with "a foo" and write "bar" at position 2, possible resulting states are: "a foo", "a boo", "a bao" or "a bar". It makes a lot more sense if you consider it shared, concurrently accessed memory. If you try to access it without atomics you can get funny results. And if you kill one process in the middle you might be stuck with reordered accesses indefinitely. Something like ext4 provides more than that. If you want ACID then you'll have to opt into that. The same as you have to do with concurrent programming (e.g. via std::atomic). But there are many cases where none of this is needed, where all you need is a bag to hold a few bytes for a while. E.g. cache files or large media blobs. The only issue is ubiquity of the necessary tooling, or the lack thereof. Many standard libraries now ship with concurrency-safe data structures while you often have to reach for 3rd-party libraries for safe file abstractions if you don't want to code your own. > If SQLite can implement transactions on top of the current filesystem APIs, then obviously its possible to put that behaviour in the kernel. If userspace can already implement it (when needed) based on provided kernel primitives, why should the kernel maintain two APIs side by side? Userspace needs many different levels of granularity. Sometimes integrity doesn't matter at all. Sometimes it only matters that writes make it to disk in correct order but it's ok for the last ones to get lost. And sometimes you need multiple processes memory-mapping a file and doing shared byte-level access and only random byte-ranges need to be committed to storage at any given time.