by josephg · 3y ago · 0 comments
Another simpler way to improve the filesystem API would be to add a write barrier system call. If I call write(file, a); barrier(file); write(file, b); then the OS guarantees that the second write can't start before the first write is fully committed to disk. This is enough to implement most journaling systems, databases and log files.
This would perform much better than the current POSIX API because you don't need to "stop the world" with an expensive fsync before issuing subsequent write commands. The kernel can buffer chunks of writes separated by barriers, and issue them to the underlying device as needed.
The completion API is nicer though, because you can (for example), not respond to a network request to update the database until the changes are flushed to disk.
The underlying SCSI and SATA protocols would support this with command queueing. I would have envisioned using an fcntl() to set the current group ID on an fd.
I wonder what it would take to actually implement this stuff in linux. A lot of work, sure - but far from impossible.
Thanks for lmdb btw! The design is lovely. I've used it in a couple projects, and I had a read through your code for inspiration while I was designing out a little storage engine for something I've been working on. Its delightful.
Thanks, that's great feedback! Happy to hear that you're both using it successfully and that you actually read the code and learned from it.
The POSIX requirements were made in and for a different world.
For example they also completely break down for distributed network filesystems. (Or at least destroy your hope of performance.)