UFS dirhash has a limit on how much memory is used to prevent runaway
allocations. I believe the default limit (2MB) is rather conservative.
It was picked to avoid causing trouble back when machines were tiny and
dirhash was new.

For example, a maildir with 100K files takes about 3MB of memory. Because
this is over the current limit, we will fall back to linear search. This has a
detrimental impact on system wide performance.

I picked a new limit of 5MB. This allows for my one very large directory, a
few additional directories, and some spare room. It's also still reasonably
conservative imo.

One can always change the default via sysctl, which is what I've done locally,
but I think increasing the default will reduce surprises in the future. And
for people with only small directories, there's no change. The increased limit
won't be used.


Index: ufs_dirhash.c
===================================================================
RCS file: /cvs/src/sys/ufs/ufs/ufs_dirhash.c,v
retrieving revision 1.40
diff -u -p -r1.40 ufs_dirhash.c
--- ufs_dirhash.c       26 Oct 2017 02:38:54 -0000      1.40
+++ ufs_dirhash.c       20 Feb 2019 21:48:09 -0000
@@ -1057,7 +1057,7 @@ ufsdirhash_init(void)
        rw_init(&ufsdirhash_mtx, "dirhash_list");
        arc4random_buf(&ufsdirhash_key, sizeof(ufsdirhash_key));
        TAILQ_INIT(&ufsdirhash_list);
-       ufs_dirhashmaxmem = 2 * 1024 * 1024;
+       ufs_dirhashmaxmem = 5 * 1024 * 1024;
        ufs_mindirhashsize = 5 * DIRBLKSIZ;
 }
 

Reply via email to