Linux下的磁盘碎片整理

Linux下的磁盘碎片整理

网上有些帖子说XFS不用做碎片整理,其实是错误的。XFS用延迟写入等技术确实可以减少碎片的出现,但是如果 服务器用了几年,并且文件操作比较频繁,还是会出现碎片的,应该整理。注意:在Debian中XFS相关命令在xfsprogs包中,而xfs_fsr命令是在xfsdump包中的。所以要用xfs_fsr整理碎片,记得安装xfsdump包。 其他Linux发行版本中,包含xfs相关命令的包也应该叫类似的名字,自己google一下。
    xfsdump - Administrative utilities for the XFS filesystem

    xfslibs-dev - XFS filesystem-specific static libraries and headers

    xfsprogs - Utilities for managing the XFS filesystem



一、查看碎片

    1、查看/dev/sdc1的碎片情况:

        # xfs_db -c frag -r /dev/sdc1

        actual 93133, ideal 8251, fragmentation factor 91.14%
     这个应该整理一下碎片了 :)


    2、查看/dev/sdb1的碎片情况:

        # xfs_db -c frag -r /dev/sdb1

        actual 905607, ideal 900507, fragmentation factor 0.56%
     这个不用做碎片整理。    


    3、另一种命令形式:

        # xfs_db -r /dev/sdd1
        xfs_db> frag
        actual 117578, ideal 116929, fragmentation factor 0.55%


    4、也可以通过xfs_bmap命令了解某个文件的情况:

        # xfs_bmap -v case19.dat
            case19.dat:
            EXT: FILE-OFFSET       BLOCK-RANGE            AG AG-OFFSET               TOTAL
            0: [0..9551]:        592061576..592071127    1 (103696496..103706047)   9552
            1: [9552..86039]:    599312816..599389303    1 (110947736..111024223)  76488
            2: [86040..170399]:  599655400..599739759    1 (111290320..111374679)  84360
            3: [170400..256799]: 599751632..599838031    1 (111386552..111472951)  86400
 , nike tn;          4: [256800..340079]: 1185490752..1185574031  2 (208760592..208843871)  83280
            5: [340080..592703]: 1185577976..1185830599  2 (208847816..209100439) 252624


二、整理碎片

     # xfs_fsr /dev/sdc1

三、他从xfs_fsr得到了好处:)    (摘自 http://www.linux.com/feature/141404

    Wow! Thanks. That'l teach me to use a non-default tech without researching it.    
    Over the years, my MythTV box had gotten inexplicably slow with lots of disk access for many operations like starting playback of a recorded video. With the advice here, I measured 98.6% fragmentation. A few sample files I checked that were 1-6GB captured MPEG-2 videos were stored on over 30,000 extents!
    After 2 nights of de-fragmenting, I'm down to 17% fragmented and startup time of playing a video is noticeably faster with less hard drive activity.


四、参考
http://www.linux.com/feature/141404
http://www.nekochan.net/wiki/index.php/XFS_defragmentation
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/a_man/cat1/fsr_xfs.z

你可能感兴趣的:(linux)