Saturday, September 6, 2008

Tuning ext3 Filesystem

Checking the filesystem

Since ext3 is a journaled filesystem it will never be labeled as dirty even if there are real problems. We can force the filesystem checks to be run at every boot and/or at periodic intervals. During the boot process the init script scans the list of devices in /etc/fstab, and then runs fsck (unless options on the filesystem instruct it otherwise).

Examine and change the properties of a filesystem using tune2fs [options] /dev/name - here name is either

  • sdXY for disk X, partition Y
  • mdX for software raid partitions
  • the name of logical volumes under LVM.

View parameters with “-l” option, there are four parameters of interest

  1. Mount Count: how many times the filesystem has been mounted since it was last checked
  2. Maximum Mount Count: run checks at every X mounts (CentOS defaults this value to -1, never gets checked)
  3. Last Checked: Date/time the last filesystem check was run
  4. Check Interval: How often should checks be run (CentOS default = 0, never gets checked)

Change the defaults to run checks on every boot or at 7 day intervals (you may want to stagger these so that not all filesystems are being checked simultaneously).

  • Run fsck on every boot tune2fs -c 1 /dev/md0

    tune2fs -c 1 /dev/VolGroup00/LogVol00

  • Run fsck every 7 days tune2fs -i 7d /dev/md0. Note: This does not mean that fsck will be run every 7 days for you, rather it means if the system reboots and it has been more than 7 days since the filesystem was checked, then fsck will run now. If you really want the filesystem checked every 7 days then it must be done via a cron job and the filesystem should (must?) be unmounted as well....which is not really practical for a busy server :-(

    tune2fs -i 7d /dev/VolGroup00/LogVol00

Reclaiming some disk space

By default the filesystem reserves some space for root so normal users can never truly fill up a filesystem. This gives root some space to work in during times of crisis (ext3 by default reserves 5% for root). Details are provided by tune2fs

[root ~]# tune2fs -l /dev/VolGroup00/LV_Home |grep [Bb]lock\ count
Block count: 108797952
Reserved block count: 5439897

Preserving this extra 5% is necessary on / and /var but it seems to be overkill on really big filesystems. On my ~400GB /home filesystem (with a block size = 4096 bytes), the 5439897 reserved blocks are ~ 20 GB. To reserve only 1% space for root do

[root ~]# tune2fs -m1 /dev/VolGroup00/LV_Home

which will reclaim 4% (about 16GB) for normal users and leave root with 4GB of breathing room. To reserve less than 1% for root you need to calculate the number of blocks yourself and use the “-r” option.

No comments: