directory lease handling perf bug

Steve French smfrench at gmail.com
Tue Apr 8 22:08:02 UTC 2025


In doing some additional testing of directory leases to Samba, I
noticed that to various servers (not just Samba) we are not caching
directory contents (e.g. a pattern like "ls /mnt ; ls /mnt") even
though we are getting the directory lease.   Digging deeper into this,
I noticed a performance bug -
e.g. look at this function in readdir.c: called from cifs_readdir() for "ls"

static void finished_cached_dirents_count(struct cached_dirents *cde,
                                        struct dir_context *ctx)
{
        if (cde->ctx != ctx)
                return;
        if (cde->is_valid || cde->is_failed)
                return;
        if (ctx->pos != cde->pos)
                return;

        cde->is_valid = 1;
}

The dir_context passed into cifs_readdir() never seems to match the
cached dir_ctxt pointer so we won't set cde->is_valid. On each call to
cifs_readdir (for the same directory) it looks like ctx is different.
 This doesn't break any tests but it seems like a huge hit for
performance that we are incorrectly checking whether to cache the
directory.   I couldn't find a recent change that broke this, but it
looks like it will be a HUGE help to perf when we fix this.

--
Thanks,

Steve



More information about the samba-technical mailing list