linux文件系统评估之inode

  存储系统上线前要做资源评估,通常需要在性能(即iops、带宽等)和容量维度进行业务评估;而具体到本地文件系统存储的容量时,需要根据具体业务对文件系统的可用数据空间和可用inode数进行评估,作者通过工作中一事例对此有了更深刻的认识:

  由于系统需求,要将linux服务器A的本地磁盘数据(数据量260GB左右)同步至linux服务器B的本地磁盘,A和B相应的分区可用空间均为293GB左右;在数据同步接近完成时,log开始提示错误信息机器B“No space left on device”,而df -lh命令显示B本地文件系统还有50GB左右可用空间;猜测是inode已用完所致,使用df -i命令显示B本地文件系统的IFree确实为0,IUsed为1946万,IUse%为100%;而机器A同样分区大小的文件系统却显示Inodes总数为3900万、IUsed为1986万,其inode总数为机器B的2倍,那如何将增加机器B文件系统的inode数量呢?

  通过man page了解到,extX文件系统格式化完成后,其inode数不能在线调整,只能重新格式化并通过参数配置;通常使用mke2fs创建文件系统时,会使用/etc/mke2fs.conf中的预设参数配置,其中与inode相关的有inode_size(ext4默认为256)和inode_ratio(默认为16384),inode_size参数的含义容易理解,即单个inode结构自身所占字节数,man page(CentOS 6.4,kernel 2.6.32)介绍如下:

Specify  the  size  of  each  inode  in bytes.  mke2fs creates 256-byte inodes by default.  In kernels after 2.6.10 and some earlier vendor kernels it is possible to utilize inodes  larger  than  128  bytes  to  store extended  attributes for improved performance.  The inode-size value must be a power of 2 larger or equal to 128.  The larger the inode-size the more space the inode table will consume, and  this  reduces  the  usable  space  in  the  filesystem  and can also negatively impact performance.  Extended attributes stored in large  inodes are not visible with older kernels, and such filesystems will not be mountable with  2.4  kernels  at  all.  It is not possible to change this value after the filesystem is created.

将机器B的ext4文件系统加上“-I 128”参数重新格式化,虽其inode_size从256变为128,其inode总数却并未发生变化;另一个参数inode_ratio在man page上的描述却不易理解:

Specify  the  bytes/inode  ratio.   mke2fs  creates an inode for every bytes-per-inode bytes of space on the disk.  The larger the bytes-per-inode ratio, the  fewer  inodes  will  be  created.   This  value  generally shouldn't be smaller than the blocksize of the filesystem, since in that case more inodes would be made than can ever be used.  Be warned that it is not possible to expand the number of inodes on a filesystem after it is created, so be careful deciding the correct value for this parameter.

经过求证与测试后顿悟,其含义可通俗描述为:格式化时,每bytes-per-inode(或inode_ratio)字节大小的空间就创建一个inode,在分区大小固定前提下,该值越大,inode个数越少,data block就越多,该值越小,inode个数越多,data block就越少;以默认值16384(即16KiB)为例,如果文件系统上所有文件大小均为16KiB(或平均值),则data block耗尽的同时inode也将耗尽,二者占文件系统比例处于最理想状态,对于大量小文件的业务,通常将该值调小以增加inode数量;

  上述机器B的问题正是如此,参照机器A的inode总数是机器B的2倍,将inode_ratio值设置为8KiB,加上"-i 8192"参数重新格式化,成功将机器B的inode总数翻倍。

  另外,相对于ext3默认inode_size为128,ext4默认inode_size变为256,以存储其它字段(如nanosecond timestamps,inode versioning,extend attributes等)。

  此事例告诉我们,使用extX文件系统时,需要在上线前根据存储业务情况对文件系统的data block和inode数做综合评估;如果是和上述相反的大文件存储业务,可以将inode_ratio值调大,以增加data block数量,如使用“-T largefile”选项对应的inode_ratio值为1MiB,在1.8TiB大小的分区创建ext4文件系统时,可增加20~30GiB左右的数据空间。

  对于不能准备评估或需求特殊(如海量小文件)的存储业务,可考虑使用ReiserFSXFSJFS等,以避免inode耗尽的风险;关于这些filesystem的介绍,请关注后续博文。

参考文章:

http://www.linux-mag.com/id/8658/

http://www.geekride.com/understanding-unix-linux-filesystem-inodes/

http://stackoverflow.com/questions/3618820/how-many-bytes-per-inodes

https://ext4.wiki.kernel.org/index.php/Main_Page

https://en.wikipedia.org/wiki/ReiserFS

http://www.serverfocus.org/reiserfs-vs-ext4-vs-xfs-vs-zfs-vs-btrfs

------------------------------------

http://www.cnblogs.com/wuhuiyuan/p/linux-filesystem-inodes.html

个人原创,转载请注明出处。

posted @ 2015-10-19 16:17  it_arch_notes  阅读(5461)  评论(0编辑  收藏  举报