Re: [PATCH v8] KEYS: key_garbage_collector(): process in chunks

From: Jarkko Sakkinen

Date: Fri Oct 30 2026 - 17:30:30 EST


On Fri, Oct 30, 2026 at 10:54:08PM +0200, Jarkko Sakkinen wrote:
> key_garbage_collector() has a design that is not resistant enough for
> workqueue lockups. The duration scales up relative to the number of items
> in the serial tree, which causes a reoccuring theme of being guilty of
> causing workqueue lockups.
>
> Resolve the problem by processing in chunks:
>
> 1. Declare a static variable key_gc_work, which owns the garbage collection
> in-flight state, and key_schedule_gc_work() for re-scheduling the work.
> 2. Define KEY_GC_CHUNK_SIZE, set to 64 keys, as the bound for the number
> of items scanned and destroyed.
> 3. Define KEY_GC_DESTROYING to mark resume to destruction without repeating
> the RCU grace period. Drain the graveyard before advancing key-type
> reaping.
> 4. Define KEY_GC_REAP_REQUESTED for preserving full-pass requests across
> the continuations.
>
> keygcbench results without the patch:
>
> unused: min=798.785 avg=4181.989 max=7565.193 var=11446068.927
> expired: min=0.003 avg=2404.971 max=4111.065 var=3061018.501
> combined: min=0.003 avg=3115.778 max=7565.193 var=7172908.943
>
> keygcbench results with the patch:
>
> unused: min=0.005 avg=0.125 max=79.590 var=1.088
> expired: min=0.002 avg=0.196 max=236.207 var=8.121
> combined: min=0.002 avg=0.154 max=236.207 var=3.912
>
> These results translate to:
>
> - 93% drop in the combined variance.
> - 2.2% increase in the total task time.
>
> The value 64 for KEY_GC_CHUNK_SIZE was cherry-picked from the set {1, 2,
> ..., 1024} by running the benchmark for each chunk size three times.
>
> At the far left variance is 97% lower but at the same time total time
> grows by 133%, when compared to the selected chunk size. The size was
> picked based on getting a reasonable variance with a minimal throughput
> decline.
>
> Fixes: 0c061b5707ab ("KEYS: Correctly destroy key payloads when their keytype is removed")
> Reported-by: syzbot+c15de43f1e7fffbb7b9b@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=c15de43f1e7fffbb7b9b

These re-appeared because last time I fixed up them in the patch and
forgot to remove them from the commit. Not submitting a new version
for this but it can be done :-)

It's just so irrelevant detail in the end of the day so I had my
eyes more on the code than the tag; thus slipped.

> Link: https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd-test.git/tree/package/keygcbench
> Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>

No new Sashiko issues reported. Weird that they came so late.

Br, Jarkko