Report this

What is the reason for this report?

Low number of inodes

Posted on August 11, 2020

I selected a 100gb volume to be added to one of my droplets. One of the things I need to do with this volume is to write millions of files to it. I selected DO to format and mount the volume for me, but I quickly saw that the default number of inodes that DO creates is very low for the size of the volume. (output from df -i)

/dev/sda       3276800    11 3276789    1% /mnt/volume_nyc1_01

I ended up increasing the number of inodes:

/dev/sda       26214400    11 26214389    1% /mnt/volume_nyc1_01

(Command I used: mkfs.ext4 -N 26214400 /dev/sda)

While this isn’t a problem per se, it would be nice that DO handles this for users automatically. Is there a reason why DO chose a relatively small inode number for a large volume?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

As you have correctly pointed out you can change the number of inodes. Your application seems unique in that most users aren’t storing millions of files and inodes themselves take up space, 256 bytes per inode. While that seems largely irrelevant, if you 10x the number of inodes by default, and then everyone creates a volume, you will end up with a large amount of used up diskspace just for inodes and would provide less overall storage for customers. So it’s easier for just customers to adjust according to their needs and otherwise provide an inode amount that works for the majority of customer use cases by default.

Heya,

Running out of inodes can be a real headache, especially when you have a folder with millions of smaller files. Don’t worry, I’ve got you covered! Here’s a more efficient way to handle this using the find command directly.

  1. Identify Inode Usage: First, let’s identify which directories are consuming the most inodes. You can use the find command combined with wc -l to get a count of the inodes used by each directory.

    find / -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" | wc -l' \; | sort -n -k2
    

This command will give you a sorted list of directories with their inode usage.

  1. Drill Down Further: Once you’ve identified the main directory, you need to drill down further. For example, if /home is the culprit:

    find /home -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" | wc -l' \; | sort -n -k2
    

Keep drilling down until you find the specific directory causing the issue.

  1. Handle Hidden Files: Include hidden files in your search by specifying the appropriate paths:

    find /home/youruser -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" -name ".*" | wc -l' \; | sort -n -k2
    
  2. Clean Up: Once you’ve found the directory with the most inodes, it’s time to clean up. Here are a few strategies:

  • Delete Unnecessary Files: Identify and delete files you don’t need. For example, temporary files, logs, or cache files:

    ```
    find /home/youruser/temp -type f -delete
    ```
    
  1. Automate Cleanups: To prevent this from happening again, you can set up a cron job to regularly clean up unnecessary files:

    crontab -e
    

Add a job to clean up temporary files every week:

    0 3 * * 0 find /home/youruser/temp -type f -mtime +7 -delete
  1. Increase Inode Limit: If the issue persists and you can’t delete any more files, consider resizing your filesystem to increase the inode limit. This is a more complex operation and might require backing up your data.

Here are some commands to help you get started:

# Check inode usage
df -i

# Identify high inode usage directories
find / -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" | wc -l' \; | sort -n -k2

# Drill down into specific directories
find /home -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" | wc -l' \; | sort -n -k2

# Include hidden files in search
find /home/youruser -xdev -type d -exec sh -c 'echo -n "{}: "; find "{}" -name ".*" | wc -l' \; | sort -n -k2

# Delete unnecessary temporary files
find /home/youruser/temp -type f -delete

# Compress files
tar -czvf archive.tar.gz /home/youruser/folder

# Move files to another server
scp -r /home/youruser/folder user@other-server:/path/to/destination

# Automate cleanups with cron job
crontab -e

By following these steps, you should be able to clear up some inodes and prevent this issue from recurring in the future.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.