Skip to contentSkip to conversation

keys: Add cond_resched to key_gc_unused_keys()

PATCH In review [email protected] 2 participants 3 messages Nov 27, 2024 – Dec 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 keys: Add cond_resched to key_gc_unused_keys()

From: MengEn Sun <[email protected]>

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.

---
 security/keys/gc.c | 1 +
 1 file changed, 1 insertion(+)
security/keys/gc.c +1 -0
index 7d687b0..14e4f1c 100644
@@ -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();
 	}
 }
 
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 39 lines · On Wed Nov 27, 2024 at 5:52 AM EET, mengensun88 wrote:

From: MengEn Sun <[email protected]>

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.

---
 security/keys/gc.c | 1 +
 1 file changed, 1 insertion(+)
security/keys/gc.c +0 -0
index 7d687b0..14e4f1c 100644

security/keys/gc.c static noinline void key_gc_unused_keys(struct list_head *keys) · line 171

Quoted 7 lines
security/keys/gc.c +1 -0
@@ -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();
 	}
 }
 

This really needs ack from David.

Get the idea tho.

BR, Jarkko

author
#2 lore raw

Hi, David

Quoted 42 lines · On Sat, 30 Nov 2024 04:46:35 +0200 Jarkko Sakkinen wrote:

From: [email protected]

Quoted 40 lines · On Wed Nov 27, 2024 at 5:52 AM EET, mengensun88 wrote:

From: MengEn Sun <[email protected]>

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.

---
 security/keys/gc.c | 1 +
 1 file changed, 1 insertion(+)
security/keys/gc.c +0 -0
index 7d687b0..14e4f1c 100644
@@ -165,6 +165,7 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
 
Quoted 9 lines

security/keys/gc.c static noinline void key_gc_unused_keys(struct list_head *keys) · line 171

Quoted 6 lines
security/keys/gc.c +1 -0
 		memzero_explicit(key, sizeof(*key));
 		kmem_cache_free(key_jar, key);
+		cond_resched();
 	}
 }
 

This really needs ack from David.

Could you please provide me with some valuable suggestions? That way, I can make adjustments for a version 2 based on your advice. Thank you very much!

Quoted 4 lines

Get the idea tho.

BR, Jarkko

Regards
Meng En