WeSee
WeSee

Reputation: 3772

Yii2: Reducing inodes usage on vServer

On my Linux vServer the inodes are limited (e.g. 250.000). I found that an Yii2 installation requires quite a lot of inodes. The number of inode is roughly the number of files and directories.

The number of inodes used in the current directory and its subdirectories can be determined with

find .  -xdev -printf '%h\n' | sort | uniq -c | awk '{total = total + $1}END{print total}'

An average of my Yii2 projects is about 30k inodes. There are not much in files in ./web/assets, in the ./runtime or ./web/images folders. Most of the inodes are used in the ./vendor directory.

So the number of my Yii2 projects is limited to 8 projects.

What can I do to reduce inode usage in Yii2 projects?

Upvotes: 2

Views: 288

Answers (1)

dan4thewin
dan4thewin

Reputation: 1184

Assuming you have root in your Linux vServer, you can embed a new filesystem in a single file and mount it. Such a file would take only a single inode in the parent filesystem while the number of inodes within the image is up to you.

# dd if=/dev/zero of=myfs bs=1MB count=512
512+0 records in
512+0 records out
512000000 bytes (512 MB) copied, 4.10134 s, 125 MB/s
# losetup --find --show `pwd`/myfs
/dev/loop0
# mkfs -t ext4 -i 1024 /dev/loop0
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done
Creating filesystem with 500000 1k blocks and 500464 inodes
Filesystem UUID: fef5ab29-8991-4f99-8a27-80b4d11b3133
Superblock backups stored on blocks:
        8177, 24529, 40881, 57233, 73585, 204401, 220753, 400625

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

# mount /dev/loop0 /mnt
# df -i | sed -n '1p;/mnt/p'
Filesystem     Inodes  IUsed  IFree IUse% Mounted on
/dev/loop0     500464     11 500453    1% /mnt

Here, I chose ext4 and set the bytes-per-inode, -i, to its minimum value, giving the largest inode count, 500464, for 512MiB on ext4.

You could make multiple filesystems this way, one for each project, or make a much larger one with many more inodes.

To mount the image at the next reboot, add a line to /etc/fstab.

Upvotes: 1

Related Questions