6

Is it based on a number determined when formatting a hard drive?

For instance:

$ df -Ti /
Filesystem     Type Inodes IUsed  IFree IUse% Mounted on
/dev/dm-0      ext4 983040 95683 887357   10% /

Where does that 983040 come from? Can we increase/decrease it? Within what limits?

  • @StéphaneChazelas I'll assume that you were just testing if I was paying attention ;-) (I often look at the edit history, before posting comments, and of course this time I hadn't). – Anthon Aug 17 '16 at 17:58

2 Answers2

6

If you're talking about ext4 filesystems, it's based on the size of the filesystem. Defaults to 1 inode per 16,384 bytes. More information at Archwiki - ext4 - bytes per inode ratio

Note that this ratio can be revised at the time of filesystem creation, see man page for mkfs.ext4

To address the subsequent edits to the question, where you added some questions:

Where does that 983040 come from?

It comes from the filesystem size. 1 inode per 16,384 bytes of filesystem, by default.

Can we increase/decrease it?

Yes, but not easily. Backup the filesystem, recreate the filesystem using the "-i bytes-per-inode" argument in the man page. Restore the filesystem contents.

Within what limits?

As shown in the man page, bytes-per-inode should not be set to less than the block size, otherwise you're likely to have more inodes than could ever possibly be used. As Stéphane Chazelas points out, empty files, devices, fifos, sockets, short symlinks consume an inode, but don't consume a block.

Do you really need to create more than 887,357 further files in the root filesystem ?

steve
  • 21,892
  • empty files, devices, fifos, sockets, short symlinks take one inode, but no block, so it's technically possible to use up the whole inode table while using very little data. So in some (OK contrived) situations, it may make sense to have bytes-per-inode smaller than the block size. – Stéphane Chazelas Aug 17 '16 at 15:06
  • Note that the -i bytes-per-inode is calculated based on the size of the block device, that is not the ratio size_in_the_fs/number_of_inodes, but block_device_size/number_of_inodes. For instance, with a mkfs -b 4096 -i 4096 on a device that is 10MiB large, you'll get 2560 inodes, but only about 5MiB of space available, so it will be more around 2KiB per inode. – Stéphane Chazelas Aug 17 '16 at 16:01
4

It's not a per-disk measure, it's a per-filesystem measure. For many filesystems, yes it is determined at format time. For some filesystems, it's dynamic based on the filesystem usage, average file size, and other bits of information.

John
  • 17,011