路径访问:读取

File Read Timeline (Time Increasing Downward)
File Read Timeline (Time Increasing Downward)
  • open() 获取文件标识符就需要 5 次 I/O
  • 每次 read() 读取一个数据块就需要 3 次 I/O
    • 向 inode 写入最近访问时间

路径访问:写入

File Creation Timeline (Time Increasing Downward)
File Creation Timeline (Time Increasing Downward)

(这张图有问题,第 8-9 行的 read,write 应该对应的是 foo inode,第 10 行的 write 应该对应的是 bar inode)

  • 创建就需要 10 次 I/O
    • 4 次读取沿着路径走
    • 2 次,读取并写入 i-bmap(找到空闲 inode 并标记使用)
    • 1 次读取文件夹的数据块更新名称到 inode 的映射
    • 2 次,读取并写入以更新文件夹的 inode
    • 1 次修改,初始化文件本身的 inode
  • 每次 write() 写入一个新数据块就需要 5 次 I/O

缓存与缓冲

庞大的 I/O 开销。

现代 OS 用物理内存缓存 (read cacheing) 读操作,缓冲 (write buffering) 写操作。

  • 缓存重要的块(inode 表,数据块等)
    • 静态 v.s. 动态分割 (static v.s. dynamic partitioning)
    • 将块缓存合入页缓存:统一页缓存 (unified page cache)
  • 缓冲写入
    • 将写入操作在内存中延迟,合并,取消甚至调度