Log-Structured File System (LFS)

CSCI 333 : Storage Systems

Spring 2021

Log-structured File Systems belong to a class of file systems called no-overwrite file systems. In an LFS, data is written out-of-place (in contrast with FFS’s in-place updates). The LFS design and on-disk layout attempts to convert all write operations into sequential I/O.

Unlike many computer science concepts, LFS is descriptively named: the log-structured file system writes data and metadata in an append-only fashion, essentially treating the disk as a circular log.

Learning Objectives

Trends/Realities that Influenced LFS Design

There were two dominant motivations for the introduction of LFS.

  1. RAM sizes were increasing:
  1. Random I/O had always been slow relative to sequential I/O, and the gap was ever growing

1-sentence Overview of the LFS Idea

Treat the disk as a circular log, and append all updates (data and metadata) to the end of that log.

Challenges:

  1. Metadata objects are often smaller than a disk block, so how can we aggregate as many metadata updates as possible into large I/Os?
  2. The disk size is limited, so we eventually reach the end of our log. When we “wrap around” our circular log, how do we ensure that:

Overview of Techniques

Questions:

  1. What are the advantages of using:
  1. How long should the system wait between writing checkpoints?

Garbage Collection

LFS data and metadata is written out-of-place, which means that updates result in older data becoming “stale”. When possible, garbage collection runs in the background to reclaim space consumed by stale data/metadata.

LFS performs garbage collection at the granularity of entire segments. The process of GC roughly proceeds as follows:

To simplify the process of identifying live data, each segment keeps additional metadata about the blocks written inside it. For each data block, the segment summary info contains:

Using this info, the segment cleaner can consult the current inode map to determine if the block is “live” or “stale” by comparing the inode’s data pointer to the LBA of the block. If they don’t match, the block can be cleaned.

Questions:

  1. Why does LFS try to prioritize garbage collecting cold segments over hot segments?
  2. How does segment size affect garbage collection?
  1. How often should garbage collection be run?
  1. Does LFS need a defragmenter like FFS?
  2. In what scenarios does garbage collection become foreground work? In other words, should the system every stop accepting new updates in order to prioritize garbage collection?
  3. How many free segments should LFS reserve for GC?

Consistency

File systems crash. Sometimes crashes are caused by software bugs, sometimes by a clumsy professor tripping on the power cord. Either way, it is important that the file system can recover to a consistent state. That is, some data may unfortunately be lost during the crash, but the state of the file system data structures should always represent some valid sequence of successful operations.

Questions:

  1. How many checkpoint blocks does LFS use, and why is the answer not “1”?
  2. How does LFS handle a crash in the middle of a checkpoint?
  3. LFS can crash in the middle of GC. When can LFS safely delete a GCed segment and reuse it in the system?

 

Comparing FS Designs

FFS is an update-in-place filesystem. LFS is a no-overwrite filesystem. Both classes of filesystems have different best and worst case workloads. Without considering long-term “aging”, think about the following “simple” reading and writing patterns.

  1. Suppose I write a very large file to each filesystem, and later update that file (this is not uncommon, consider a Virtual Machine Disk Image). How efficiently does each filesystem perform the following:
  1. Suppose I turn on my computer and read a file that I have already written (the cache is initially empty). How efficiently does each filesystem perform the following:
  1. Based on your answers to the above questions, is one file system clearly better than the other?
  2. There are two types of locality that often arise: temporal and spatial. Can you classify the file system types in terms of how they favor each type of locality?