F2FS: A New File System for Flash Storage

0x00 引言

SSD有种它自己的特点。Linux的Ext FS,XFS FS等主要还是为HHD设计,优化的出发点也是HHD的工作方式。而SSD的工作方式和HHD有着本质的不同. F2FS是Linux上的一个为SSD设计的FS,另外F2FS是一个Log Structured的FS(所以先看一下[2,3]),现在在很多的智能手机上已经使用了(苹果也号称它的新的APFS是为SSD优化设计的,不过找不到具体技术细节的东西)。

The detrimental effects of random writes could be reduced by the log-structured file system (LFS) approach and/or the copy-on-write strategy. For exam- ple, one might anticipate file systems like BTRFS and NILFS2 would perform well on NAND flash SSDs; unfortunately, they do not consider the charac- teristics of flash storage devices and are inevitably suboptimal in terms of performance and device lifetime.

0x01 基本思路

On-Disk Layout

F2FS将SSD分为固定程度的segment,连续的segment组成section,一些section 组成zone。F2FS分为6个区域:

  • Superblock: 初始化之后就不变的,文件系统的元数据;SB

  • Checkpoint:保存了文件系统状态,和LFS中的一样,也是2个轮流使用的;CP

  • Segment Information Table:segmemt相关的信息; SIT

  • Node Address Table :Node地址表;NAT

  • Segment Summary Area : 保存Main Area中block的信息; SSA

  • Main Area: 保存数据的地方。MA

     A node block con- tains inode or indices of data blocks, while a data block contains either directory or user file data.
    

结构图,这个图很清晰地表示了F2FS的结构:

看一看一个读文件的过程加深理解,假设读取“/dir/file” :

  1. 读取包含root的inode的block,这个位置信息在NAT中;
  2. 从root inode的块中,找到dir的目录项,得到dir的inode number;
  3. 通过NAT,根据dir的inode number找到物理位置;
  4. 读取dir对应的block;
  5. 在dir的block中找file的inode number,重复3,找到inode;
  6. 根据inode的信息读取file的数据,数据保存在MA中;

File Structure

​ 与LFS中的inode map不同,F2FS使用 “node”结构,每一个node有一个唯一的node id。使用这个id,NAT可以找到node block。node block可以表示inode,direct和direct node。

 An inode block contains a file’s metadata, such as file name, inode number, file size, atime and dtime. A direct node block contains block addresses of data and an indirect node block has node IDs locating another node blocks.

这里基本结构和常见的没有很多区别。也使用了一些常见的优化方法,比如小文件内联。这里要注意到与LFS不同的地方,LFS是尽可能的避免随机写,F2FS这里是存在一些随机写的(看上面的结构图),比如更新NAT。由于SSD随机写的性能远高于HHD,这个是合理的。

Directory Structure

没有什么特别的。可以说就是一个映射关系表而已。

In F2FS, a 4KB directory entry (“dentry”) block is composed of a bitmap and two arrays of slots and names in pairs. The bitmap tells whether each slot is valid or not. A slot carries a hash value, inode number, length of a file name and file type (e.g., normal file, directory and symbolic link). A directory file constructs multi-level hash tables to manage a large number of dentries efficiently.

0x02 Logging

Multi-head Logging

Logging当然是Log Structured的核心内容啦。与LFS使用”一个“log不同,F2FS使用了”多个”log。根据数据的“冷热”程度分为hot, warm and cold。

F2FS使用了一些方式来判断冷热程度。如上表所示。

Cleaning

Cleaning类似LFS中GC的过程,不够正对SSD做了一些优化。首先,以section粒度来进行cleaning。基本的思路和常见的比如LFS的相似:

  1. Victim selection。找到需要回收的section;

  2. Valid block identification and migration,移动存活的block;

  3. Post-cleaning process,只有在一个checkpoint之后,这个被回收的才真正被标记为空,可以被重新使用。

    After all valid blocks are migrated, a victim section is registered as a candidate to become a new free section (called a “pre-free” section in F2FS). After a checkpoint is made, the section finally becomes a free section, to be reallocated. We do this because if a pre-free section is reused before checkpointing, the file system may lose the data referenced by a previous checkpoint when unexpected power outage occurs.
    

Adaptive Logging

在 normal logging和threaded logging 2中logging策略中. 与LFS不同,F2FS根据系统状态选择不同的策略,这里考虑带了SSD相对较高的随机写性能:

if there are more than k clean sections, where k is a pre-defined threshold, normal logging is ini- tiated. Otherwise, threaded logging is activated. k is set to 5% of total sections by default and can be configured. ...
There is a chance that threaded logging incurs undesirable random writes when there are scattered holes. Nevertheless, such random writes typically show better spatial locality than those in update-in-place file systems, since all holes in a dirty segment are filled first before F2FS searches for more in other dirty segments.

0x03 Checkpointing and Recovery

这里与CP区域的关系比较大,在CP区域保存一下信息:

  • Header and footer,用途类似LFS中的时间戳;
  • NAT and SIT bitmaps,标记目前的NAT,SIT blocks;
  • NAT and SIT journals,保存最近更新的NAT SIT项,避免频繁更新NAT SIT;
  • Summary blocks of active segments,还没有写入SSA区域的SSA blocks;
  • Orphan blocks,如果一个inode在关闭之前被删除,它就被记录为孤儿inode(这个与linux中的文件操作相关,比如两个process同时操作一个文件,一个进程在另外一个关闭之前将这个文件删除了,那么只有到这个进程关闭之前才会将这个文件删除).

恢复:

After a sudden power-off, F2FS rolls back to the latest consistent checkpoint. In order to keep at least one stable checkpoint pack while creating a new pack, F2FS maintains two checkpoint packs. If a checkpoint pack has identical contents in the header and footer, F2FS considers it valid. Otherwise, it is dropped.

此外,F2FS也使用了常见的Roll-Forward Recovery 方式

F2FS implements an efficient roll-forward recovery mechanism to enhance fsync performance. The key idea is to write data blocks and their direct node blocks only, excluding other node or F2FS metadata blocks. In order to find the data blocks selectively after rolling back to the stable checkpoint, F2FS remains a special flag in- side direct node blocks.

参考

  1. F2FS: A New File System for Flash Storage, FAST’15.
  2. “Operating Systems: Three Easy Pieces“ (Chapter: Log-structured File Systems) by Remzi Arpaci-Dusseau and Andrea Arpaci-Dusseau. Arpaci-Dusseau Books, 2014.
  3. The Design and Implementation of a Log-Structured File System, TOCS 1992.

F2FS--针对SSD的文件系统相关推荐

  1. mysql ssd优化_针对 SSD 的 MySQL IO 优化

    现在数据库标配基本都是SSD了,在使用SSD之前,对SSD进行了充分的测试,这其中当然包括最为关键的性能测试部分.下面就跟大家分享一下在SSD性能测试过程中遇到的一个问题和解决问题的思路. 我们的性能 ...

  2. macunity日志目录_Mac升级10.13需谨慎,Unity不显示资源的解决办法

    原标题:Mac升级10.13需谨慎,Unity不显示资源的解决办法 前言: 上个月苹果开发者大会展示了ARkit,一批前沿开发者立马跟上尝鲜.Unity的ARkit插件马上随之而来.作者按捺不住激动的 ...

  3. 固态硬盘 linux 文件系统,SSD是否需要使用特别的文件系统?

    用认真的态度与专业的情怀倾注于存储,欢迎关注我,与我交流哦! 我们常用的电脑系统主要是Windows和Linux,其中,Windows系统中常用的文件系统主要是FAT和NFTS,FAT是旧Window ...

  4. SSD固态硬盘文件系统选择与性能优化

    最近由于工作需要,对ext3, ext4, reiserfs, reiser4, xfs, jfs, btrfs, nilfs2, logfs多种文件系统在SSD固态硬盘上的性能进行了全面的测试评估与 ...

  5. 镁光ssd管理工具 linux,在 SSD 上使用 Btrfs 文件系统的相关优化

    优化挂载参数 在 Linux 中挂载 SSD 上的 btrfs,可以采用各种参数进行优化: # UUID=/btrfs defaults,ssd,discard,noatime,compress=lz ...

  6. 在 SSD 上使用 btrfs 文件系统的相关优化

    优化挂载参数 在 Linux 中挂载 SSD 上的 btrfs,可以采用各种参数进行优化: # <file system> <mount point> <type> ...

  7. Linux文件系统基础(1)

    本文首发于http://oliveryang.net,转载时请包含原文或者作者网站链接. 1. 什么是文件系统 直接引用来自维基百科文件系统的定义, A file system is a set of ...

  8. Android性能优化--IO 优化( IO基本知识:应用程序、文件系统和磁盘,三种IO方式及适用场景,多线程阻塞IO和NIO)

    目录 I/O 的基本知识 1. 文件系统 2. 磁盘 Android I/O 1. Android 闪存 2. 两个疑问 疑问一:文件为什么会损坏? 疑问二:I/O 有时候为什么会突然很慢? 不同的场 ...

  9. 【开源】F2FS技术拆解

    F2FS (Flash Friendly File System) 是专门针对SSD.eMMC.UFS等闪存设备设计的文件系统.由三星工程师Jaegeuk Kim于2012年10月发布到Linux社区 ...

最新文章

  1. .NET Framework/.NET Compact Framework/.NET Micro Framework功能集比较
  2. 高颜值性价比神器,乐Pro3双摄AI版带来不一样的上手体验
  3. 链表问题(6)-----排序
  4. [Tips]Linux在命令行中打开图形化程序的各种命令
  5. java 反射用法_Java 反射的概念与使用
  6. python 西门子交换机_python读取交换机
  7. 怎么判断我选了多少个复选框_7~8个月宝宝一天吃多少辅食,怎么安排?妈妈这样做,养出健康娃...
  8. SPOJ Problem 22:Triangle From Centroid
  9. java.io.FileNotFoundException: ...\ibs\library-1.0.17.jar (系统找不到指定的文件。)
  10. bzoj·入门OJ·统计损失
  11. 句子迷网站 据说战争与和平很牛
  12. 昆明计算机学校录取分数,云南省昆明铁路机械学校2021年招生录取分数线
  13. 使用Chrome开发者工具精确定位网页元素位置
  14. MySQL的引擎初识
  15. 证券业上云内参: 深圳证券信息
  16. Minecraft我的世界开服教程
  17. NoSQL数据库与分布式缓存对比:同工异曲
  18. 个人隐私保护法_浅学一下
  19. 3D Multi-Object Tracking: A Baseline and New Evaluation Metrics论文阅读记录
  20. 【每日早报】2019/08/12

热门文章

  1. 汤姆计算机科技有限公司英语,关于计算机专业汤姆猫概述简介介绍的毕业设计论文英文英语外文文献翻译成品资料:Tomcat介绍(中英文双语对照).docx...
  2. 【C++】定义一个求绝对值函数的模板,实现对不同数据类型的数求绝对值。
  3. 一个完整的MSI包的配置文件XML的内容形式和查看方法ORCA
  4. 多线程-Callable接口
  5. 适合大一大二学生的深度学习实践项目汇总:涵盖图像处理、语音识别、自然语言处理等领域
  6. 用计算机程序实现离散化的对象模型,模糊PID应用
  7. Python —— 字典攻击
  8. 从思维转变看数字化转型 IT 经营
  9. [转载]我的时间管理与方法论
  10. 跑得快算法分析(多叉树深度递归)