UNIX 文件系统家族
UNIX 文件系统家族
UNIX 文件系统家族
想要一个更好的文件系统?
观察一些文件系统的统计数据
Most files are small: ~2K is the most common size
Average file size is growing: ~200K is the average
Most bytes are stored in large files: A few big files use most space
File systems contains lots of files: ~100K on average
File systems are roughly half full: Even as disks grow, file systems remain ~50% full
Directories are typically small: Many have few entries; most have 20 or fewer
UNIX 文件系统家族
UNIX 系列文件系统的改进
支持 (硬) 链接
树
→
\to
→
图 (链接)
允许一个 “虚拟磁盘” 存在多份引用
struct node (数据), struct edge (目录中的文件) 要分开
支持任意大小文件的随机访问
小文件
~2K is the most common size
大文件
A few big files use most space: 数据库、视频、……
UNIX 文件系统家族
所以我们需要 struct node
“iNode” (index node)
保存 ls -l 里的各种 metadata
Mode, Links, User/Group, Size, Access/Modify/Change Time
(Minix1 和 Minix2 的 fs/inode.h 完全一样)
是的,fstat 就直接把数据搬到进程里
以及一个用于索引的数据结构
map<int,int> (file offset
→
\to
→
block id)
UNIX 文件系统家族
ext2: 不过是另一个数据结构
“Superblock”:文件系统级的元数据
inode 数量,block_per_block (以第一个 superblock 为准), ...
UNIX 文件系统家族
ext2 inode: 联合数据结构 (Fast/Slow Path)
UNIX 文件系统家族
ext2 目录文件
在 “文件”上的数据结构
map<string,int> (name
→
\to
→
inode)
UNIX 文件系统家族
ext2: 性能与可靠性
局部性与缓存
bitmap, inode 都有 “集中存储” 的局部性
通过内存缓存减少读/写放大
大文件
O
(
1
)
O(1)
O
(
1
)
随机读写
支持链接 (一定程度减少空间浪费)
inode 在磁盘上连续存储,便于缓存/预取
依然有碎片的问题
但可靠性依然是个很大的问题
存储 inode 的数据块损坏是很严重的