且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[深入理解文件系统之十一] ext2中data和meta-data的数据一致性

更新时间:2022-03-07 04:30:34


 ext2中data和meta-data的数据一致性

  • ext2 中的e2fsck

e2fsck是ext2/ext3/ext4的文件系统数据一致性的检查工具。在ext2中,出现下面的三种情况时,有必要进行一致性检查:

a. not cleanly unmounted;

b. the maximum mount count has been exceeded;

c. maximum time between checks has been exceeded.


考虑到文件系统变动带来的兼容性要求,ext2中e2fsck需要支持的三种标志

COMPAT: on-disk format is 100% compatible with older on-disk formats for reading and writing


RO_COMPAT: on-disk format is 100% compatible with older on-disk formats  only for  reading


INCOMPAT: the on-disk format has changed in some way that makes it unreadable by older kernels, or would otherwise cause a problem if an old kernel tried to mount it。


对e2fsck而言,它需要用比内核更严格的方式来处理上面的flags。如果连e2fsck都不能正确解析上面的任何一个flag,整个文件系统的一致性的检查都不会进行,这是因为e2fsck在此情况下判断当前文件系统给定的特性是否有效。


  •  ext2的meta data

根据作用的级别不同,ext2保证data和metadata同步写入磁盘可以分为三种方式:

per file: 打开的时候指定O_SYNC flag;  (ext2 专有特性)

per file : chattr +S file_name

per file-system: mount的时候指定sync选项


  • ext2的局限性

ext2文件系统的局限性一方面来自内核代码的限制,比如在Linux 2.4内核中,一个块设备的最大size是2T。另外一方面,来自于它的block bitmap/inode bitmap/inode  块/数据块的数据拓扑结构,比如文件大小和文件系统size的限制:

Filesystem block size:     1kB        2kB        4kB        8kB

File size limit:          16GB      256GB     2048GB     2048GB

Filesystem size limit:  2047GB     8192GB    16384GB    32768GB


再如目录中文件数的限制:

There is an upper limit of 32000 subdirectories in a single directory

另外,受限于目录中文件基于链表的组织形式,建议一个目录中最大允许10-15k files, 否则会出现严重的性能瓶颈。当然如果改成了基于hash的目录索引的方式,最大支持的文件数目可以达到100k~1M+.


  • ext2中的journal扩展

Stephen Tweedie为ext2开发了文件系统的journal功能。主要目的是:

1.避免meta-data corrution;

2. long time to do e2fsck;


文件系统的Journal只保存meta-data (data 也可以同时保存)。对于完整的journal ,重放到文件系统中去; 否则,当前incomplete的transaction会被丢弃,这个transaction所代表的对文件系统的修改也会丢失。


参考链接:

References

==========

The kernel source   file:/usr/src/linux/fs/ext2/

e2fsprogs (e2fsck)  http://e2fsprogs.sourceforge.net/

Design & Implementation http://e2fsprogs.sourceforge.net/ext2intro.html

Journaling (ext3)   ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/

Filesystem Resizing http://ext2resize.sourceforge.net/

Compression (*)     http://e2compr.sourceforge.net/


Implementations for:

Windows 95/98/NT/2000   http://www.chrysocome.net/explore2fs

Windows 95 (*)      http://www.yipton.net/content.html#FSDEXT2

DOS client (*)     ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/

OS/2 (+)        ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/

RISC OS client     http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/




















本文转自存储之厨51CTO博客,原文链接:http://blog.51cto.com/xiamachao/1917977 ,如需转载请自行联系原作者