1

How approximately calc bytes-per-inode for ext2?

I have 7.3GB storage (15320519 sectors 512B each). I have made ext2 filesystem with block size 4096

mke2fs /dev/sda2 -i 524288 -m 0 -L "SSD" -F -b 4096 -U 11111111-2222-3333-4444-555555555555 -O none,filetype,sparse_super,large_file

Filesystem label=SSD
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
15104 inodes, 1915064 blocks
0 blocks (0%) reserved for the super user
First data block=0
Maximum filesystem blocks=4194304
59 block groups
32768 blocks per group, 32768 fragments per group
256 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Usually all my files has size 100kB (and about 5 files can be 400MB). I try to read this and this. But still not clear how approximately calc bytes-per-inode? Current 524288 is not enough, for now I can't make new files in sda2 but still have a lot of free space.

P.S. Extra info

# df -T
Filesystem           Type       1K-blocks      Used Available Use% Mounted on
/dev/root            ext4          146929     84492     59365  59% /
devtmpfs             devtmpfs      249936         0    249936   0% /dev
tmpfs                tmpfs         250248         0    250248   0% /dev/shm
tmpfs                tmpfs         250248        56    250192   0% /tmp
tmpfs                tmpfs         250248       116    250132   0% /run
/dev/sda2            ext2         7655936    653068   7002868   9% /mnt/sda2

# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               143.5M     82.5M     58.0M  59% /
devtmpfs                244.1M         0    244.1M   0% /dev
tmpfs                   244.4M         0    244.4M   0% /dev/shm
tmpfs                   244.4M     56.0K    244.3M   0% /tmp
tmpfs                   244.4M    116.0K    244.3M   0% /run
/dev/sda2                 7.3G    637.8M      6.7G   9% /mnt/sda2

# fdisk -l
Disk /dev/sda: 7.45 GiB, 8001552384 bytes, 15628032 sectors
Disk model: 8GB ATA Flash Di
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0a19a8af

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1          309   307508   307200  150M 83 Linux
/dev/sda2       307512 15628030 15320519  7.3G 83 Linux
2
  • I suspect that defaults for ext2 might not have been updated for some time. But I'm also curious as to why you are using ext2 in 2024? (if you don't need the integrity / don't want the overhead of journalling then you can disable it when running mkfs or at mount (but IIRC, latter still reserves space) Commented May 22, 2024 at 8:44
  • It doesn't looks like a problem of ext2 source code, it looks like I don't know which ratio I should use in my case... Anyway ext4 has the same bytes/inode ratio issue... I use ext2 to don't disable journalling and disable reserving space manually... Commented May 22, 2024 at 10:40

1 Answer 1

2

Your free space is roughly 7.3*1024*1024*1024 bytes. On average, the size of a file is expected to be 100*1024 bytes. This means you have room for approximately

7.3*1024*1024*1024 / (100*1024) = 7.3*1024*1024/100 ≃ 76,546

distinct files. That implies you need precisely that many inodes.

The mke2fs output indicates you currently have 15,104 inodes; it's no wonder you run out of them -- you need approx. five times as many.

I believe you are missing that the -i option already directly specifies your expected average file size. You need one inode per (distinct) file, so if your avg file size is 100KB, then a new inode should be assigned to every 100KB of storage. Simply re-run the command with -i $((100*1024)).

(Your current option -i 524288 tells mke2fs that your usual file size will be 512KB, which is cca. five times larger than reality -- that's why you get cca. five times fewer inodes than needed.)

In summary, just read "bytes-per-inode" as "bytes-per-distinct-file".

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.