I have a directory tree that contains many small files, and a small number of larger files. The average size of a file is about 1 kilobyte. There are 210158 files and directories in the tree (this number was obtained by running find | wc -l).

A small percentage of files gets added/deleted/rewritten several times per week. This applies to the small files, as well as to the (small number of) larger files.

The filesystems that I tried (ext4, btrfs) have some problems with positioning of files on disk. Over a longer span of time, the physical positions of files on the disk (rotating media, not solid state disk) are becoming more randomly distributed. The negative consequence of this random distribution is that the filesystem is getting slower (such as: 4 times slower than a fresh filesystem).

Is there a Linux filesystem (or a method of filesystem maintenance) that does not suffer from this performance degradation and is able to maintain a stable performance profile on a rotating media? The filesystem may run on Fuse, but it needs to be reliable.

If you know which files are going to be big/not changing very often, and which are going to be small/frequently changing, you might want to create two filesystems with different options on them, more suited to each scenario. If you need them to be accessible as they were a part of the same structure, you can do some tricks with mount, symlinks.
–
MarcinJan 10 '12 at 13:22

I am quiet surprised to know that btrfs(with copy-on-write feature) has been sluggish to you over a period of time. I am curious to have the results shared from you, possibly helping each other in new direction of performance tuning with it.
–
Nikhil MulleyJan 10 '12 at 14:00

there is a new animal online zfs on Linux, available in native mode and fuse implementations, incase you wanted to have a look.
–
Nikhil MulleyJan 10 '12 at 14:03

I tried zfs on linux once, was quite unstable. Managed to completely lock up the filesystem quite often. Box would work, but any access to the FS would hang.
–
PatrickJan 10 '12 at 14:46

Result:
While Ext4 had good overall performance, ReiserFS was extreme fast at reading sequential files. It turned out that XFS is slow with many small files - you should not use it for this use case.

Fragmentation issue

The only way to prevent file systems from distributing files over the drive, is to keep the partition only as big as you really need it, but pay attention not to make the partition too small, to prevent intrafile-fragmenting. Using LVM can be very helpful.

Further reading

The Arch Wiki has some great articles dealing with file system performance:

You should specify what version of the kernel youre basing that comparison off of. XFS got some very significant speed imporovments in one of the recent kernels (think it was 2.6.31, but dont quote me on that).
–
PatrickJan 11 '12 at 1:47

Other note, having a UPS is vital on any filesystem not running in synchronous IO mode. Ext4, reiserfs, and btrfs would all suffer data loss without a proper shutdown.
–
PatrickJan 11 '12 at 1:48

@Patrick Kernel: look here even though XFS performance has been improved, it's still slow with small files (DBench uses a filesize of 5B). XFS was intentionally made for CGI with huge partitions and files that are > 4MB, not for small 1KB files.
–
tafferJan 11 '12 at 9:18

1

btrfs internally does your lvm trick. It allocates smaller chunks of the disk and places files in those chunks, then only allocates another chunk of the disk when the existing chunks fill up.
–
psusiJan 11 '12 at 19:38

1

@taffer, it is. The transactions have the same effect as the journal does in other filesystems: they protect the fs metadata. In theory they can be used by applications in the way you describe, but there is currently no api to allow applications to open and close transactions.
–
psusiJan 12 '12 at 20:31

I am using ReiserFS for this task, it is especially made for handling a lot of small files. There is an easy to read text about it at the funtoo wiki.

ReiserFS also has a host of features aimed specifically at improving small file performance. Unlike ext2, ReiserFS doesn't allocate storage space in fixed one k or four k blocks. Instead, it can allocate the exact size it needs.

XFS is noted for performing very well in situations like this. This is part of why we use it at my work for our mail stores (that can contain hundreds of thousands of files in 1 directory).
It has better fault tolerance than ReiserFS, is in much wider use, and is generally a very mature filesystem.

Additionally, XFS supports online defragmentation. Though it does use a delayed allocation technique which results in less fragmentation (vs other filesystems) to begin with.

XFS is noted for performing very well in situations like this. [citation needed]
–
tafferJan 14 '12 at 16:13

Ehm, xfs is especially known for the opposite: working really well with big files, but not that well on small ones! Look at this exhaustive benchmark for example (or jump right to the conclusion on page 10 ^^): ilsistemista.net/index.php/linux-a-unix/…
–
LevitJul 2 '14 at 12:51

@Levit I think you're misreading that report. The report very clearly shows that XFS performs very well for random IO. But that aside, the report does not address the type of scenario in this question, lots of files. Random IO is one thing, large numbers of files is where ext* falls on its face.
–
PatrickJul 2 '14 at 13:26

Sry, I don't wanna make a discussion here, but if you look through the benches you see that pattern or just look at the closing statement on page 10 of this article stating for large file installation (as VM hosting system) or direct I/O, go with XFS .... which is where it really shines. I don't say it is extremely terrible with small files, but surely not ideal for it!
–
LevitJul 2 '14 at 13:34

@Levit See page 4 & page 7. You should always look at the data someone uses to arrive at their conclusion, and never trust the conclusion by itself.
–
PatrickJul 2 '14 at 15:22