diff mbox series

keys: Add cond_resched to key_gc_unused_keys()

Message ID 1732679561-22967-1-git-send-email-mengensun@tencent.com (mailing list archive)
State New
Headers show
Series keys: Add cond_resched to key_gc_unused_keys() | expand

Commit Message

MengEn Sun Nov. 27, 2024, 3:52 a.m. UTC
From: MengEn Sun <mengensun@tencent.com>

When running the follow test:
while :
do
    stress-ng --key=64 --key-ops=1000
done

We used the bcc tools funclatency to measure the execution
latency of key_gc_unused_keys(), and the results are as
follows:

funclatency key_gc_unused_keys.constprop.5 -i 1 -m
msecs               : count
    0 -> 1          : 0
    2 -> 3          : 0
    4 -> 7          : 0
    8 -> 15         : 0
   16 -> 31         : 0
   32 -> 63         : 0
   64 -> 127        : 1

It seems that key_gc_unused_keys() takes a long time to
execute, and there are no scheduling points in this function,
which may harm latency-sensitive services.

Therefore, we have added a scheduling point to this function.

Reviewed-by: YueHong Wu <yuehongwu@tencent.com>
Signed-off-by: MengEn Sun <mengensun@tencent.com>
---
 security/keys/gc.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/security/keys/gc.c b/security/keys/gc.c
index 7d687b0..14e4f1c 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -165,6 +165,7 @@  static noinline void key_gc_unused_keys(struct list_head *keys)
 
 		memzero_explicit(key, sizeof(*key));
 		kmem_cache_free(key_jar, key);
+		cond_resched();
 	}
 }