Tuesday, January 29, 2013

Fragmentation


Mainly to avoid fragmentation, the ext2/ext3 filesystem is divided into block groups.

When allocating space for a new file or extending an existing file, the ext2/ext3 filesystem will preallocate upto eight data blocks for the file. Unused preallocated blocks are freed when the file is closed, truncated or when a non-sequential write is detetcted. When extending a file, the ext2/ext3 filesystem will try to get  a new block for the file near the last  block that was allocated for the file. If a free block cannot be found in the file's block group, a free block is allocated from another block group.

How To check the fragmentation at various levels?

1) To check fragmentation for a specific file, using filefrag command

# filefrag -v messages-20130106
Filesystem type is: ef53
File size of messages-20130106 is 1637646 (400 blocks, blocksize 4096)
 ext logical physical expected length flags
   0       0  2804193               1
   1       1  2786878  2804193      2
   2       3    25640  2786879     19
   3      22    25504    25658     42
   4      64  1279296    25545     60
   5     124  2636896  1279355    276 eof
messages-20130106: 6 extents found


2) To find the fragmentation for a mounted filesystem, use dumpe2fs command

# dumpe2fs /dev/sda2

Group 143: (Blocks 4685824-4718591) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Checksum 0x4cd5, unused inodes 8096
  Block bitmap at 4194319 (+4294475791), Inode bitmap at 4194335 (+4294475807)
  Inode table at 4201926-4202431 (+4294483398)
  32768 free blocks, 8096 free inodes, 0 directories, 8096 unused inodes
  Free blocks: 4685824-4718591
  Free inodes: 1157729-1165824

Group 144: (Blocks 4718592-4751359) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0x6a35, unused inodes 8096
  Block bitmap at 4718592 (+0), Inode bitmap at 4718608 (+16)
  Inode table at 4718624-4719129 (+32)
  26164 free blocks, 8096 free inodes, 0 directories, 8096 unused inodes
  Free blocks: 4718605-4718607, 4718621-4718623, 4725202-4751359
  Free inodes: 1165825-1173920

The ext2/ext3 filesystem is divided into block groups.  So in above case, we observe that for block group Group43, there is no fragmentation. The free blocks are available in a single stretch (Free blocks: 4685824-4718591). However, the block group Group44, has number of small gaps in it's free blocks(Free blocks: 4718605-4718607, 4718621-4718623, 4725202-4751359).

1 comment:

  1. You found your post fun to read. I can't wait to see your post soon. Good luck with the upcoming update. This article is very interesting and practical. I would like to share your latest Profile and article about Auto Clicker Downloads. Here you will learn Free Auto Clicker. Post your opinion after reading the full Profile. Thank you.

    ReplyDelete