Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal number of files per directory vs number of directories for EXT4

Tags:

I have a program that produces large number of small files (say, 10,000 files). After they are created, another script accesses them and processes one by one.

Questions:

  • does it matter, in terms of performance, how the files are organized (all in one directory or in multiple directories)
  • if so, then what is the optimal number of directories and files per dir?

I run Debian with ext4 file system

Related

  • Maximum number of files/folders on Linux?
  • https://serverfault.com/questions/104986/what-is-the-maximum-number-of-files-a-file-system-can-contain
like image 808
Jakub M. Avatar asked Oct 24 '12 09:10

Jakub M.


People also ask

How many files are in a folder ext4?

ext4: Maximum number of files: 232 - 1 (4,294,967,295)

What is the maximum file system size in ext4?

The ext4 file system can support volumes with sizes up to 1 Exabyte (EB) (1,000 Terabytes = 1018 Bytes) and files with sizes up to 16 Terabytes (TB). Ext4 is backward compatible with ext3 and ext2, making it possible to mount ext3 and ext2 as ext4.

What is the maximum number of files this file system can have?

NTFS File Size Maximum disk size: 256 terabytes. Maximum file size: 256 terabytes. Maximum number of files on disk: 4,294,967,295. Maximum number of files in a single folder: 4,294,967,295.

Is there a limit to how many files can be in a folder?

You can put 4,294,967,295 files into a single folder if drive is formatted with NTFS (would be unusual if it were not) as long as you do not exceed 256 terabytes (single file size and space) or all of disk space that was available whichever is less.


1 Answers

10k files inside a single folder is not a problem on Ext4. It should have the dir_index option enabled by default, which indexes directories content using a btree-like structure to prevent performance issues.

To sum up, unless you create millions of files or use ext2/ext3, you shouldn't have to worry about system or FS performance issues.

That being said, shell tools and commands don't like to be called with a lot of files as parameter ( rm * for example) and may return you an error message saying something like 'too many arguments'. Look at this answer for what happens then.

like image 76
mbarthelemy Avatar answered Oct 01 '22 04:10

mbarthelemy