Writing to Disk Sequentially
Let's see how to turn all writes into sequential writes for LFS.
We thus have our first challenge: how do we transform all updates to the file-system state into a series of sequential writes to disk? To understand this better, let’s use a simple example. Imagine we are writing a data block to a file. Writing the data block to disk might result in the following on-disk layout, with written at disk address :
However, when a user writes a data block, it is not only data that gets written to disk; there is also other metadata that needs to be updated. In this case, let’s also write the inode (I) of the file to disk, and have it point to the data block D. When written to disk, the data block and inode would look something like this (note that the inode looks as big as the data block, which generally isn’t the case; in most systems, data blocks are 4 KB in size, whereas an inode is much smaller, around 128 bytes):
This basic idea, of simply writing all updates (such as data blocks, inodes, etc.) to the disk sequentially, sits at the heart of LFS. If you understand this, you get the basic idea. But as with all complicated systems, the devil is in the details.
Get hands-on with 1400+ tech skills courses.