Here’s a surprising “gotcha” for the filesystem btrfs…
You are very limited to the maximum number of hard links to a single file when the hard links and that one target file are all in the same directory. For hard links where the source and target are in different directories, the limit for btrfs is a more reasonable 2^32. Admittedly, having many hard links to a file in the same directory is a strange corner-case for operation, but still one that has been tripped over by real world users and could be a killer for certain applications.
See the kernel bug report: Number of supported hard links is very low – breaks real world software
Comments about this on the btrfs devs list include:
… the max link count on btrfs is 2^32. The lower limit is only in place on links to the same file in the same directory.
… the link count on subdirs being unrelated. The link count on btrfs directories is always one.
And this comment gives a good summary and comparison with other filesystems:
… I’ve made a quick test and managed to create many more links to the same file in the *same* directory on other filsystems:
XFS can do at least 100000, probably more;
Reiserfs did 64535;
ext3 managed to do 32000;
ext4 did 65000.While I agree it might be a bit stupid to create so many hardlinks to the same file on the same directory, this issue can be seen as one of “backward compatibility” with other widely used and established Linux filesystems.
Despite it being stupid or not, the fact is that I’ve seen some crazy stuff along the years working with Unix, so people will expect this kind of things to *not* break when they switch from their old filesystems to shiny new btrfs.
The fact being that this limit is way lower than on other filesystems (we’re talking 2 orders of magnitude, at best!), I too suggest that the limit should be increased. Not being critical, it might be done when some other features require a format change but, nonetheless, should be done for the sake of avoiding breakage on existing systems. …
The problem is:
… The max number of hard link is depend on total length of hard link names.
… The limit is imposed by the format of inode back references. We can get rid of the limit, but it requires a disk format change.
One (extreme) test fail case is:
… The number of links depends on the length of a filename.
Is _13_ (yes, thirteen) hardlinks in a directory a big number? I don’t think so. …
As of this post, the “last modified” for the bug report is “2010-07-27 07:16”. The maillist thread ended 2011-10-15.
What’s the latest?…
Certainly one to watch out for with any software that might make lots of repeated hard links to a file in the same directory. There’s some real world problem examples noted in that thread for such as: BackupPC (backups); nnmaildir mail backend in Gnus (an Emacs package for reading news and email); and a web archiver. Also, Bacula (backups) and Mutt (email client) are given as problem examples in a summary of the present status for using btrfs in the Ubuntu 12.10 release.
My own interest was tickled when considering a simple example for file deduplication on repeated identical datafiles collected from a scientific instrument (filenames differ, the contents change occasionally, from a proprietary data capture system)… For my example, having found out about this limit feature of btrfs, I now know to write my deduplication script in a different way to how I would have naturally written the script. That is slightly more messy but should work fine.
However, to my mind this is still a very unexpected limit when compared to other commonly used filesystems. There is no problem if it is either fixed, or if it is well publicized enough so that everyone knows about it to then program around it.
Simplest should be to fix the problem at source, even if the problem is for a very rare set of circumstances… (For example, it has cost me some time and has forced me to check that I am ok for how I use rsync for backups on various multiple systems!)
I wish good luck with the further development of btrfs!
Regards,
Martin
Update:
Patches to fix this have recently been posted 21/05/2012: “btrfs: extended inode refs”
How soon before they are tested and included?
Some further patches 07/06/2012 from Mark Fasheh:
btrfs-progs: Support for extended inode refs
The patches have been reviewed and look to be getting submitted:
btrfs: extended inode refs
The “btrfs extended inode refs” were patched nearly a year ago now (already!) and I’ve certainly given them a thorough testing for my rsync backups. And to think they were thought to be an “obscure corner case”… Filesystems seem to be full of surprises…
This maillist posting nicely summarizes the present state of play: some feedbacks seen on btrfs
All looks to be developing well but there is still some way to go yet for the developers to complete the features list. Note the “EXPERIMENTAL – under heavy development”. However, noting that, I’m using btrfs on various non-critical systems and for some of my backups and it all works very well for my usage case. Even so, always have a backup to hand!