Tag Archives: inode

No space left on device: Small files and inodes

I’ve run out of “free space” on building, testing and staging servers few times in last year with relatively small projects based on Symfony 2 or Zend Framework 2.

Used frameworks are rather small:

  • Symfony (2.4): 6450 files, 1283 folders, 46788608 bytes (apparent size 29894665)
  • Zend Framework (2.2): 2421 files, 427 folders, 17498112 bytes (apparent size 10912260)

So, framework or project files are not the issue, even if you build, test and deploy many times per day without removing previous releases (deployment process issue, fixed first). I’m talking in file size context.

So when you run out of free space – you login into server and type:

df -h

and see that you have half of partition empty (sometimes more), but when you try to create a new file you get: “No space left on device”.

But why? But how?

In my case it was inode count. I’ve run out of inodes on my partition. To see inode usage type:

df -i

So, inode (index node) is a data structure used to represent a filesystem object. Read more on Wikipedia or try to use search engines to find more info about inode.

At trouble making servers I’ve used default settings for my filesystems.

For example: if you have Ubuntu 13.10 and 4GB partition formatted with ext3 filesystem you will have 262144 inodes.
I’ve tried to copy Zend Framework 2 on that partition: 92 good copies, 1 corrupted copy, 2.2 GB free and out of inodes – waste of disk space. With Symfony 2 I’ve got 33 copies and out of inodes.

How to solve this issue? Buy bigger drive or increase inode count when you create filesystem on partition.

I’ll try to calculate optimal inode count for 4Gb partition with ext3 filesystem for both frameworks with maximal copies count. It might be a synthetic example, but if you automate builds of many projects with similar file count and file size ratio – this might help.

Partition size is about 3781115904 bytes, so we can copy ~80 Symfony 2 copies or ~216 copies of Zend Framework 2. Symfony 2 will require about 618640 inodes and Zend Framework 2 about 615168 inodes (inode per file or directory). Lets create ext3 filesystem on 4GB partition with 620000 inodes. Command for example:

mkfs.ext3 -N 620000 /dev/sdb1

I’ve tried to copy Zend Framework 2 on that partition: 216 good copies, with Symfony 2 I’ve got 79 copies – more than twice bigger.

Another way to calculate inodes count for partition: average file size in your project. Zend framework 2 7227 bytes, Symfony 2 7254 bytes, so on 3781115904 bytes partition we might have up to 522254 files (with avg.: 7240 bytes per file).

Conclusion: default filesystem settings not always the best choice for build, testing or staging servers. Look at your project or projects you will place on your servers, do some calculations – you might get better disk space usage for same price. Don’t forget, that you might need to place Composer cache somewhere on your build server – PHP projects/frameworks/libraries have quite big amount of smaller files in our times (in development versions even more) – this knowledge might be handy.

This calculations might not be suitable for production servers – user uploaded content might change average file size and your inode count might be a penalty. I never tested is there any performance penalties (or other drawbacks) if you increase inodes count.

Don’t forget that this rules apply only for filesystems with inodes, like ext2, ext3. Ext4 might have other rules (depends on settings). There are filesystems without inodes too.