Reduce inode usage

From sabarish4u.wordpress.com

Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode number indexes a table of inodes in a known location on the device; from the inode number, the kernel can access the contents of the inode, including the location of the file allowing access to the file. A file’s inode number can be found using the ls -i command. The ls -l command displays some of the inode contents for each file. Stat will show a more complete listing of file attributes, including the inode number, number of blocks it occupies and block size.

[root@host2.myserver.com] ~ >> stat .bashrc
File: `.bashrc'
Size: 325 Blocks: 8 IO Block: 4096 regular file
Device: ca03h/51715d Inode: 293879 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-01-06 09:39:35.000000000 -0500
Modify: 2010-07-28 13:51:44.000000000 -0400
Change: 2010-08-27 16:16:18.000000000 -0400

File names and directory implications:
* Inodes do not contain file names, only file metadata.
* Unix directories are lists of “link” structures, each of which contains one filename and one inode number.
* The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.
* The kernel’s in-memory representation of this data is called struct inode in Linux.

We can find the inode usage (Number of files) owned by each user/directory, especially useful in VPS. Each VPS will have inode limits (the maximum number of files that can be created in that VPS)

For example If the inode usage is 100 % then we needs to find out which user/directory has owned the maximum number of files.

[root@server]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vzfs 800000 800000 0 100% /
simfs 800000 800000 0 100% /tmp
simfs 800000 800000 0 100% /var/tmp

Run the following commands

[root@server ~]# repquota -a | sort -nk6 | head

Block limits File limits
*** Report for user quotas on device /dev/vzfs
———————————————————————-
Block grace time: 00:00; Inode grace time: 00:00
User used soft hard grace used soft hard grace
test1 +- 25816 25600 25600 none 663 0 0
test2 – 4 0 0 1 0 0
mail – 4 0 0 1 0 0

(more…)

Continue ReadingReduce inode usage