{"id":2229708,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229708/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-12-sprasad@microsoft.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/projects/12/?format=json","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-12-sprasad@microsoft.com>","date":"2026-04-28T16:07:57","name":"[v3,12/19] cifs: register a shrinker to manage cached_dirents","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a42cc0ae9c4659f2bcb01e8df06fcea845a0043b","submitter":{"id":79368,"url":"http://patchwork.ozlabs.org/api/1.1/people/79368/?format=json","name":"Shyam Prasad N","email":"nspmangalore@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260428160804.281745-12-sprasad@microsoft.com/mbox/","series":[{"id":501896,"url":"http://patchwork.ozlabs.org/api/1.1/series/501896/?format=json","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/2229708/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229708/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11248-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=rWqqXbxr;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11248-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=\"rWqqXbxr\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.180","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 sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4m1G690Mz1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 02:22:26 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id CDFA03078408\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 16:14:39 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 2FBC944BC9F;\n\tTue, 28 Apr 2026 16:08:33 +0000 (UTC)","from mail-pl1-f180.google.com (mail-pl1-f180.google.com\n [209.85.214.180])\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 9FFBB44CF54\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 16:08:31 +0000 (UTC)","by mail-pl1-f180.google.com with SMTP id\n d9443c01a7336-2b7adb38d65so52854995ad.2\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 09:08:31 -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.29\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 09:08:29 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777392513; cv=none;\n b=Ty/S27PkznqJ933M+n4o66xYmLF0R04HgWDTeG4j348hOYMpgVGdWInzpomLdXo76WUKG4nOOskGq2xtWKiAOugLL7remTebTob2tJ2Qs35MgkhClU+2UPeftO45QyaVWGkgqOifeR4eCGt/yKG8/nQEdbrxEkIQ8YUvhh7wC3c=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777392513; c=relaxed/simple;\n\tbh=dqM+OIMm/FolEhXWiZwlX21e6UtqoaVlDP5evwvYHl4=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=ITahQfaJGy5/XLcEM7qXdTsc5ywnaswe0d7RKbAnnVY2JmkUQsUKJzp2FHeiKCh85yaTdp5fdyY3ZvylxahjTahenhYzplqQXdgYEQBnj86y/nxZ0VvATWhwEgPwrtT7QyjtE2s1aSDpHkLFyzg/IMYzEF2Dg0aWWsdisxlb5js=","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=rWqqXbxr; arc=none smtp.client-ip=209.85.214.180","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777392511; x=1777997311;\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=WzzvatsWQlTBCszh4aTpD+tIu471HTtNRSO4+Bzjhio=;\n        b=rWqqXbxrvjbe5AfR/jkbLhm5Yiw+ufmyKYbOUzZDcqiXvpsD2gxYL4YJgREzc9sGs7\n         BJfKFPldga2dZR1U1mREmsygKw7+4JIX8FQbG0dHAyGc+C0YhBUY0ZkaXeaojuiwi227\n         9x0X3i6Qpt+q7XH/7HIjIXHNYtBiPMIJhIGIIKmlT6oYxu8NGlnoxZb6Ou+yxQTdtot1\n         RmgFc5Bb3pqQQqe9MoDqp6hWvcfp58rtQYIsr89abSLkxO6yWFSo3KYC9x3KIEj+aDrx\n         s/mXNfOzQpy9vzcqJkOvQlCrksEP2GYW++Vd4Z7fKaaX0GyefAFB50bE1E8+EZGqSvmT\n         X0xg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777392511; x=1777997311;\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=WzzvatsWQlTBCszh4aTpD+tIu471HTtNRSO4+Bzjhio=;\n        b=Jn/+0v7jUqA0ql/4Eyz+VCPs2JuIR1JOdea9LvNqGRBk9lmvya1e2cLsPKqBzujiO1\n         nC8JiImFEeBzfvlOdsM9eiANcVejI/tLYbUv/Eft1eNC12l0SaOmQR+weJJfcXcX6JJQ\n         Jfw/DOQfiWPHmIFhPNY7hYUPWH8obe6vNo0wI213yJbOw3/n/YnbF7xqEhPVeZuor843\n         gpGf9MvVcy6q7qJ6ALguuLeg0fuVPFvWRKSxrB/qMgOvZGqK6FA7zKE+R1H5oSSNPfWJ\n         oUnvr+7IN/EyOxOwG42FCb1ZJq8SdMTDVritr9K1EFFeI7D3QYIwzqDrsV/YExHkc9ci\n         /RDQ==","X-Gm-Message-State":"AOJu0YyjY68IsJEmvswREWBzMP9aSUH6H4iH9Bp6maxMZP4cP6Dlt9zc\n\tKIU5aw/WbF6xDBThgO6OqllcDxTv4Vxf8Ki8S5iv5nGx1ZDPQiyfGGLpkrTBpd/StDM=","X-Gm-Gg":"AeBDietT/Vv/AlIFhuY7719bWSd5wq0mLTXSSTuU/HC9VSqygN2rJB2zLmkmQ8K3fmg\n\tGsvi6xkAi7PbcYABdbHPCb0cCKN+HaXqiU+1elgafJmFczXoPxuncoOagF5ln3uX/qxQmSCyL/9\n\tqyAm0WzR5iUUzZ9F09vyvuiHeqB0mwaco2RdhktSVXdGROUqF7kiA7jPml1x1PS6o0btLhzhWeP\n\t0YlYupX353eAIvWzkMy55vzRxvZzl2y7H9lhOuhae7JGzHdp28ljapJzn3opR4wCXRtlfCCOCp8\n\tqLP1Z0+teXGjBsfDrdWtiNQHBsAmv+ijz/P/xsyka5ewnlQ2p8wQRPWdlXRW4j3BLixD+l2ODtE\n\tf6/9lktWdlwC0IR7iAykx3gc/KJr3023fbuGZACo0S634EEX0Hmw5inh0jL1s74Su8046npbK9/\n\tElgZ7SKGHASPVQRd0Kz1gyRcnE+nVOqvc/OgdsO3DCr00eq785FzRmoiK8gAsPbk3kLnfGPvcR0\n\t10=","X-Received":"by 2002:a17:903:1205:b0:2b2:4f43:b48c with SMTP id\n d9443c01a7336-2b97c400b5amr37328515ad.14.1777392510463;\n        Tue, 28 Apr 2026 09:08:30 -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 12/19] cifs: register a shrinker to manage cached_dirents","Date":"Tue, 28 Apr 2026 21:37:57 +0530","Message-ID":"<20260428160804.281745-12-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\nSince the cached_dirents are now backed by folioq, we do not need\na timed cleanup of these cfids anymore. This change registers a\nshrinker with the mm layer for the dircache. If mm needs to free up\nmemory or flush the cache, it can inform cifs about this using the\nshrinker interface.\n\nSigned-off-by: Shyam Prasad N <sprasad@microsoft.com>\n---\n fs/smb/client/cifsfs.c | 86 +++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 80 insertions(+), 6 deletions(-)","diff":"diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c\nindex 32d0305a1239a..ee5de358e27f8 100644\n--- a/fs/smb/client/cifsfs.c\n+++ b/fs/smb/client/cifsfs.c\n@@ -29,6 +29,7 @@\n #include <linux/uuid.h>\n #include <linux/xattr.h>\n #include <linux/mm.h>\n+#include <linux/shrinker.h>\n #include <linux/key-type.h>\n #include <uapi/linux/magic.h>\n #include <net/ipv6.h>\n@@ -123,27 +124,86 @@ MODULE_PARM_DESC(dir_cache_timeout, \"Number of seconds to cache directory conten\n \t\t\t\t \"Range: 1 to 65000 seconds, 0 to disable caching dir contents\");\n /* Module-wide total cached dirents (in bytes) across all tcons */\n atomic64_t cifs_dircache_bytes_used = ATOMIC64_INIT(0);\n+static struct shrinker *cifs_dircache_shrinker;\n \n /*\n  * Write-only module parameter to drop all cached directory entries across\n  * all CIFS mounts. Echo a non-zero value to trigger.\n  */\n-static void cifs_drop_all_dir_caches(void)\n+static unsigned long cifs_drop_all_dir_caches(bool wait, unsigned long nr_to_free)\n {\n \tstruct TCP_Server_Info *server;\n \tstruct cifs_ses *ses;\n \tstruct cifs_tcon *tcon;\n+\tu64 before, after, freed_bytes = 0;\n+\tu64 target_bytes;\n+\n+\tbefore = atomic64_read(&cifs_dircache_bytes_used);\n+\tif (nr_to_free == ULONG_MAX)\n+\t\ttarget_bytes = U64_MAX;\n+\telse\n+\t\ttarget_bytes = (u64)nr_to_free * PAGE_SIZE;\n \n \tspin_lock(&cifs_tcp_ses_lock);\n \tlist_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {\n \t\tlist_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {\n \t\t\tif (cifs_ses_exiting(ses))\n \t\t\t\tcontinue;\n-\t\t\tlist_for_each_entry(tcon, &ses->tcon_list, tcon_list)\n-\t\t\t\tinvalidate_all_cached_dirs(tcon);\n+\t\t\tlist_for_each_entry(tcon, &ses->tcon_list, tcon_list) {\n+\t\t\t\tinvalidate_all_cached_dirs_nowait(tcon);\n+\t\t\t\tafter = atomic64_read(&cifs_dircache_bytes_used);\n+\t\t\t\tif (after < before)\n+\t\t\t\t\tfreed_bytes = before - after;\n+\t\t\t\tif (freed_bytes >= target_bytes)\n+\t\t\t\t\tgoto out_unlock;\n+\t\t\t}\n \t\t}\n \t}\n+out_unlock:\n \tspin_unlock(&cifs_tcp_ses_lock);\n+\n+\tif (wait)\n+\t\tflush_workqueue(cfid_put_wq);\n+\n+\tafter = atomic64_read(&cifs_dircache_bytes_used);\n+\tif (after >= before)\n+\t\treturn 0;\n+\treturn (unsigned long)(before - after);\n+}\n+\n+static unsigned long cifs_dircache_shrinker_count(struct shrinker *shrink,\n+\t\t\t\t\t\t   struct shrink_control *sc)\n+{\n+\tu64 bytes = atomic64_read(&cifs_dircache_bytes_used);\n+\n+\t(void)shrink;\n+\t(void)sc;\n+\n+\treturn DIV_ROUND_UP_ULL(bytes, PAGE_SIZE);\n+}\n+\n+static unsigned long cifs_dircache_shrinker_scan(struct shrinker *shrink,\n+\t\t\t\t\t\t  struct shrink_control *sc)\n+{\n+\tunsigned long freed_bytes;\n+\n+\t(void)shrink;\n+\n+\tif (!sc->nr_to_scan)\n+\t\treturn 0;\n+\n+\tif (!atomic64_read(&cifs_dircache_bytes_used))\n+\t\treturn SHRINK_STOP;\n+\n+\t/*\n+\t * Shrinker scan can run from reclaim context, so avoid synchronously\n+\t * flushing worker queues here to prevent long stalls/deadlocks.\n+\t */\n+\tfreed_bytes = cifs_drop_all_dir_caches(false, max_t(unsigned long, 1, sc->nr_to_scan));\n+\tif (!freed_bytes)\n+\t\treturn SHRINK_STOP;\n+\n+\treturn DIV_ROUND_UP_ULL(freed_bytes, PAGE_SIZE);\n }\n \n static int cifs_param_set_drop_dir_cache(const char *val, const struct kernel_param *kp)\n@@ -154,7 +214,7 @@ static int cifs_param_set_drop_dir_cache(const char *val, const struct kernel_pa\n \tif (rc)\n \t\treturn rc;\n \tif (bv)\n-\t\tcifs_drop_all_dir_caches();\n+\t\tcifs_drop_all_dir_caches(true, ULONG_MAX);\n \treturn 0;\n }\n \n@@ -2038,10 +2098,19 @@ init_cifs(void)\n \tif (rc)\n \t\tgoto out_destroy_mids;\n \n+\tcifs_dircache_shrinker = shrinker_alloc(0, \"cifs-dircache\");\n+\tif (!cifs_dircache_shrinker) {\n+\t\trc = -ENOMEM;\n+\t\tgoto out_destroy_request_bufs;\n+\t}\n+\tcifs_dircache_shrinker->count_objects = cifs_dircache_shrinker_count;\n+\tcifs_dircache_shrinker->scan_objects = cifs_dircache_shrinker_scan;\n+\tshrinker_register(cifs_dircache_shrinker);\n+\n #ifdef CONFIG_CIFS_DFS_UPCALL\n \trc = dfs_cache_init();\n \tif (rc)\n-\t\tgoto out_destroy_request_bufs;\n+\t\tgoto out_free_dircache_shrinker;\n #endif /* CONFIG_CIFS_DFS_UPCALL */\n #ifdef CONFIG_CIFS_UPCALL\n \trc = init_cifs_spnego();\n@@ -2083,8 +2152,11 @@ init_cifs(void)\n #endif\n #ifdef CONFIG_CIFS_DFS_UPCALL\n \tdfs_cache_destroy();\n-out_destroy_request_bufs:\n+out_free_dircache_shrinker:\n #endif\n+\tshrinker_free(cifs_dircache_shrinker);\n+\tcifs_dircache_shrinker = NULL;\n+out_destroy_request_bufs:\n \tcifs_destroy_request_bufs();\n out_destroy_mids:\n \tdestroy_mids();\n@@ -2117,6 +2189,8 @@ exit_cifs(void)\n \tcifs_dbg(NOISY, \"exit_smb3\\n\");\n \tunregister_filesystem(&cifs_fs_type);\n \tunregister_filesystem(&smb3_fs_type);\n+\tshrinker_free(cifs_dircache_shrinker);\n+\tcifs_dircache_shrinker = NULL;\n \tcifs_release_automount_timer();\n \texit_cifs_idmap();\n #ifdef CONFIG_CIFS_SWN_UPCALL\n","prefixes":["v3","12/19"]}