From: Jeff Layton <jlayton@xxxxxxxxxx>> >On Fri, 2025-08-08 at 17:22 +0000, Charles Hedrick wrote: >> In the past we've seen high CPU in cases where we had a very large number of subdirectories in a directory. This was due to the cost of reconnecting them. >> >> In a patch March 9 in Centos 9, "ovl: do not try to reconnect a disconnected origin dentry", an optimization was made to avoid this, but it was only implemented for overlay. Would it make sense to do the same thing in nfsd? >> >> in nfsfs.c, it would change the call to exportfs_decode_fh_raw so that when to pass >> exp->ex_flags & NFSEXP_NOSUBTREECHECK ? NULL : nfsd_acceptable, since nfsd_acceptable will always return true if NOSUBTREECHECK is set. > >Can that function cope with a disconnected dir dentry? Note this a >little while later in the function: > > if (d_is_dir(dentry) && > (dentry->d_flags & DCACHE_DISCONNECTED)) { > printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %pd2\n", > dentry); > } > >...so I imagine such a change will make that printk pop a lot more. Probably not. Sorry for not checking further. There are too many uses of dentry in the nfsd code for me to check all of them. Although I can't find the code that does it, my concern is that permission checking would probably not be possible without the full tree. The real performance problem is exportfs_get_name in reconnect_one. If you have a directory with a very large number of subdirectories, they are in the cache on a client, but not in the dnode cache on the server, then processing all the subdirectories becomes an N**2 problem, because each subdirectory has to be looked up by a linear search in the parent. I don't know the code, so it's a bit unclear to me why the get_name followed by lookup is done. Is it to make sure that the file is still in the parent directory? Could you do the same thing in the special case where the file is a subdirectory by checking that .. is still the parent? Unfortunately some of our users have exactly this pattern. Many AI training sets have a subdirectory per item, with two things in it, the item and a file of metadata.