What makes ext3 determine how frequently to perform file system checks when no options are specified

ext3

I created two partitions on a 1.5 TB drive, the first was 1 TB, the latter was the remaining .5 TB. Both were formatted as ext3. I don't mind the automatic filesystem checks occurring every so often, so I never bother configuring the frequency of it. What I found odd was that it decided to make the automatic check occur every 39 mounts for the 1 TB, and 27 mounts for the .5 TB partition. I attempted to look in the man pages as well as various forums, but I couldn't find any mention about how it determines the frequency for file system checks. I assume it is a simple formula, so does anyone know what it is?

Best Answer

The good thing about linux is the source is always somewhere. You can download or view the base e2fsprogs sources on kernel.org. This can also depend on your specific version and distribution though...

From current code it looks like it's some value added to 20 based on the UUID of the partition, if you have enable_periodic_fsck = 1 in your mke2fs.conf

mke2fs.c

if (get_bool_from_profile(fs_types, "enable_periodic_fsck", 0)) {
    fs->super->s_checkinterval = EXT2_DFL_CHECKINTERVAL;
    fs->super->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
    /*
     * Add "jitter" to the superblock's check interval so that we
     * don't check all the filesystems at the same time.  We use a
     * kludgy hack of using the UUID to derive a random jitter value
     */
     for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++)
         val += fs->super->s_uuid[i];
     fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT;
 } else
     fs->super->s_max_mnt_count = -1;

mke2fs.h

:#define EXT2_DFL_MAX_MNT_COUNT              20

Always good to see the words 'kludgy' and 'hack' in code =)

Related Question