get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2229732/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2229732,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2229732/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-18-sprasad@microsoft.com/",
    "project": {
        "id": 12,
        "url": "http://patchwork.ozlabs.org/api/1.1/projects/12/?format=api",
        "name": "Linux CIFS Client",
        "link_name": "linux-cifs-client",
        "list_id": "linux-cifs.vger.kernel.org",
        "list_email": "linux-cifs@vger.kernel.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260428160804.281745-18-sprasad@microsoft.com>",
    "date": "2026-04-28T16:08:03",
    "name": "[v3,18/19] cifs: keep cfids in rbtree for efficient lookups",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "dcd43f711ed7d4fb6ddb40cb5a2b7da95f0290dc",
    "submitter": {
        "id": 79368,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/79368/?format=api",
        "name": "Shyam Prasad N",
        "email": "nspmangalore@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-18-sprasad@microsoft.com/mbox/",
    "series": [
        {
            "id": 501896,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/501896/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501896",
            "date": "2026-04-28T16:07:57",
            "name": "[v3,01/19] cifs: change_conf needs to be called for session setup",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/501896/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2229732/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2229732/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "\n <linux-cifs+bounces-11256-incoming=patchwork.ozlabs.org@vger.kernel.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "linux-cifs@vger.kernel.org"
        ],
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=Tso/BtqV;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11256-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)",
            "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"Tso/BtqV\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.179",
            "smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com",
            "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"
        ],
        "Received": [
            "from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4mNs6Fl7z1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 02:39:25 +1000 (AEST)",
            "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 523C9319A2C5\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 16:14:51 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 1C60344D033;\n\tTue, 28 Apr 2026 16:08:41 +0000 (UTC)",
            "from mail-pl1-f179.google.com (mail-pl1-f179.google.com\n [209.85.214.179])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 04C1144D696\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 16:08:36 +0000 (UTC)",
            "by mail-pl1-f179.google.com with SMTP id\n d9443c01a7336-2a8fba3f769so52131095ad.2\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 09:08:36 -0700 (PDT)",
            "from sprasad-dev1.corp.microsoft.com ([167.220.110.216])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b97ac7894csm30864465ad.50.2026.04.28.09.08.35\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 09:08:35 -0700 (PDT)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777392521; cv=none;\n b=jL1m+/CWAolXHnqw7AYK4KMHWNwcW6P+lRY5Rg5+SkW8T6PtcDva0SWAjl0iqJcR4hOUCtWxe3zO9lnSb3xpZWikQW2kuApdqR+dvxoyLbCyN8fcRdvpehQwrnLq0CQCLKD6it6KfbioDPObXnfhVNP/ZHVjSa7uh4FoENoUlYY=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777392521; c=relaxed/simple;\n\tbh=o0N32qWfdGxLwXjkbDqAtu2/BBJadb3qdMdCxb+FO28=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=tYMc6zPGSV6XwPqL+x9FMQu6rUlpZVKGcy8TxCkee/0tcDgVILgqNicO/pRs1u2ZZUjCEjoL29lcRguxzTDAAhHWZ2hPqTfGqhvGlCD8RlDSWwUH3LXHTMXGAtbMHD2X0IWXppWxA4Fx7XbeBVKHK+DHt5hM552BF0c/W3zJAJI=",
        "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=Tso/BtqV; arc=none smtp.client-ip=209.85.214.179",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777392516; x=1777997316;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=pGsmBdudK7tseR2Ysem6WDL8rrBZQlqIDRvGpYGz1FQ=;\n        b=Tso/BtqVI9L+PSnCNWMhO9/oEcHJPrW/qt3WJlJ7MXfztxPfVUBo+P1+I/pmtcHqVb\n         bfehlm+/Hce7mVv+4fN8Sf2TY1pQHhzfTPfqVtnn5cWxqhpD9mhpoO7k1S159qtNL3KM\n         FkQXGBm9N/PpjnV37LJNWWE7sxoFgomkUJn789M5C8kzf7a+R5plPg3FFIegyyTWRR82\n         v/wT622oy7HshHk/cNFiGZMwtoSRi+dXPJ2JXA4bio1KKjeLWFVuXhpn1Oe84T/dfkQ3\n         Jy26rr4hPicwPnC6DTdvzqIliVqBTQlm4dEMj9WL5gUd85/oBl2C+ZfKstIspew6SgzT\n         U+Dg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777392516; x=1777997316;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=pGsmBdudK7tseR2Ysem6WDL8rrBZQlqIDRvGpYGz1FQ=;\n        b=j0TZL4kP2a7udIKDZYnmzw6+q1s/FO7yrkNNlhBV8yBjVZNKfyqX9E1YETxgQkgcbR\n         BTV9UZSyMHFOLPeBSJ8DxjHXBtCuC4b38v0z+2kTXszNwskbyF6i8884Fpj6jjPqKXLx\n         d4F3Jcc25UX3HMa0S7m57Kz7b+2xkKXihrVjFYSOxv3CrXoss1dUKzsBDF34weK24cvf\n         JDIvd+ch+V3Lc6D2V5TBIJ+UGVXQEqThUV4PzNTWnz3xewTWlVBbZPTKO0ymvcM+07Eh\n         rSeXWOdAMBFjvnffaJ8KdzOvM+9yJJZslHUW8Npd4TSXU0yD8E3iCW8rNRpv9JnrBWgK\n         q9Ig==",
        "X-Gm-Message-State": "AOJu0YzZu2SPj1+dc1tH5NxOe9NCwQDcEKkhRPYEfdqXtfrbEPl2Vbes\n\tiypYyXWg+EuzriETvlClHTlqvaL/4vlx6RuIuZSjtEl3ou/WZ8y0I5luKrUubqM7GOs=",
        "X-Gm-Gg": "AeBDievk557PtTVNCvPgPQiGUr/teG20TRGRhVbTM1u3/32OlVNI1WG1/C2bJvGjqq7\n\tbRmXitLCS6SYM1LtCdr+YVU2JDS0MRUhgpdnHmtVBXPQymTJhJf2D05crKKgkEjRNH7BbBcG02o\n\tYiC8GfOjTrnkeskQrzAizAbTxUWdMQl+9R6MvAXHn4iTi+uy48KMJHs+RzlmYBV1gEytzHs8bVS\n\tCA/q9iTQXPtk+fcjIL24C/iKlbhzSlDeEFAxYbwDTZbyrCUHbbs1DLcVx5dEiaPyAs1U6vdcdtP\n\tdZjfqHjV+tsXbI0pFrGUiqnefrQ0eAx/m47QXFgAHhVCg7ExF+mfT0/PQp7Q0dQ0dg2/7wfbMXq\n\tjiE4uiwuQuouieb/BJ3JoGKSP+ct2Sllj72f535GOHrJTnJ73IFyXeLOXT24+1ftnEa2ty0dMn8\n\t0Sphixk4BOEIXo9BagYxHW5W0RqaRkmek8PeUuV1t6Dtq/gtvRWd8InXLCk79X9h/T",
        "X-Received": "by 2002:a17:903:11d0:b0:2ae:6192:8d78 with SMTP id\n d9443c01a7336-2b97c3df3d6mr38582335ad.1.1777392515819;\n        Tue, 28 Apr 2026 09:08:35 -0700 (PDT)",
        "From": "nspmangalore@gmail.com",
        "X-Google-Original-From": "sprasad@microsoft.com",
        "To": "linux-cifs@vger.kernel.org,\n\tsmfrench@gmail.com,\n\tpc@manguebit.org,\n\tbharathsm@microsoft.com,\n\tdhowells@redhat.com,\n\thenrique.carvalho@suse.com,\n\tematsumiya@suse.de",
        "Cc": "Shyam Prasad N <sprasad@microsoft.com>",
        "Subject": "[PATCH v3 18/19] cifs: keep cfids in rbtree for efficient lookups",
        "Date": "Tue, 28 Apr 2026 21:38:03 +0530",
        "Message-ID": "<20260428160804.281745-18-sprasad@microsoft.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20260428160804.281745-1-sprasad@microsoft.com>",
        "References": "<20260428160804.281745-1-sprasad@microsoft.com>",
        "Precedence": "bulk",
        "X-Mailing-List": "linux-cifs@vger.kernel.org",
        "List-Id": "<linux-cifs.vger.kernel.org>",
        "List-Subscribe": "<mailto:linux-cifs+subscribe@vger.kernel.org>",
        "List-Unsubscribe": "<mailto:linux-cifs+unsubscribe@vger.kernel.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit"
    },
    "content": "From: Shyam Prasad N <sprasad@microsoft.com>\n\nToday tcon->cfids are maintained as a linked list. When we do\nnot limit the number of cfids (limited by system memory), this\ncan be a problem if the mount has a large number of active dir\naccesses. We soon start hitting perf bottlenecks.\n\nThis change stores cfids in a rbtree instead of a linked list.\nThe nodes of this tree are keyed based on the path inside the tcon.\n\nAdditionally, for faster lookups by dentry, introducing a hashtable\nto allow lookups of cfids by dentry faster. This is important\nsince open_cached_dir_by_dentry is called quite frequently.\n\nSigned-off-by: Shyam Prasad N <sprasad@microsoft.com>\n---\n fs/smb/client/cached_dir.c | 227 ++++++++++++++++++++++++++-----------\n fs/smb/client/cached_dir.h |   8 +-\n fs/smb/client/cifs_debug.c |   4 +-\n 3 files changed, 172 insertions(+), 67 deletions(-)",
    "diff": "diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c\nindex 6fb88c4c97dc1..14c87ac1a4ad4 100644\n--- a/fs/smb/client/cached_dir.c\n+++ b/fs/smb/client/cached_dir.c\n@@ -22,6 +22,7 @@ static void smb2_close_cached_fid(struct kref *ref);\n static void cfids_laundromat_worker(struct work_struct *work);\n \n #define CACHED_DIRENT_HASH_BITS\t7\n+#define CACHED_DIR_DENTRY_HT_BITS\t8\n \n struct cached_dir_dentry {\n \tstruct list_head entry;\n@@ -1240,6 +1241,57 @@ int cifs_wait_for_pending_dcache(struct cached_fid *cfid,\n \treturn ret;\n }\n \n+static struct cached_fid *cfid_rb_find(struct rb_root *root, const char *path)\n+{\n+\tstruct rb_node *node = root->rb_node;\n+\n+\twhile (node) {\n+\t\tstruct cached_fid *cfid = rb_entry(node, struct cached_fid, node);\n+\t\tint cmp = strcmp(path, cfid->path);\n+\n+\t\tif (cmp < 0)\n+\t\t\tnode = node->rb_left;\n+\t\telse if (cmp > 0)\n+\t\t\tnode = node->rb_right;\n+\t\telse\n+\t\t\treturn cfid;\n+\t}\n+\treturn NULL;\n+}\n+\n+static struct cached_fid *cfid_dentry_ht_find(struct cached_fids *cfids,\n+\t\t\t\t\t      struct dentry *dentry)\n+{\n+\tstruct cached_fid *cfid;\n+\n+\thlist_for_each_entry(cfid,\n+\t\t\t     &cfids->dentry_ht[hash_ptr(dentry, CACHED_DIR_DENTRY_HT_BITS)],\n+\t\t\t     dentry_node) {\n+\t\tif (cfid->dentry == dentry)\n+\t\t\treturn cfid;\n+\t}\n+\treturn NULL;\n+}\n+\n+static void cfid_rb_insert(struct rb_root *root, struct cached_fid *new)\n+{\n+\tstruct rb_node **link = &root->rb_node;\n+\tstruct rb_node *parent = NULL;\n+\n+\twhile (*link) {\n+\t\tstruct cached_fid *cfid = rb_entry(*link, struct cached_fid, node);\n+\t\tint cmp = strcmp(new->path, cfid->path);\n+\n+\t\tparent = *link;\n+\t\tif (cmp < 0)\n+\t\t\tlink = &(*link)->rb_left;\n+\t\telse\n+\t\t\tlink = &(*link)->rb_right;\n+\t}\n+\trb_link_node(&new->node, parent, link);\n+\trb_insert_color(&new->node, root);\n+}\n+\n static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,\n \t\t\t\t\t\t    const char *path,\n \t\t\t\t\t\t    bool lookup_only,\n@@ -1247,22 +1299,21 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,\n {\n \tstruct cached_fid *cfid;\n \n-\tlist_for_each_entry(cfid, &cfids->entries, entry) {\n-\t\tif (!strcmp(cfid->path, path)) {\n-\t\t\t/*\n-\t\t\t * If it doesn't have a lease it is either not yet\n-\t\t\t * fully cached or it may be in the process of\n-\t\t\t * being deleted due to a lease break.\n-\t\t\t */\n-\t\t\tspin_lock(&cfid->cfid_lock);\n-\t\t\tif (!is_valid_cached_dir(cfid)) {\n-\t\t\t\tspin_unlock(&cfid->cfid_lock);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\tkref_get(&cfid->refcount);\n+\tcfid = cfid_rb_find(&cfids->entries, path);\n+\tif (cfid) {\n+\t\t/*\n+\t\t * If it doesn't have a lease it is either not yet\n+\t\t * fully cached or it may be in the process of\n+\t\t * being deleted due to a lease break.\n+\t\t */\n+\t\tspin_lock(&cfid->cfid_lock);\n+\t\tif (!is_valid_cached_dir(cfid)) {\n \t\t\tspin_unlock(&cfid->cfid_lock);\n-\t\t\treturn cfid;\n+\t\t\treturn NULL;\n \t\t}\n+\t\tkref_get(&cfid->refcount);\n+\t\tspin_unlock(&cfid->cfid_lock);\n+\t\treturn cfid;\n \t}\n \tif (lookup_only) {\n \t\treturn NULL;\n@@ -1276,7 +1327,7 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,\n \t}\n \tcfid->cfids = cfids;\n \tcfids->num_entries++;\n-\tlist_add(&cfid->entry, &cfids->entries);\n+\tcfid_rb_insert(&cfids->entries, cfid);\n \tcfid->on_list = true;\n \tkref_get(&cfid->refcount);\n \t/*\n@@ -1458,26 +1509,30 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,\n \t\t\tstruct cached_fid *parent_cfid;\n \n \t\t\tspin_lock(&cfids->cfid_list_lock);\n-\t\t\tlist_for_each_entry(parent_cfid, &cfids->entries, entry) {\n+\t\t\thlist_for_each_entry(parent_cfid,\n+\t\t\t\t\t     &cfids->dentry_ht[hash_ptr(dentry->d_parent,\n+\t\t\t\t\t\t\t\tCACHED_DIR_DENTRY_HT_BITS)],\n+\t\t\t\t\t     dentry_node) {\n+\t\t\t\tif (parent_cfid->dentry != dentry->d_parent)\n+\t\t\t\t\tcontinue;\n \t\t\t\tspin_lock(&parent_cfid->cfid_lock);\n-\t\t\t\tif (parent_cfid->dentry == dentry->d_parent) {\n-\t\t\t\t\tcifs_dbg(FYI, \"found a parent cached file handle\\n\");\n-\t\t\t\t\tif (is_valid_cached_dir(parent_cfid)) {\n-\t\t\t\t\t\tlease_flags\n-\t\t\t\t\t\t\t|= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE;\n-\t\t\t\t\t\tmemcpy(pfid->parent_lease_key,\n-\t\t\t\t\t\t       parent_cfid->fid.lease_key,\n-\t\t\t\t\t\t       SMB2_LEASE_KEY_SIZE);\n-\t\t\t\t\t}\n-\t\t\t\t\tspin_unlock(&parent_cfid->cfid_lock);\n-\t\t\t\t\tbreak;\n+\t\t\t\tcifs_dbg(FYI, \"found a parent cached file handle\\n\");\n+\t\t\t\tif (is_valid_cached_dir(parent_cfid)) {\n+\t\t\t\t\tlease_flags\n+\t\t\t\t\t\t|= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE;\n+\t\t\t\t\tmemcpy(pfid->parent_lease_key,\n+\t\t\t\t\t       parent_cfid->fid.lease_key,\n+\t\t\t\t\t       SMB2_LEASE_KEY_SIZE);\n \t\t\t\t}\n \t\t\t\tspin_unlock(&parent_cfid->cfid_lock);\n+\t\t\t\tbreak;\n \t\t\t}\n \t\t\tspin_unlock(&cfids->cfid_list_lock);\n \t\t}\n \t}\n \tcfid->dentry = dentry;\n+\thlist_add_head(&cfid->dentry_node,\n+\t\t       &cfids->dentry_ht[hash_ptr(dentry, CACHED_DIR_DENTRY_HT_BITS)]);\n \tcfid->tcon = tcon;\n \n \t/*\n@@ -1630,7 +1685,9 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,\n \n \t\tspin_lock(&cfids->cfid_list_lock);\n \t\tif (cfid->on_list) {\n-\t\t\tlist_del(&cfid->entry);\n+\t\t\tif (cfid->dentry)\n+\t\t\t\thlist_del_init(&cfid->dentry_node);\n+\t\t\trb_erase(&cfid->node, &cfids->entries);\n \t\t\tcfid->on_list = false;\n \t\t\tcfids->num_entries--;\n \t\t}\n@@ -1674,26 +1731,28 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,\n \t\treturn -ENOENT;\n \n \tspin_lock(&cfids->cfid_list_lock);\n-\tlist_for_each_entry(cfid, &cfids->entries, entry) {\n-\t\tif (cfid->dentry == dentry) {\n-\t\t\tspin_lock(&cfid->cfid_lock);\n-\t\t\tif (!is_valid_cached_dir(cfid)) {\n-\t\t\t\tspin_unlock(&cfid->cfid_lock);\n-\t\t\t\trc = -ENOENT;\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t\tcifs_dbg(FYI, \"found a cached file handle by dentry\\n\");\n-\t\t\tkref_get(&cfid->refcount);\n-\t\t\t*ret_cfid = cfid;\n-\t\t\tcfid->last_access_time = jiffies;\n-\t\t\trc = 0;\n-\t\t\ttrace_cfid = cfid;\n+\tcfid = cfid_dentry_ht_find(cfids, dentry);\n+\tif (cfid) {\n+\t\tspin_lock(&cfid->cfid_lock);\n+\t\tif (!is_valid_cached_dir(cfid)) {\n \t\t\tspin_unlock(&cfid->cfid_lock);\n \t\t\tspin_unlock(&cfids->cfid_list_lock);\n-\t\t\ttrace_smb3_open_cached_dir_by_dentry(cfid, dentry->d_name.name,\n-\t\t\t\t\t\t\t dentry->d_name.len, 0);\n+\t\t\ttrace_smb3_open_cached_dir_by_dentry(cfid,\n+\t\t\t\t\t   dentry->d_name.name,\n+\t\t\t\t\t   dentry->d_name.len, rc);\n \t\t\treturn rc;\n \t\t}\n+\t\tcifs_dbg(FYI, \"found a cached file handle by dentry\\n\");\n+\t\tkref_get(&cfid->refcount);\n+\t\t*ret_cfid = cfid;\n+\t\tcfid->last_access_time = jiffies;\n+\t\trc = 0;\n+\t\tspin_unlock(&cfid->cfid_lock);\n+\t\tspin_unlock(&cfids->cfid_list_lock);\n+\t\ttrace_smb3_open_cached_dir_by_dentry(cfid,\n+\t\t\t\t   dentry->d_name.name,\n+\t\t\t\t   dentry->d_name.len, rc);\n+\t\treturn rc;\n \t}\n \tspin_unlock(&cfids->cfid_list_lock);\n \ttrace_smb3_open_cached_dir_by_dentry(NULL, dentry->d_name.name,\n@@ -1715,7 +1774,9 @@ __releases(&cfid->cfids->cfid_list_lock)\n \tlockdep_assert_held(&cfid->cfids->cfid_list_lock);\n \n \tif (cfid->on_list) {\n-\t\tlist_del(&cfid->entry);\n+\t\tif (cfid->dentry)\n+\t\t\thlist_del_init(&cfid->dentry_node);\n+\t\trb_erase(&cfid->node, &cfid->cfids->entries);\n \t\tcfid->on_list = false;\n \t\tcfid->cfids->num_entries--;\n \t}\n@@ -1790,6 +1851,7 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)\n {\n \tstruct rb_root *root = &cifs_sb->tlink_tree;\n \tstruct rb_node *node;\n+\tstruct rb_node *cfid_node;\n \tstruct cached_fid *cfid;\n \tstruct cifs_tcon *tcon;\n \tstruct tcon_link *tlink;\n@@ -1807,7 +1869,9 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)\n \t\tif (cfids == NULL)\n \t\t\tcontinue;\n \t\tspin_lock(&cfids->cfid_list_lock);\n-\t\tlist_for_each_entry(cfid, &cfids->entries, entry) {\n+\t\tfor (cfid_node = rb_first(&cfids->entries);\n+\t\t     cfid_node; cfid_node = rb_next(cfid_node)) {\n+\t\t\tcfid = rb_entry(cfid_node, struct cached_fid, node);\n \t\t\ttmp_list = kmalloc_obj(*tmp_list, GFP_ATOMIC);\n \t\t\tif (tmp_list == NULL) {\n \t\t\t\t/*\n@@ -1823,6 +1887,7 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)\n \n \t\t\tspin_lock(&cfid->cfid_lock);\n \t\t\ttmp_list->dentry = cfid->dentry;\n+\t\t\thlist_del_init(&cfid->dentry_node);\n \t\t\tcfid->dentry = NULL;\n \t\t\tspin_unlock(&cfid->cfid_lock);\n \n@@ -1850,7 +1915,8 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)\n void invalidate_all_cached_dirs_nowait(struct cifs_tcon *tcon)\n {\n \tstruct cached_fids *cfids = tcon->cfids;\n-\tstruct cached_fid *cfid, *q;\n+\tstruct cached_fid *cfid;\n+\tstruct rb_node *rb_node = NULL, *next_node = NULL;\n \n \tif (cfids == NULL)\n \t\treturn;\n@@ -1861,8 +1927,14 @@ void invalidate_all_cached_dirs_nowait(struct cifs_tcon *tcon)\n \t * during this process.\n \t */\n \tspin_lock(&cfids->cfid_list_lock);\n-\tlist_for_each_entry_safe(cfid, q, &cfids->entries, entry) {\n-\t\tlist_move(&cfid->entry, &cfids->dying);\n+\tfor (rb_node = rb_first(&cfids->entries);\n+\t     rb_node; rb_node = next_node) {\n+\t\tnext_node = rb_next(rb_node);\n+\t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n+\t\tif (cfid->dentry)\n+\t\t\thlist_del_init(&cfid->dentry_node);\n+\t\trb_erase(rb_node, &cfids->entries);\n+\t\tlist_add(&cfid->dying_entry, &cfids->dying);\n \t\tcfids->num_entries--;\n \t\tspin_lock(&cfid->cfid_lock);\n \t\tcfid->is_open = false;\n@@ -1939,7 +2011,9 @@ bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16])\n \t\treturn false;\n \n \tspin_lock(&cfids->cfid_list_lock);\n-\tlist_for_each_entry(cfid, &cfids->entries, entry) {\n+\tfor (struct rb_node *rb_node = rb_first(&cfids->entries);\n+\t     rb_node; rb_node = rb_next(rb_node)) {\n+\t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n \t\tspin_lock(&cfid->cfid_lock);\n \t\tif (cfid->has_lease &&\n \t\t    !memcmp(lease_key,\n@@ -1952,7 +2026,9 @@ bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16])\n \t\t\t * We found a lease remove it from the list\n \t\t\t * so no threads can access it.\n \t\t\t */\n-\t\t\tlist_del(&cfid->entry);\n+\t\t\tif (cfid->dentry)\n+\t\t\t\thlist_del_init(&cfid->dentry_node);\n+\t\t\trb_erase(rb_node, &cfids->entries);\n \t\t\tcfid->on_list = false;\n \t\t\tcfids->num_entries--;\n \n@@ -1984,7 +2060,9 @@ static struct cached_fid *init_cached_dir(const char *path)\n \n \tINIT_WORK(&cfid->close_work, cached_dir_offload_close);\n \tINIT_WORK(&cfid->put_work, cached_dir_put_work);\n-\tINIT_LIST_HEAD(&cfid->entry);\n+\tRB_CLEAR_NODE(&cfid->node);\n+\tINIT_HLIST_NODE(&cfid->dentry_node);\n+\tINIT_LIST_HEAD(&cfid->dying_entry);\n \tINIT_LIST_HEAD(&cfid->dirents.entry_list);\n \tmutex_init(&cfid->dirents.de_mutex);\n \tmutex_init(&cfid->cfid_open_mutex);\n@@ -2039,14 +2117,20 @@ static void cfids_laundromat_worker(struct work_struct *work)\n \n \tspin_lock(&cfids->cfid_list_lock);\n \t/* move cfids->dying to the local list */\n-\tlist_cut_before(&entry, &cfids->dying, &cfids->dying);\n+\tlist_splice_init(&cfids->dying, &entry);\n \n-\tlist_for_each_entry_safe(cfid, q, &cfids->entries, entry) {\n+\tfor (struct rb_node *rb_node = rb_first(&cfids->entries), *next_node;\n+\t     rb_node; rb_node = next_node) {\n+\t\tnext_node = rb_next(rb_node);\n+\t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n \t\tspin_lock(&cfid->cfid_lock);\n \t\tif (dir_cache_timeout && cfid->last_access_time &&\n \t\t    time_after(jiffies, cfid->last_access_time + HZ * dir_cache_timeout)) {\n \t\t\tcfid->on_list = false;\n-\t\t\tlist_move(&cfid->entry, &entry);\n+\t\t\tif (cfid->dentry)\n+\t\t\t\thlist_del_init(&cfid->dentry_node);\n+\t\t\trb_erase(rb_node, &cfids->entries);\n+\t\t\tlist_add(&cfid->dying_entry, &entry);\n \t\t\tcfids->num_entries--;\n \t\t\tif (cfid->has_lease) {\n \t\t\t\t/*\n@@ -2065,8 +2149,8 @@ static void cfids_laundromat_worker(struct work_struct *work)\n \t}\n \tspin_unlock(&cfids->cfid_list_lock);\n \n-\tlist_for_each_entry_safe(cfid, q, &entry, entry) {\n-\t\tlist_del(&cfid->entry);\n+\tlist_for_each_entry_safe(cfid, q, &entry, dying_entry) {\n+\t\tlist_del(&cfid->dying_entry);\n \n \t\tdput(cfid->dentry);\n \t\tcfid->dentry = NULL;\n@@ -2098,7 +2182,13 @@ struct cached_fids *init_cached_dirs(void)\n \tif (!cfids)\n \t\treturn NULL;\n \tspin_lock_init(&cfids->cfid_list_lock);\n-\tINIT_LIST_HEAD(&cfids->entries);\n+\tcfids->entries = RB_ROOT;\n+\tcfids->dentry_ht = kcalloc(1 << CACHED_DIR_DENTRY_HT_BITS,\n+\t\t\t\t   sizeof(*cfids->dentry_ht), GFP_KERNEL);\n+\tif (!cfids->dentry_ht) {\n+\t\tkfree(cfids);\n+\t\treturn NULL;\n+\t}\n \tINIT_LIST_HEAD(&cfids->dying);\n \n \tINIT_DELAYED_WORK(&cfids->laundromat_work, cfids_laundromat_worker);\n@@ -2126,25 +2216,34 @@ void free_cached_dirs(struct cached_fids *cfids)\n \n \tcancel_delayed_work_sync(&cfids->laundromat_work);\n \n+\tkfree(cfids->dentry_ht);\n+\tcfids->dentry_ht = NULL;\n+\n \tspin_lock(&cfids->cfid_list_lock);\n-\tlist_for_each_entry_safe(cfid, q, &cfids->entries, entry) {\n+\tfor (struct rb_node *rb_node = rb_first(&cfids->entries), *next_node;\n+\t     rb_node; rb_node = next_node) {\n+\t\tnext_node = rb_next(rb_node);\n+\t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n \t\tcfid->on_list = false;\n+\t\tif (cfid->dentry)\n+\t\t\thlist_del_init(&cfid->dentry_node);\n \t\tspin_lock(&cfid->cfid_lock);\n \t\tcfid->is_open = false;\n \t\tspin_unlock(&cfid->cfid_lock);\n-\t\tlist_move(&cfid->entry, &entry);\n+\t\trb_erase(rb_node, &cfids->entries);\n+\t\tlist_add(&cfid->dying_entry, &entry);\n \t}\n-\tlist_for_each_entry_safe(cfid, q, &cfids->dying, entry) {\n+\tlist_for_each_entry_safe(cfid, q, &cfids->dying, dying_entry) {\n \t\tcfid->on_list = false;\n \t\tspin_lock(&cfid->cfid_lock);\n \t\tcfid->is_open = false;\n \t\tspin_unlock(&cfid->cfid_lock);\n-\t\tlist_move(&cfid->entry, &entry);\n+\t\tlist_move(&cfid->dying_entry, &entry);\n \t}\n \tspin_unlock(&cfids->cfid_list_lock);\n \n-\tlist_for_each_entry_safe(cfid, q, &entry, entry) {\n-\t\tlist_del(&cfid->entry);\n+\tlist_for_each_entry_safe(cfid, q, &entry, dying_entry) {\n+\t\tlist_del(&cfid->dying_entry);\n \t\tfree_cached_dir(cfid);\n \t}\n \ndiff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h\nindex 0726f25b9144a..58dde9452ec9b 100644\n--- a/fs/smb/client/cached_dir.h\n+++ b/fs/smb/client/cached_dir.h\n@@ -11,6 +11,7 @@\n #include <linux/completion.h>\n #include <linux/build_bug.h>\n #include <linux/list.h>\n+#include <linux/rbtree.h>\n #include <linux/netfs.h>\n \n struct cifs_search_info;\n@@ -139,7 +140,9 @@ struct cached_dirents {\n };\n \n struct cached_fid {\n-\tstruct list_head entry;\n+\tstruct rb_node node;\n+\tstruct hlist_node dentry_node;\n+\tstruct list_head dying_entry;\n \tstruct cached_fids *cfids;\n \tconst char *path;\n \tbool has_lease;\n@@ -181,7 +184,8 @@ struct cached_fids {\n \t */\n \tspinlock_t cfid_list_lock;\n \tint num_entries;\n-\tstruct list_head entries;\n+\tstruct rb_root entries;\n+\tstruct hlist_head *dentry_ht;\n \tstruct list_head dying;\n \tstruct delayed_work laundromat_work;\n \t/* aggregate accounting for all cached dirents under this tcon */\ndiff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c\nindex cc7d26a3917c5..81908679a11e3 100644\n--- a/fs/smb/client/cifs_debug.c\n+++ b/fs/smb/client/cifs_debug.c\n@@ -326,7 +326,9 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)\n \t\t\t\t\t\tcfids->num_entries,\n \t\t\t\t\t\t(unsigned long)atomic_long_read(&cfids->total_dirents_entries),\n \t\t\t\t\t\t(unsigned long long)atomic64_read(&cfids->total_dirents_bytes));\n-\t\t\t\tlist_for_each_entry(cfid, &cfids->entries, entry) {\n+\t\t\t\tfor (struct rb_node *rb_node = rb_first(&cfids->entries);\n+\t\t\t\t     rb_node; rb_node = rb_next(rb_node)) {\n+\t\t\t\t\tcfid = rb_entry(rb_node, struct cached_fid, node);\n \t\t\t\t\tspin_lock(&cfid->cfid_lock);\n \t\t\t\t\tseq_printf(m, \"0x%x 0x%llx 0x%llx \",\n \t\t\t\t\t\ttcon->tid,\n",
    "prefixes": [
        "v3",
        "18/19"
    ]
}