kfence: use TASK_IDLE when awaiting allocation
Subsystems (3)
Marco Elver
maintainerPATCH 1/1 kfence: use TASK_IDLE when awaiting allocation
Since wait_event() uses TASK_UNINTERRUPTIBLE by default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.
Instead, use TASK_IDLE via wait_event_idle() to not count towards load.
--- mm/kfence/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/kfence/core.c +3 -3
@@ -627,10 +627,10 @@ static void toggle_allocation_gate(struct work_struct *work)* During low activity with no allocations we might wait a * while; let's avoid the hung task warning. */ -wait_event_timeout (allocation_wait,atomic_read (&kfence_allocation_gate), - sysctl_hung_task_timeout_secs *HZ /2 ); +wait_event_idle_timeout (allocation_wait,atomic_read (&kfence_allocation_gate), + sysctl_hung_task_timeout_secs *HZ /2 ); }else { -wait_event (allocation_wait,atomic_read (&kfence_allocation_gate)); +wait_event_idle (allocation_wait,atomic_read (&kfence_allocation_gate)); }/* Disable static key and reset timer. */
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
Quoted 3 lines · On Fri, 21 May 2021 10:32:09 +0200 Marco Elver wrote:
Since
wait_event()usesTASK_UNINTERRUPTIBLEby default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.
Because of a blocking wq callback, kfence_timer should be queued on a unbound workqueue in the first place. Feel free to add a followup to replace system_power_efficient_wq with system_unbound_wq if it makes sense to you that kfence behaves as correctly as expected independent of CONFIG_WQ_POWER_EFFICIENT_DEFAULT given "system_power_efficient_wq is identical to system_wq if 'wq_power_efficient' is disabled."
Marco Elver
maintainerQuoted 11 lines · Hillf Danton
Quoted 3 lines · On Fri, 21 May 2021 10:32:09 +0200 Marco Elver wrote:
Since
wait_event()usesTASK_UNINTERRUPTIBLEby default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.Because of a blocking wq callback,
kfence_timershould be queued on a unbound workqueue in the first place. Feel free to add a followup to replacesystem_power_efficient_wqwithsystem_unbound_wqif it makes sense to you that kfence behaves as correctly as expected independent ofCONFIG_WQ_POWER_EFFICIENT_DEFAULTgiven "system_power_efficient_wqis identical tosystem_wqif 'wq_power_efficient' is disabled."
Thanks for pointing it out -- I think this makes sense, let's just use the unbound wq unconditionally. Since it's independent of this patch, I've sent it separately:
https://lkml.kernel.org/r/[email protected]
From: Marco Elver
Quoted 7 lines
Sent: 21 May 2021 09:32
Since
wait_event()usesTASK_UNINTERRUPTIBLEby default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.Instead, use
TASK_IDLEviawait_event_idle()to not count towards load.
Doesn't that let the process be interruptible by a signal. Which is probably not desirable.
There really ought to be a way of sleeping with TASK_UNINTERRUPTIBLE without changing the load-average.
IIRC the load-average is really intended to include processes that are waiting for disk - especially for swap.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Marco Elver
maintainerQuoted 7 lines · David Laight
From: Marco Elver
Quoted 6 lines
Sent: 21 May 2021 09:32
Since
wait_event()usesTASK_UNINTERRUPTIBLEby default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.
Quoted 7 lines
Quoted 1 line
Instead, use
TASK_IDLEviawait_event_idle()to not count towards load.Doesn't that let the process be interruptible by a signal. Which is probably not desirable.
There really ought to be a way of sleeping with
TASK_UNINTERRUPTIBLEwithout changing the load-average.
That's what TASK_IDLE is:
include/linux/sched.h:#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
See https://lore.kernel.org/lkml/[email protected]/T/
Thanks,
-- Marco
Quoted 8 lines
IIRC the load-average is really intended to include processes that are waiting for disk - especially for swap.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
From: Marco Elver
Quoted 15 lines
Sent: 21 May 2021 10:48
Quoted 12 lines · David Laight
From: Marco Elver
Quoted 7 lines
Sent: 21 May 2021 09:32
Since
wait_event()usesTASK_UNINTERRUPTIBLEby default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.Instead, use
TASK_IDLEviawait_event_idle()to not count towards load.Doesn't that let the process be interruptible by a signal. Which is probably not desirable.
Quoted 6 lines
Quoted 2 lines
There really ought to be a way of sleeping with
TASK_UNINTERRUPTIBLEwithout changing the load-average.That's what
TASK_IDLEis:include/linux/sched.h:#define
TASK_IDLE(TASK_UNINTERRUPTIBLE|TASK_NOLOAD)
That's been added since I last tried to stop tasks updating the load-average :-)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Marco Elver
maintainerDear stable maintainers,
The patch "kfence: use TASK_IDLE when awaiting allocation" has landed in mainline as 8fd0e995cc7b, however, does not apply cleanly to 5.12.y due to a prerequisite patch missing.
My recommendation is to cherry-pick the following 2 commits to 5.12.y (rather than rebase 8fd0e995cc7b on top of 5.12.y):
37c9284f6932 kfence: maximize allocation wait timeout duration 8fd0e995cc7b kfence: use TASK_IDLE when awaiting allocation
Many thanks,
-- Marco
---------- Forwarded message ---------
From: Marco Elver <[email protected]>
Date: Fri, 21 May 2021 at 10:32
Subject: [PATCH] kfence: use TASK_IDLE when awaiting allocation
To: <[email protected]>, <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, Mel Gorman <[email protected]>, <[email protected]>
Since wait_event() uses TASK_UNINTERRUPTIBLE by default, waiting for an allocation counts towards load. However, for KFENCE, this does not make any sense, since there is no busy work we're awaiting.
Instead, use TASK_IDLE via wait_event_idle() to not count towards load.
--- mm/kfence/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Greg Kroah-Hartman
maintainerQuoted 11 lines · Marco Elver
Dear stable maintainers,
The patch "kfence: use
TASK_IDLEwhen awaiting allocation" has landed in mainline as8fd0e995cc7b, however, does not apply cleanly to 5.12.y due to a prerequisite patch missing.My recommendation is to cherry-pick the following 2 commits to 5.12.y (rather than rebase
8fd0e995cc7bon top of 5.12.y):
37c9284f6932kfence: maximize allocation wait timeout duration8fd0e995cc7bkfence: useTASK_IDLEwhen awaiting allocation
Thanks, that worked!
greg k-h