存储系统上线前要做资源评估,通常需要在性能(即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

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

linux文件系统评估之inode的更多相关文章

  1. Linux文件系统中的inode节点详细介绍

    这篇文章主要介绍了Linux文件系统中的inode节点,详细讲解了inode是什么.inode包含的信息.inode号码的相关资料等,需要的朋友可以参考下 一.inode是什么? 理解inode,要从 ...

  2. linux文件系统软链接硬链接

    引子 目前,UNIX的文件系统有很多种实现,例如UFS(基于BSD的UNIX文件系统).ext3.ext4.ZFS和Reiserfs等等. 不论哪一种文件系统,总是需要存储数据.硬盘的最小存储单位是扇 ...

  3. 【Linux学习】Linux文件系统4—Linux文件硬链接与软连接

    Linux文件系统4-Linux文件硬链接与软连接 inode:索引节点 (连接文件)link 一.文件硬链接 1.Linux文件系统中,inode只相同的文件是硬链接文件 2.不同文件名,inode ...

  4. Linux文件系统(inode、block……)

    内容源于<鸟哥的Linux私房菜> 认识 EXT2 文件系统 文件系统的特殊观察与操作 文件系统 superblock,inode,block superblock,inode,block ...

  5. linux 文件系统(inode和block)

    linux文件系统(inode block superblock)   先说一下格式化:每种操作系统所设置的文件属性/权限并不相同,为了存放这些文件所需的数据,因此就需要将分区格式化,以成为操作系统能 ...

  6. 理解Linux文件系统之inode

    很少转发别人的文章,但是这篇写的太好了. 理解inode   作者: 阮一峰 inode是一个重要概念,是理解Unix/Linux文件系统和硬盘储存的基础. 我觉得,理解inode,不仅有助于提高系统 ...

  7. # linux文件系统(inode block superblock)

    先说一下格式化:每种操作系统所设置的文件属性/权限并不相同,为了存放这些文件所需的数据,因此就需要将分区格式化,以成为操作系统能够利用的文件系统格式.linux的文件格式为Ext2/Ext3,现在好像 ...

  8. [转]理解Linux文件系统之inode

    很少转发别人的文章,但是这篇写的太好了. 理解inode   作者: 阮一峰 inode是一个重要概念,是理解Unix/Linux文件系统和硬盘储存的基础. 我觉得,理解inode,不仅有助于提高系统 ...

  9. Linux基础篇学习——Linux文件系统之文件存储与读取:inode,block,superblock

    Linux文件类型 代表符号 含义 - 常规文件,即file d directory,目录文件 b block device,块设备文件,支持以"block"为单位进行随机访问 c ...

随机推荐

  1. hdoj 1874 畅通工程续【dijkstra算法or spfa算法】

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. AutoLayout框架Masonry使用心得

    AutoLayout框架Masonry使用心得 字数1769 阅读1481 评论1 喜欢17 我们组分享会上分享了页面布局的一些写法,中途提到了AutoLayout,会后我决定将很久前挖的一个坑给填起 ...

  3. Struts2 + Spring + Hibernate 通用 Service 和 DAO

    我在 Struts2 + Spring + Hibernate  项目开发中总结出了一个Service 和 DAO ,可以用于处理任何的pojo(bean).使用这两个Service 和 DAO 可以 ...

  4. NSTimer运行机制和线程问题

    A.首先要理解NSTimer运行机制和Runloop之间的关系: 1.IOS的Run Loops机制 Run Loops是线程的基础部份,任何线程,包括主结程,都包含了一个run loop对象,Coc ...

  5. linux快速入门 1.1命令行操作

    http://lovesoo.org/linux-command-line-operation.html 1.1命令行操作 目录: <wp_nokeywordlink>Shell简介 &l ...

  6. js获取上传文件内容(未完待续)

    js 获取上传文件的字节数及内容 <div> 上传文件 : <input type="file" name = "file" id = &qu ...

  7. Java 判断是否为汉字 判断是否为乱码 判断字符串是否为双整型数字 整数 数字

    /**  * 判断是否为汉字  *   * @param str  * @return  */ public static boolean isGBK(String str) {  char[] ch ...

  8. Android Touch事件原理加实例分析

    Android中有各种各样的事件,以响应用户的操作.这些事件可以分为按键事件和触屏事件.而Touch事件是触屏事件的基础事件,在进行Android开发时经常会用到,所以非常有必要深入理解它的原理机制. ...

  9. [AngularJS] Accessible Button Events

    Often buttons need to be handled by JavaScript, and if done improperly it can lead to accessibility ...

  10. ASC(1)G(上升时间最长的序列)

    G - Beautiful People Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...