29

I need to create a very high number of files which are not very large (like 4kb,8kb). It's not possible on my computer cause it takes all inodes up to 100% and I cannot create more files :

$ df -i /dev/sda5
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda5            54362112 36381206 17980906   67% /scratch

(I started deleting files, it's why it's now 67%)

The bytes-per-nodes are of 256 on my filesystem (ext4)

$ sudo tune2fs -l /dev/sda5 | grep Inode
Inode count:              54362112
Inodes per group:         8192
Inode blocks per group:   512
Inode size:               256

I wonder if it's possible to set this value very low even below 128(during reformating). If yes,what value should I use? Thx

1
  • 5
    The 'Inode size' is not the same as bytes-per-inode. 'Inode size' is simply the amount (number of bytes) of data each inode can contain, while bytes-per-inode refers to the ratio inodes to diskspace. Both values are independent. Jun 28, 2012 at 8:43

3 Answers 3

35

The default bytes per inode is usually 16384, which is the default inode_ratio in /etc/mke2fs.conf (it's read prior to filesystem creation). If you're running out of inodes, you might try for example:

mkfs.ext4 -i 8192 /dev/mapper/main-var2

Another option that affects this is -T, typically -T news which further reduces it to 4096.

Also, you can not change the number of inodes in a ext3 or ext4 filesystem without re-creating or hex-editing it. Reiser filesystems are dynamic so you'll never have an issue with them.

2
  • 7
    How do I determine the current bytes-per-inode value for a filesystem? Your command worked, but is there some value(s) in the tune2fs output that shows the ratio? Jun 28, 2012 at 8:49
  • 1
    I just wanted to comment that you can verify/change the default value in /etc/mke2fs.conf on Red Hat and derivatives. Feb 9, 2014 at 14:15
14

You can find out the approximate inode ratio by dividing the size of available space by the number of available inodes. For example:

$ sudo tune2fs -l /dev/sda1 | awk -F: ' \
    /^Block count:/ { blocks = $2 } \
    /^Inode count:/ { inodes = $2 } \
    /^Block size:/ { block_size = $2 } \
    END { blocks_per_inode = blocks/inodes; \
          print "blocks per inode:\t", blocks_per_inode, \
                "\nbytes per inode:\t", blocks_per_inode * block_size }'

blocks per inode:    3.99759 
bytes per inode:     16374.1
1
  • If you get an error like "tune2fs: Bad magic number in super-block while trying to open /dev/sda3" try running "blkid". The actual file system I needed to use was "/dev/mapper/myubuntu--vg-root".
    – jamshid
    Mar 17, 2017 at 2:10
-8

I have found solution to my problem on the mke2fs man page :

-I inode-size

Specify the size of each inode in bytes. mke2fs creates 256-byte inodes by default. In kernels after 2.6.10 and some earlier vendor kernels it is possible to utilize inodes larger than 128 bytes to store extended attributes for improved performance. The inode-size value must be a power of 2 larger or equal to 128. The larger the inode-size the more space the inode table will consume, and this reduces the usable space in the filesystem and can also negatively impact performance. Extended attributes stored in large inodes are not visible with older kernels, and such filesystems will not be mountable with 2.4 kernels at all. It is not possible to change this value after the filesystem is created.

The maximun you will be able to set is given by your block-size.

sudo tune2fs -l /dev/sda5 | grep "Block size"
Block size:               4096

Hope this can help....

1
  • 8
    The inode-size (-I) is something different than the bytes-per-inode (-i) setting. The inode-size determines the size of a single inode, larger inodes can contain more pointers to blocks, reducing the need for indirect blocks at the cost or increased disk usage. The bytes-per-inode setting sets a ratio that will be used to determine the maximum number of inodes. None of these two values can be changed after the filesystem had been created.
    – Tader
    Mar 1, 2012 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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