f2fs study 笔记之二: SSA揭秘
作者:互联网
node inode
node: used to locate block;
inode: upper lawyer logical entity (file/directory)
block 和file name如何关联
计算出hash 值之后,根据 inode 去读对应的block:
这里除了比较hash值之外,还会比较file name,所以可以避免hash冲突。
hash 函数在 hash.c 里面: fs/f2fs/hash.c
- f2fs_dentry_block:
/ 4KB-sized directory entry block /
struct f2fs_dentry_block {
/ validity bitmap for directory entries in each block /
u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
u8 reserved[SIZE_OF_RESERVED];
struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
} __packed;
- f2fs_dir_entry
/ One directory entry slot representing F2FS_SLOT_LEN-sized file name /
struct f2fs_dir_entry {
le32 hash_code; / hash code of file name /
le32 ino; / inode number /
le16 name_len; / lengh of file name /
u8 file_type; / file type /
} __packed;
- NAT
struct f2fs_nat_entry {
u8 version; / latest version of cached nat entry /
le32 ino; / inode number /
__le32 block_addr; / block address /
} __packed;
hash 过程
struct f2fs_dir_entry f2fs_find_target_dentry(struct fscrypt_name fname,
f2fs_hash_t namehash, int max_slots,
struct f2fs_dentry_ptr d)
{
struct f2fs_dir_entry *de;
unsigned long bit_pos = 0;
int max_len = 0;
if (max_slots)
*max_slots = 0;
while (bit_pos < d->max) {
if (!test_bit_le(bit_pos, d->bitmap)) {
bit_pos++;
max_len++;
continue;
}
de = &d->dentry[bit_pos];
if (unlikely(!de->name_len)) {
bit_pos++;
continue;
}
if (**de->hash_code == namehash &&
fscrypt_match_name(fname, d->filename[bit_pos],
le16_to_cpu(de->name_len)))**
goto found;
if (max_slots && max_len > *max_slots)
*max_slots = max_len;
max_len = 0;
bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
}
- called in find_in_block()
called in find_in_level()
called in __f2fs_find_entry()
called by f2fs_add_regular_entry()
inode 和文件名、目录名如何关联
SSA 的主要作用
哪些类型的数据会用到SSA?
在IO路径上SSA 如何工作?
参考
标签:hash,f2fs,max,study,entry,SSA,block,name 来源: http://blog.51cto.com/xiamachao/2348758