R.A. Epigonos et al.

[linux] ext3のhddの予約ブロックを減らし、ext4に変換、デフラグ

tune2fs -m 0 で予約ブロックを減らして、ユーザが保存できる領域を増やそう。

ext3でフォーマットされたアーカイブ用hddの予約ブロックを減らす

普通にmksfでフォーマットしたhddの状態を確認すると、以下のようになる。ブロック数的には約95%使用済みなのに、useは100%になっている。この5%分がreserved blocksと呼ばれるもの。

# df -aT /dev/sdz1
Filesystem     Type  1K-blocks       Used Available Use% Mounted on
/dev/sdz1      ext3 2884284060 2737719028     51756 100% /****************

アーカイブ用なので、書き換え頻度が低く、読み出しすることが多い。こういう場合は予約ブロックの一つの機能であるフラグメンテーションの抑制を無視しても領域がほしい。というわけで以下のようにして予約ブロックを減らす。終わればuseがブロック数の割合と同じ95%になる。事前unmountは不要。詳細確認すると、reserved block count の値が0になっていることがわかる。

# time tune2fs -m 0 /dev/sdz1
tune2fs 1.42.5 (29-Jul-2012)
Setting reserved blocks percentage to 0% (0 blocks)

real    0m1.142s
user    0m0.008s
sys     0m0.012s
# df -aT /dev/sdz1
Filesystem     Type  1K-blocks       Used Available Use% Mounted on
/dev/sdz1      ext3 2884284060 2737719028 146565032  95% /****************
# tune2fs -l /dev/sdz1
tune2fs 1.42.5 (29-Jul-2012)
Filesystem volume name:   <none>
Last mounted on:          *****************
Filesystem UUID:          ************************************
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent sparse_super large_file uninit_bg
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              183148544
Block count:              732566385
Reserved block count:     0
Free blocks:              10028
Free inodes:              183132167
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      849
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Filesystem created:       *** Feb  8 21:14:32 ****
Last mount time:          *** Jul 21 16:25:21 ****
Last write time:          *** Jul 21 16:25:21 ****
Mount count:              2
Maximum mount count:      -1
Last checked:             *** Jul  8 12:06:51 ****
Check interval:           0 (<none>)
Lifetime writes:          281 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      ************************************
Journal backup:           inode blocks

ext3フォーマットHDDのフラグメンテーション

せっかく5%~140GB程度の領域ができたので、ここにファイルを詰め込みたい。そこでまずは fsck でフラグメンテーションの状況チェック。3TBのディスクで2時間程度かかる。fsckの前にumountを忘れずに。断片化しているファイルの割合は 52.5%。

# umount /dev/sdz1
# time fsck -nvf /dev/sdz1
fsck from util-linux 2.20.1
e2fsck 1.42.5 (29-Jul-2012)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

       21524 inodes used (0.01%, out of 183148544)
       11310 non-contiguous files (52.5%)
           1 non-contiguous directory (0.0%)
             # of inodes with ind/dind/tind blocks: 21512/21463/0
   695925127 blocks used (95.00%, out of 732566385)
           0 bad blocks
           1 large file

       21511 regular files
           4 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
           0 symbolic links (0 fast symbolic links)
           0 sockets
------------
       21515 files

real    141m57.259s
user    18m55.175s
sys     11m32.167s

ext3からext4への変換とデフラグ

フラグメンテーションの大きさは50%程度だけど、アーカイブ用なのでデフラグをしておきたい。ext3には標準的なデフラグソフトがないのでフォーマットをext4に変換してデフラグする。フォーマット変換の前にumount、フォーマット変換、ファイルシステムチェック。fstab のエントリをext4に書き換え、マウント。

# umount /dev/sdz1
# time tune2fs -O extents,uninit_bg,dir_index /dev/sdz1
tune2fs 1.42.5 (29-Jul-2012)

real    0m1.099s
user    0m0.012s
sys     0m0.300s
# time e2fsck -fDC0 /dev/sdz1
e2fsck 1.42.5 (29-Jul-2012)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/sdz1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdz1: 21524/183148544 files (52.6% non-contiguous), 695925074/732566385 blocks

real    141m57.639s
user    19m31.989s
sys     11m17.946s
# vi /etc/fstab
# mount /dev/sdz1
# df -aT /dev/sdz1
Filesystem     Type  1K-blocks       Used Available Use% Mounted on
/dev/sdz1      ext4 2884284060 2737718816 146565244  95% /****************

フラグメンテーションのチェックと、デフラグ。オンラインでデフラグできるので便利。残念ながらフラグメンテーションは解決されず。

# time e4defrag -c /dev/sdz1
Filesystem is not mounted

real    0m0.101s
user    0m0.004s
sys     0m0.000s
# mount /dev/sdz1
# time e4defrag -c /dev/sdz1
<Fragmented files>                             now/best       size/ext
1. /***********************************************************
                                                 3/1             84 KB
2. /*****************************************************************
                                                 3/1            298 KB
3. /****************************************************************
                                                 3/1            386 KB
4. /*************************************************
                                                 3/1            394 KB
5. /******************************************************************
                                                 3/1            492 KB

 Total/best extents                             737501/32438
 Average size per extent                        3708 KB
 Fragmentation score                            1
 [0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
 This device (/dev/sdz1) does not need defragmentation.
 Done.

real    83m4.445s
user    0m1.732s
sys     1m33.290s
# time e4defrag /dev/sdz1
ext4 defragmentation for device(/dev/sdz1)
        Total extents:                  737501->737501
        Fragmented percentage:          100%->100%

real    114m7.063s
user    0m8.365s
sys     4m56.339s
# time e4defrag -c /dev/sdz1
<Fragmented files>                             now/best       size/ext
1. /***********************************************************
                                                 3/1             84 KB
2. /*****************************************************************
                                                 3/1            298 KB
3. /****************************************************************
                                                 3/1            386 KB
4. /*************************************************
                                                 3/1            394 KB
5. /******************************************************************
                                                 3/1            492 KB

 Total/best extents                             737501/32438
 Average size per extent                        3708 KB
 Fragmentation score                            1
 [0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
 This device (/dev/sdz1) does not need defragmentation.
 Done.


real    83m21.468s
user    0m1.708s
sys     1m34.202s

最初からext4フォーマット、reserved block countを0にしてフォーマット

# time mkfs -t ext4 -m 0 -c -c /dev/sdz1
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61054976 inodes, 244190385 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
7453 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848

Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: done
Testing with pattern 0x00: done
Reading and comparing: done
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


real    2196m10.328s
user    289m24.601s
sys     98m22.093s
# tune2fs -l /dev/sdz1
tune2fs 1.42.5 (29-Jul-2012)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ************************************
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              61054976
Block count:              244190385
Reserved block count:     0
Free blocks:              240307294
Free inodes:              61054965
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      965
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       *** Jul 22 01:10:05 ****
Last mount time:          n/a
Last write time:          *** Jul 23 13:46:11 ****
Mount count:              0
Maximum mount count:      -1
Last checked:             *** Jul 22 01:10:05 ****
Check interval:           0 (<none>)
Lifetime writes:          134 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      ************************************
Journal backup:           inode blocks

リファレンス

  1. why mkfs takes 5% space default?
  2. Formatting and making filesystem in Linux
  3. How to defragment an ext3 filesystem - a great resource for How To's from Wikia
  4. Ext4 Howto - Ext4

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-12-09T10:50:59+09:00
  2. Modified: 2008-12-09T10:50:59+09:00
  3. Generated: 2023-08-27T23:09:17+09:00