I have a Synology NAS (DS1815+, DSM 5.2) running ext4 and I observed bad performance on directories with thousands of (small) files.
The Synology NAS ext4 did not have the dir_index extension set up by default! I have no idea why Synology does that, because the dir_index feature only jumps in for big directories. It then creates an index which makes accessing, counting, iterating etc. much faster.
To check if you have the feature installed, use tune2fs -l /dev/yourDev :
tune2fs -l /dev/vg1/volume_1 | grep features
Filesystem features: ... dir_index ...
If you do not see dir_index in the list of features, than you can add it to your ext3/4 filesystem:
- umount /dev/youDev #Unmount the device
- tune2fs -O dir_index /dev/yourDev #add feature to FS
- e2fsck -D /dev/yourDev # Create indexes
For a Synology NAS the steps are:
tune2fs -O dir_index /dev/vg1/volume_1
e2fsck -D /dev/vg1/volume_1
The dir_index feature is available for ext3 and ext4 and is usually/often a default when creating ext4 on modern Linux distributions. However - as this Synology NAS shows - it's worth checking. In my case, this features increased rsyncing folder with 100k (small) files to the NAS from 4Mb/s to 14Mb/s.
Some quoting from www.debian-administration.org
The most useful tweak you can perform is the way that directory
indexes are scanned when looking for files. This is controlled by the
option "dir_index". By default this wouldn't be enabled but you can
add it by running:
mine:~# tune2fs -O dir_index /dev/sda1
Once you've done this you'll be able to see the updated filesystem
flags which are in use:
mine:~# tune2fs -l /dev/sda1 | grep features Filesystem features:
has_journal resize_inode dir_index filetype needs_recovery
Once you've done this you should find that listing the contents of
directories with large numbers of files becomes faster, and that
finding files in directories is also better.