All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kfence: use TASK_IDLE when awaiting allocation
@ 2021-05-21  8:32 ` Marco Elver
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Elver @ 2021-05-21  8:32 UTC (permalink / raw)
  To: elver, akpm
  Cc: glider, dvyukov, linux-kernel, linux-mm, kasan-dev, Mel Gorman, stable

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.

BugLink: https://bugzilla.suse.com/show_bug.cgi?id=1185565
Fixes: 407f1d8c1b5f ("kfence: await for allocation using wait_event")
Signed-off-by: Marco Elver <elver@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: <stable@vger.kernel.org> # v5.12+
---
 mm/kfence/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index e18fbbd5d9b4..4d21ac44d5d3 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -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. */
-- 
2.31.1.818.g46aad6cb9e-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] kfence: use TASK_IDLE when awaiting allocation
@ 2021-05-21  8:32 ` Marco Elver
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Elver @ 2021-05-21  8:32 UTC (permalink / raw)
  To: elver, akpm
  Cc: glider, dvyukov, linux-kernel, linux-mm, kasan-dev, Mel Gorman, stable

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.

BugLink: https://bugzilla.suse.com/show_bug.cgi?id=1185565
Fixes: 407f1d8c1b5f ("kfence: await for allocation using wait_event")
Signed-off-by: Marco Elver <elver@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: <stable@vger.kernel.org> # v5.12+
---
 mm/kfence/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index e18fbbd5d9b4..4d21ac44d5d3 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -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. */
-- 
2.31.1.818.g46aad6cb9e-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  8:32 ` Marco Elver
  (?)
@ 2021-05-21  9:37 ` Hillf Danton
  2021-05-21 11:17     ` Marco Elver
  -1 siblings, 1 reply; 10+ messages in thread
From: Hillf Danton @ 2021-05-21  9:37 UTC (permalink / raw)
  To: Marco Elver
  Cc: akpm, glider, dvyukov, linux-kernel, linux-mm, kasan-dev,
	Mel Gorman, stable

On Fri, 21 May 2021 10:32:09 +0200 Marco Elver wrote:
>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.

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."


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  8:32 ` Marco Elver
  (?)
  (?)
@ 2021-05-21  9:39 ` David Laight
  2021-05-21  9:47   ` Marco Elver
  -1 siblings, 1 reply; 10+ messages in thread
From: David Laight @ 2021-05-21  9:39 UTC (permalink / raw)
  To: 'Marco Elver', akpm
  Cc: glider, dvyukov, linux-kernel, linux-mm, kasan-dev, Mel Gorman, stable

From: Marco Elver
> Sent: 21 May 2021 09:32
> 
> 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.

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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  9:39 ` David Laight
@ 2021-05-21  9:47   ` Marco Elver
  2021-05-21 10:15     ` David Laight
  0 siblings, 1 reply; 10+ messages in thread
From: Marco Elver @ 2021-05-21  9:47 UTC (permalink / raw)
  To: David Laight
  Cc: akpm, glider, dvyukov, linux-kernel, linux-mm, kasan-dev,
	Mel Gorman, stable

On Fri, May 21, 2021 at 09:39AM +0000, David Laight wrote:
> From: Marco Elver
> > Sent: 21 May 2021 09:32
> > 
> > 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.
> 
> 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.

That's what TASK_IDLE is:

	include/linux/sched.h:#define TASK_IDLE                 (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)

See https://lore.kernel.org/lkml/alpine.LFD.2.11.1505112154420.1749@ja.home.ssi.bg/T/

Thanks,
-- Marco

> 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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  9:47   ` Marco Elver
@ 2021-05-21 10:15     ` David Laight
  0 siblings, 0 replies; 10+ messages in thread
From: David Laight @ 2021-05-21 10:15 UTC (permalink / raw)
  To: 'Marco Elver'
  Cc: akpm, glider, dvyukov, linux-kernel, linux-mm, kasan-dev,
	Mel Gorman, stable

From: Marco Elver
> Sent: 21 May 2021 10:48
> 
> On Fri, May 21, 2021 at 09:39AM +0000, David Laight wrote:
> > From: Marco Elver
> > > Sent: 21 May 2021 09:32
> > >
> > > 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.
> >
> > 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.
> 
> That's what TASK_IDLE is:
> 
> 	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)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  9:37 ` Hillf Danton
@ 2021-05-21 11:17     ` Marco Elver
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Elver @ 2021-05-21 11:17 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Andrew Morton, Alexander Potapenko, Dmitry Vyukov, LKML,
	Linux Memory Management List, kasan-dev, Mel Gorman, stable

On Fri, 21 May 2021 at 11:37, Hillf Danton <hdanton@sina.com> wrote:
> On Fri, 21 May 2021 10:32:09 +0200 Marco Elver wrote:
> >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.
>
> 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."

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/20210521111630.472579-1-elver@google.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] kfence: use TASK_IDLE when awaiting allocation
@ 2021-05-21 11:17     ` Marco Elver
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Elver @ 2021-05-21 11:17 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Andrew Morton, Alexander Potapenko, Dmitry Vyukov, LKML,
	Linux Memory Management List, kasan-dev, Mel Gorman, stable

On Fri, 21 May 2021 at 11:37, Hillf Danton <hdanton@sina.com> wrote:
> On Fri, 21 May 2021 10:32:09 +0200 Marco Elver wrote:
> >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.
>
> 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."

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/20210521111630.472579-1-elver@google.com


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [5.12.y] kfence: use TASK_IDLE when awaiting allocation
  2021-05-21  8:32 ` Marco Elver
                   ` (2 preceding siblings ...)
  (?)
@ 2021-06-07 14:23 ` Marco Elver
  2021-06-08 13:21   ` Greg Kroah-Hartman
  -1 siblings, 1 reply; 10+ messages in thread
From: Marco Elver @ 2021-06-07 14:23 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman, Sasha Levin; +Cc: Alexander Potapenko, kasan-dev

Dear 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 <elver@google.com>
Date: Fri, 21 May 2021 at 10:32
Subject: [PATCH] kfence: use TASK_IDLE when awaiting allocation
To: <elver@google.com>, <akpm@linux-foundation.org>
Cc: <glider@google.com>, <dvyukov@google.com>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<kasan-dev@googlegroups.com>, Mel Gorman <mgorman@suse.de>,
<stable@vger.kernel.org>


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.

BugLink: https://bugzilla.suse.com/show_bug.cgi?id=1185565
Fixes: 407f1d8c1b5f ("kfence: await for allocation using wait_event")
Signed-off-by: Marco Elver <elver@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: <stable@vger.kernel.org> # v5.12+
---
 mm/kfence/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [5.12.y] kfence: use TASK_IDLE when awaiting allocation
  2021-06-07 14:23 ` [5.12.y] " Marco Elver
@ 2021-06-08 13:21   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-08 13:21 UTC (permalink / raw)
  To: Marco Elver; +Cc: stable, Sasha Levin, Alexander Potapenko, kasan-dev

On Mon, Jun 07, 2021 at 04:23:34PM +0200, Marco Elver wrote:
> Dear 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

Thanks, that worked!

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-06-08 13:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21  8:32 [PATCH] kfence: use TASK_IDLE when awaiting allocation Marco Elver
2021-05-21  8:32 ` Marco Elver
2021-05-21  9:37 ` Hillf Danton
2021-05-21 11:17   ` Marco Elver
2021-05-21 11:17     ` Marco Elver
2021-05-21  9:39 ` David Laight
2021-05-21  9:47   ` Marco Elver
2021-05-21 10:15     ` David Laight
2021-06-07 14:23 ` [5.12.y] " Marco Elver
2021-06-08 13:21   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.