6

Are there any drawbacks to creating ext4 file systems with 2^32-1 inodes?

I have a 1tb drive and I would like to store 800 million to 1.5 billion small files on it. It seems that the max is 4 billion, so I'm wondering whether I could just set it to the max when creating an fs, or I should find some other solution.

4
  • 2
    Each ext4 inode takes up 250 bytes of disk space ...
    – Soren A
    Dec 27 '18 at 13:26
  • @SorenA, even if it's unused?
    – Fluffy
    Dec 27 '18 at 13:30
  • 1
    If size of single inode is smaller than the blocksize of the filesystem, then in that case more inodes would be made than can ever be used. Dec 27 '18 at 13:37
  • @PerlDuck, please see edit
    – Fluffy
    Dec 27 '18 at 13:42
4

According to similar questions over on Stack Overflow and Unix & Linux (see below) it is a bad idea to max out the number of inodes on an ext4 filesystem.

Better use another filesystem or split your disk into multiple filesystems.

To summarize:

  • An inode occupies 256 bytes. It may be configured to 128, but even though:

    2³² inodes × 256 bytes each = 1 TB
    
  • When creating an ext4 filesystem, you can specify the usage type as defined in /etc/mke2fs.conf:

    mkfs.ext4 -T usage-type /dev/something
    

    For storing many small files the type small might be used:

    small = {
        blocksize = 1024
        inode_size = 128
        inode_ratio = 4096
    }
    

    This means: for every 4096 bytes of diskspace (filesystem size) one inode will be reserved each of which has a size of 128 bytes. The command mkfs.ext4 -T small /dev/something would thus create 244 million inodes on a 1TB filesystem that occupy 31 GB. These 244 million files will at least occupy 250 GB (min. 1024 bytes each).

  • To hold 1 billion inodes with the small footprint (128 bytes) you would need 128 GB just for the inodes. If the smallest possible blocksize (1024 according to mk2efs's manpage) is used, then these 1 billion files would at least occupy 1TB (but remember you only have 872 GB left because of the 128 GB for the inodes).

  • The smallest possible blocksize for ext4 is 1024 bytes. Hence, you cannot store more than 1 TB / 1024 = 1 billion files and it's pointless to have more inodes.

  • As a general rule of thumb the inode_ratio should not be smaller than the blocksize because you cannot (easily) store more than one file in one block.

  • It is possible to store the first 60 bytes of a file directly whithin the inode if the filesystem is configured that way. In that case, the file would not occupy a (regular) block; read about such inline data here but also consider the inode size.

  • From a comment to the U&L question:

    Too many inodes has a deep cost for sure, they take up space themselves, and believe me that fsck performance is dead serious. We're talking practically exponential slowdowns, like 30 seconds vs 2 days... and this is I/O bound. Not to mention slow downs of file listing, indexing... etc.


References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.