Β§41.4–41.6FFS Policies, Locality, and the Large-File Exception

Part III OSTEP pp. 515–519 Β· ~7 min read

  • allocation policy
  • namespace locality
  • large-file exception

With the group structure in place, FFS needs an allocation policy : rules for where to put inodes and data. The mantra is simple β€” keep related stuff together (and unrelated stuff apart).

41.4 Policies: Placing Files and Directories

FFS uses a few common-sense heuristics. Directories go in a group with few existing directories (to spread them out) and many free inodes (so its files can be allocated nearby). Files follow two rules: put a file’s data blocks in the same group as its inode (no more inodeβ†’data seek), and put files from the same directory in the same group. Watch it against a naive alternative:

FFS places files from the same directory in the same group. Files: /a/c, /a/d, /a/e (blue-green) and /b/f (green). Compare FFS's locality-aware policy with a naive spread-inodes policy.
inodesdataG0//G1acdeaccddeeG2bfbffc, d, e all in Group 1 β€” namespace locality preserved

1FFS policy: keep a directory's files together

The root / is in Group 0. Directory /a and ALL its files (c, d, e) go in Group 1 β€” so their inodes and data sit together. Directory /b and its file f go in Group 2. Accessing /a/c then /a/d then /a/e stays within one group: short seeks.

step 1 / 2

41.5 Measuring Locality

Does directory-based grouping actually match how files are used? The namespace locality in real traces (SEER) says yes: measure the directory-tree distance between consecutive file accesses (0 = same file, 1 = same directory, 2 = shared grandparent…), and about 40% of accesses are at distance 0 or 1 β€” exactly what FFS optimizes:

Namespace locality in the SEER traces (Figure 41.1): how far apart, in the directory tree, consecutive file accesses were.
tree distancefrequency (Trace)meaning
00~7%the very same file re-opened
0-10 or 1~40% (cumulative)same file, or a sibling in the same directory
22+~25%shared grandparent directory
randomRandom baselinemuch lessrandomly ordered accesses β€” some locality only because all files share the root
Dotted-underlined cells have explanations β€” click one.

Notably, a big chunk of accesses are at distance 2 (jumping between sibling directories like src and obj) β€” locality FFS’s one-level policy does not capture.

41.6 The Large-File Exception

There’s one problem with β€œkeep a file’s blocks in its group”: a large file would fill an entire group, leaving no room for the related small files that also want to live there. So FFS makes the large-file exception :

The large-file exception: without it, one big file monopolizes a group; with it, the file spills across groups so related small files still fit.
G030 of 40 blocks (/a)G1G2G3G4G5G6/a hogs Group 0

1Without the exception

File /a is 30 blocks; groups hold 40 data blocks each. Placing all of /a in Group 0 fills it almost entirely β€” leaving no room for other files related to / (which also wants Group 0).

step 1 / 2

Spreading a file across groups obviously hurts sequential reads β€” but amortization rescues it: if each chunk is big enough, you spend most of your time transferring and little time seeking between chunks. With a 40 MB/s disk and 10 ms average positioning, the chunk needed for 50% of peak bandwidth is:

40 MBsΓ—1024 KBMBΓ—1 s1000 msΓ—10 ms=409.6 KB40\,\frac{\text{MB}}{\text{s}} \times \frac{1024\,\text{KB}}{\text{MB}} \times \frac{1\,\text{s}}{1000\,\text{ms}} \times 10\,\text{ms} = 409.6\,\text{KB}

Push for higher bandwidth and the chunk grows fast:

Amortization: how big a chunk must be to hit a target fraction of peak bandwidth (40 MB/s disk, 10 ms average positioning).
target bandwidthchunk size needed
5050% of peak409.6 KB
9090% of peak3.69 MB
9999% of peak40.6 MB
Dotted-underlined cells have explanations β€” click one.

FFS itself used a simpler rule tied to the inode: the first 12 (direct) blocks go in the inode’s group, and each indirect block’s worth of data (1024 blocks = 4 MB) goes in a different group.

Check yourself: FFS policies and the large-file exception

1.What is FFS's core allocation-policy mantra?

2.Under FFS, where do files /a/c, /a/d, and /a/e end up, and why does that help?

3.What did the SEER traces reveal about namespace locality?

4.Why does FFS make an exception for large files?

5.Spreading a large file across groups hurts sequential reads. How does FFS keep performance acceptable?

6.As you target a higher fraction of peak bandwidth, what happens to the required chunk size, and why does this matter over time?

6 questions