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

個人原創,轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM