Β§43.4–43.8Finding Inodes: The Inode Map and Checkpoint Region

Part III OSTEP pp. 551–554 Β· ~7 min read

  • inode map
  • checkpoint region
  • recursive update problem

LFS writes everything sequentially β€” which creates a new problem: where did the inodes go?

43.4 The Problem: Finding Inodes

In FFS (or the old UNIX FS), inodes live in a fixed on-disk array, so you find one by simple arithmetic: address = start + inode_number Γ— inode_size. In LFS, that’s impossible β€” inodes are scattered all over the disk, and since LFS never overwrites in place, an inode’s newest version keeps moving with every update.

43.5 The Inode Map (imap)

The fix is the classic one: a level of indirection. The inode map (imap) maps an inode number to the disk address of that inode’s most recent version β€” a simple array with a 4-byte pointer per entry, updated whenever an inode is written. To avoid extra seeks, LFS doesn’t keep the imap at a fixed spot; it writes each imap chunk right next to the data and inode it describes, in the same segment.

Tip: Use A Level Of Indirection

As Wheeler said, β€œall problems in computer science can be solved by another level of indirection” (except too many indirections). Virtual memory, files, and here the imap β€” a virtualization of inode numbers β€” all let us move structures around freely without updating every reference. The cost is a bit of overhead; weigh it.

43.6–43.7 The Checkpoint Region, and Reading

But if imap pieces are also scattered, how do we find them? There has to be one fixed place to start. That’s the checkpoint region (CR) : a known location holding pointers to the latest imap pieces. Crucially, the CR is updated only periodically (~every 30 s), so it doesn’t add a seek to every write. Reading a file thus walks a chain of indirection:

Reading a file in LFS follows a chain of indirection from a single fixed point (the checkpoint region) down to the data. The green box is the current step.
CRfixed @ 0imapinode# β†’ addrinode kblock ptrsdatafile bytesthe CR is the only fixed starting point

1Start at the checkpoint region

With nothing in memory, LFS reads the checkpoint region β€” the one fixed, well-known location. It holds pointers to the latest pieces of the inode map.

step 1 / 4

43.8 What About Directories?

Directories work exactly as before β€” a directory is just a file whose data is a set of (name β†’ inode number) mappings β€” and it’s written into the log too. Looking up foo walks the imap twice (once for the directory, once for the file):

Directories are unchanged β€” just (name β†’ inode number) maps β€” and are written into the log too. Looking up /…/foo (inode k) walks the imap twice. (Green = the block being read.)
DkA0b0:A0I[k]A1(foo,k)DA2b0:A2dir IA3m[k]:A1m[dir]:A3imapA4

1The on-disk layout after creating foo

Creating file foo in a directory writes: foo's data (Dk), foo's inode I[k], the directory's data D (holding the entry (foo, k)), the directory inode, and an imap chunk mapping both inode k and the directory's inode.

step 1 / 4

The imap also quietly solves the recursive update problem : in any never-overwrite-in-place FS, moving an inode to a new address would force updating the directory that points to it β€” then that directory’s parent, and so on up to the root. LFS avoids the whole cascade because the directory stores only the inode number (unchanged); when the inode moves, only its imap entry is updated, not the directory.

Check yourself: inode map and checkpoint region

1.Why is finding an inode harder in LFS than in FFS?

2.What does the inode map (imap) do?

3.Where does LFS store the imap, and why?

4.If imap pieces are scattered too, how does LFS find them? And what keeps this cheap?

5.What is the chain of indirection to read a file in LFS?

6.How does the imap solve the recursive update problem?

6 questions