45

Given the current structure of a directory entry on a ext4 file system on Ubuntu, what is the maximum number of files a file system can contain?

What is the general method of calculating the maximum number of files a file system can contain?

3 Answers3

50

Ext4 has a theoretical limit of 4 billion files, which is restricted by the size of inode number it uses to identify each file (ext4 uses 32-bit inode numbers). However, as John says, ext4 allocates inode tables statically, so the actual limit is set when the filesystem is created.

The df command shows you a count of free inodes on your filesystem:

$ df -i

Filesystem        iused     ifree  %iused  Mounted on
/dev/disk0s3   55253386  66810480    45%   /
/dev/disk1s3   55258045  66805821    45%   /Volumes/Clone

Ext4 also supports an unlimited number of sub-directories per directory, though it may default to a limit of 64,000. This is configurable -- see the ext4 article at Kernel Newbies.

For more information, see The new ext4 filesystem: current status and future plans from the 2007 Linux Symposium.

  • This limit of 4 billion shouldn apply nowadays anymore. I have a ext4 filesystem with 4394582016 inodes. So probably ext4 uses 64bit counter for inodes today. – Hannes Jul 09 '22 at 22:15
11

There isn't one, per se; it depends. When you create an ext4 file system, you decide the size of the inode table, which in turn governs the total number of directories or files the file system can hold at once.

John Feminella
  • 1,288
  • 1
  • 8
  • 11
  • 11
    you can run `tune2fs -l /path/to/device` and look for the Inode count value to find what the limit is for a given filesystem –  Jan 20 '10 at 05:34
  • 1
    Can we increase the Inode count? As far as I know, inodes are stored as a linked list, so it's just like adding more nodes to the linked list. I guess, the question boils down to what can be the maximum length of a linked list? –  Jan 20 '10 at 05:42
  • 4
    In ext4 the inode table is statically allocated when the filesystem is created. The only way to increase it is to recreate the filesystem. The -N or -i options are used to set the number of inodes created. –  Jan 20 '10 at 06:25
  • 1
    It is also worth noting that directories are files and must be counted as such. – dmckee --- ex-moderator kitten Jan 20 '10 at 18:12
  • 1
    As are symlinks. I'm not sure if devices, FIFOs, and sockets count or not. – ephemient Jan 20 '10 at 18:40
  • 1
    @ephemient Yes they do; any entry in the filesystem counts as an inode. – MikeyB Jan 21 '10 at 14:55
  • 1
    @Geoff Reedy What if it's a VM? I try to determine this on a Linode box, it has `ext4`. `tune2fs` command says `Couldn't find valid filesystem superblock.` probably because of the virtualization. – Csaba Toth Jun 23 '17 at 22:21
  • `# mkfs.ext4 -N 10000000000 /tmp/big.img` ⇒ *too many inodes (10000000000), specify < 2^32 inodes* – mykhal Jul 12 '21 at 08:27
5

Not Ubuntu, but on Redhat Linux basic commands such as find fail with a 'Too many arguments error' when run against a directory containing 3 million files. ls runs successfully if no parameters are included, but fails with the same error as soon as filter parameters are added.

Assuming reliability of such basic commands is a mandatory requirement I'd suggest that 3 million files is too many.

John Hadaway
  • 51
  • 1
  • 1