Skip to content

Commit 37c9284

Browse files
melvertorvalds
authored andcommitted
kfence: maximize allocation wait timeout duration
The allocation wait timeout was initially added because of warnings due to CONFIG_DETECT_HUNG_TASK=y [1]. While the 1 sec timeout is sufficient to resolve the warnings (given the hung task timeout must be 1 sec or larger) it may cause unnecessary wake-ups if the system is idle: https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com Fix it by computing the timeout duration in terms of the current sysctl_hung_task_timeout_secs value. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Marco Elver <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Jann Horn <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 407f1d8 commit 37c9284

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mm/kfence/core.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/moduleparam.h>
2121
#include <linux/random.h>
2222
#include <linux/rcupdate.h>
23+
#include <linux/sched/sysctl.h>
2324
#include <linux/seq_file.h>
2425
#include <linux/slab.h>
2526
#include <linux/spinlock.h>
@@ -621,7 +622,16 @@ static void toggle_allocation_gate(struct work_struct *work)
621622
/* Enable static key, and await allocation to happen. */
622623
static_branch_enable(&kfence_allocation_key);
623624

624-
wait_event_timeout(allocation_wait, atomic_read(&kfence_allocation_gate), HZ);
625+
if (sysctl_hung_task_timeout_secs) {
626+
/*
627+
* During low activity with no allocations we might wait a
628+
* while; let's avoid the hung task warning.
629+
*/
630+
wait_event_timeout(allocation_wait, atomic_read(&kfence_allocation_gate),
631+
sysctl_hung_task_timeout_secs * HZ / 2);
632+
} else {
633+
wait_event(allocation_wait, atomic_read(&kfence_allocation_gate));
634+
}
625635

626636
/* Disable static key and reset timer. */
627637
static_branch_disable(&kfence_allocation_key);

0 commit comments

Comments
 (0)