From 0c3911b857def2e398bd294ac2060077fb9770a7 Mon Sep 17 00:00:00 2001 From: Zongyao Chen Date: Mon, 18 May 2026 19:33:37 +0800 Subject: [PATCH] lua-lsm: skip empty kvcache dict free kvcache_dict_free() can be called for objects that never stored Lua-visible key/value state. Walking an empty rbtree and taking the global nodes GC lock in that case is unnecessary work on object teardown paths. Return immediately when the dictionary count is zero. Non-empty dictionaries still take the existing lock and unlink every cached node as before. Signed-off-by: Zongyao Chen --- security/lua/kvcache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/security/lua/kvcache.c b/security/lua/kvcache.c index 89c4627fadaf..f67ea5ea2d64 100644 --- a/security/lua/kvcache.c +++ b/security/lua/kvcache.c @@ -450,6 +450,9 @@ void kvcache_dict_free(struct kvcache_dict *dict) struct kvcache_node *node, *n; struct lua_lsm_module *module; + if (atomic_read(&dict->count) == 0) + return; + spin_lock_bh(&nodes_gc_lock); RB_FOREACH(node, kvcache, &dict->root) { module = node->module;