All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] psi: fix possible trigger missing in the window
@ 2021-12-22  0:24 Huangzhaoyang
  2021-12-22  0:31 ` Suren Baghdasaryan
  0 siblings, 1 reply; 4+ messages in thread
From: Huangzhaoyang @ 2021-12-22  0:24 UTC (permalink / raw)
  To: Johannes Weiner, Suren Baghdasaryan, Zhaoyang Huang, linux-mm,
	linux-kernel

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

When a new threshold breaching stall happens after a psi event was
generated and within the window duration, the new event is not
generated because the events are rate-limited to one per window. If
after that no new stall is recorded then the event will not be
generated even after rate-limiting duration has passed. This is
happening because with no new stall, window_update will not be called
even though threshold was previously breached. To fix this, record
threshold breaching occurrence and generate the event once window
duration is passed.

Suggested-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
v2: modify the logic according to Suren's suggestion
v3: update commit message
---
---
 include/linux/psi_types.h |  2 ++
 kernel/sched/psi.c        | 38 +++++++++++++++++++++++---------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
index 0a23300..87b694a 100644
--- a/include/linux/psi_types.h
+++ b/include/linux/psi_types.h
@@ -132,6 +132,8 @@ struct psi_trigger {
 
 	/* Refcounting to prevent premature destruction */
 	struct kref refcount;
+
+	bool threshold_breach;
 };
 
 struct psi_group {
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 1652f2b..5c67ab9 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -524,24 +524,29 @@ static u64 update_triggers(struct psi_group *group, u64 now)
 	 */
 	list_for_each_entry(t, &group->triggers, node) {
 		u64 growth;
+		bool trigger_stalled =
+			group->polling_total[t->state] != total[t->state];
 
-		/* Check for stall activity */
-		if (group->polling_total[t->state] == total[t->state])
-			continue;
-
-		/*
-		 * Multiple triggers might be looking at the same state,
-		 * remember to update group->polling_total[] once we've
-		 * been through all of them. Also remember to extend the
-		 * polling time if we see new stall activity.
-		 */
-		new_stall = true;
-
-		/* Calculate growth since last update */
-		growth = window_update(&t->win, now, total[t->state]);
-		if (growth < t->threshold)
+		/* Check for stall activity or a previous threshold breach */
+		if (!trigger_stalled && !t->threshold_breach)
 			continue;
 
+		if (trigger_stalled) {
+			/*
+			 * Multiple triggers might be looking at the same state,
+			 * remember to update group->polling_total[] once we've
+			 * been through all of them. Also remember to extend the
+			 * polling time if we see new stall activity.
+			 */
+			new_stall = true;
+
+			/* Calculate growth since last update */
+			growth = window_update(&t->win, now, total[t->state]);
+			if (growth < t->threshold)
+				continue;
+
+			t->threshold_breach = true;
+		}
 		/* Limit event signaling to once per window */
 		if (now < t->last_event_time + t->win.size)
 			continue;
@@ -550,6 +555,8 @@ static u64 update_triggers(struct psi_group *group, u64 now)
 		if (cmpxchg(&t->event, 0, 1) == 0)
 			wake_up_interruptible(&t->event_wait);
 		t->last_event_time = now;
+		/* Reset threshold breach flag once event got generated */
+		t->threshold_breach = false;
 	}
 
 	if (new_stall)
@@ -1152,6 +1159,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
 	t->last_event_time = 0;
 	init_waitqueue_head(&t->event_wait);
 	kref_init(&t->refcount);
+	t->threshold_breach = false;
 
 	mutex_lock(&group->trigger_lock);
 
-- 
1.9.1


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

* Re: [PATCH v3] psi: fix possible trigger missing in the window
  2021-12-22  0:24 [PATCH v3] psi: fix possible trigger missing in the window Huangzhaoyang
@ 2021-12-22  0:31 ` Suren Baghdasaryan
  2021-12-23  0:50   ` Zhaoyang Huang
  0 siblings, 1 reply; 4+ messages in thread
From: Suren Baghdasaryan @ 2021-12-22  0:31 UTC (permalink / raw)
  To: Huangzhaoyang
  Cc: Johannes Weiner, Zhaoyang Huang, linux-mm, linux-kernel, Peter Zijlstra

On Tue, Dec 21, 2021 at 4:24 PM Huangzhaoyang <huangzhaoyang@gmail.com> wrote:
>
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Please remember to CC Peter.

>
> When a new threshold breaching stall happens after a psi event was
> generated and within the window duration, the new event is not
> generated because the events are rate-limited to one per window. If
> after that no new stall is recorded then the event will not be
> generated even after rate-limiting duration has passed. This is
> happening because with no new stall, window_update will not be called
> even though threshold was previously breached. To fix this, record
> threshold breaching occurrence and generate the event once window
> duration is passed.
>
> Suggested-by: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
> v2: modify the logic according to Suren's suggestion
> v3: update commit message
> ---
> ---
>  include/linux/psi_types.h |  2 ++
>  kernel/sched/psi.c        | 38 +++++++++++++++++++++++---------------
>  2 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
> index 0a23300..87b694a 100644
> --- a/include/linux/psi_types.h
> +++ b/include/linux/psi_types.h
> @@ -132,6 +132,8 @@ struct psi_trigger {
>
>         /* Refcounting to prevent premature destruction */
>         struct kref refcount;
> +
> +       bool threshold_breach;
>  };
>
>  struct psi_group {
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 1652f2b..5c67ab9 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -524,24 +524,29 @@ static u64 update_triggers(struct psi_group *group, u64 now)
>          */
>         list_for_each_entry(t, &group->triggers, node) {
>                 u64 growth;
> +               bool trigger_stalled =
> +                       group->polling_total[t->state] != total[t->state];
>
> -               /* Check for stall activity */
> -               if (group->polling_total[t->state] == total[t->state])
> -                       continue;
> -
> -               /*
> -                * Multiple triggers might be looking at the same state,
> -                * remember to update group->polling_total[] once we've
> -                * been through all of them. Also remember to extend the
> -                * polling time if we see new stall activity.
> -                */
> -               new_stall = true;
> -
> -               /* Calculate growth since last update */
> -               growth = window_update(&t->win, now, total[t->state]);
> -               if (growth < t->threshold)
> +               /* Check for stall activity or a previous threshold breach */
> +               if (!trigger_stalled && !t->threshold_breach)
>                         continue;
>
> +               if (trigger_stalled) {
> +                       /*
> +                        * Multiple triggers might be looking at the same state,
> +                        * remember to update group->polling_total[] once we've
> +                        * been through all of them. Also remember to extend the
> +                        * polling time if we see new stall activity.
> +                        */
> +                       new_stall = true;
> +
> +                       /* Calculate growth since last update */
> +                       growth = window_update(&t->win, now, total[t->state]);
> +                       if (growth < t->threshold)
> +                               continue;
> +
> +                       t->threshold_breach = true;
> +               }
>                 /* Limit event signaling to once per window */
>                 if (now < t->last_event_time + t->win.size)
>                         continue;
> @@ -550,6 +555,8 @@ static u64 update_triggers(struct psi_group *group, u64 now)
>                 if (cmpxchg(&t->event, 0, 1) == 0)
>                         wake_up_interruptible(&t->event_wait);
>                 t->last_event_time = now;
> +               /* Reset threshold breach flag once event got generated */
> +               t->threshold_breach = false;
>         }
>
>         if (new_stall)
> @@ -1152,6 +1159,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
>         t->last_event_time = 0;
>         init_waitqueue_head(&t->event_wait);
>         kref_init(&t->refcount);
> +       t->threshold_breach = false;
>
>         mutex_lock(&group->trigger_lock);
>
> --
> 1.9.1
>

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

* Re: [PATCH v3] psi: fix possible trigger missing in the window
  2021-12-22  0:31 ` Suren Baghdasaryan
@ 2021-12-23  0:50   ` Zhaoyang Huang
  2021-12-23  1:11     ` Suren Baghdasaryan
  0 siblings, 1 reply; 4+ messages in thread
From: Zhaoyang Huang @ 2021-12-23  0:50 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: Johannes Weiner, Zhaoyang Huang, open list:MEMORY MANAGEMENT,
	LKML, Peter Zijlstra

@Peter Zijlstra @Johannes Weiner
Would you please review this patch? We would like to have it be merged
ASAP. Thanks.

On Wed, Dec 22, 2021 at 8:31 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Tue, Dec 21, 2021 at 4:24 PM Huangzhaoyang <huangzhaoyang@gmail.com> wrote:
> >
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> Please remember to CC Peter.
>
> >
> > When a new threshold breaching stall happens after a psi event was
> > generated and within the window duration, the new event is not
> > generated because the events are rate-limited to one per window. If
> > after that no new stall is recorded then the event will not be
> > generated even after rate-limiting duration has passed. This is
> > happening because with no new stall, window_update will not be called
> > even though threshold was previously breached. To fix this, record
> > threshold breaching occurrence and generate the event once window
> > duration is passed.
> >
> > Suggested-by: Suren Baghdasaryan <surenb@google.com>
> > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > ---
> > v2: modify the logic according to Suren's suggestion
> > v3: update commit message
> > ---
> > ---
> >  include/linux/psi_types.h |  2 ++
> >  kernel/sched/psi.c        | 38 +++++++++++++++++++++++---------------
> >  2 files changed, 25 insertions(+), 15 deletions(-)
> >
> > diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
> > index 0a23300..87b694a 100644
> > --- a/include/linux/psi_types.h
> > +++ b/include/linux/psi_types.h
> > @@ -132,6 +132,8 @@ struct psi_trigger {
> >
> >         /* Refcounting to prevent premature destruction */
> >         struct kref refcount;
> > +
> > +       bool threshold_breach;
> >  };
> >
> >  struct psi_group {
> > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > index 1652f2b..5c67ab9 100644
> > --- a/kernel/sched/psi.c
> > +++ b/kernel/sched/psi.c
> > @@ -524,24 +524,29 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> >          */
> >         list_for_each_entry(t, &group->triggers, node) {
> >                 u64 growth;
> > +               bool trigger_stalled =
> > +                       group->polling_total[t->state] != total[t->state];
> >
> > -               /* Check for stall activity */
> > -               if (group->polling_total[t->state] == total[t->state])
> > -                       continue;
> > -
> > -               /*
> > -                * Multiple triggers might be looking at the same state,
> > -                * remember to update group->polling_total[] once we've
> > -                * been through all of them. Also remember to extend the
> > -                * polling time if we see new stall activity.
> > -                */
> > -               new_stall = true;
> > -
> > -               /* Calculate growth since last update */
> > -               growth = window_update(&t->win, now, total[t->state]);
> > -               if (growth < t->threshold)
> > +               /* Check for stall activity or a previous threshold breach */
> > +               if (!trigger_stalled && !t->threshold_breach)
> >                         continue;
> >
> > +               if (trigger_stalled) {
> > +                       /*
> > +                        * Multiple triggers might be looking at the same state,
> > +                        * remember to update group->polling_total[] once we've
> > +                        * been through all of them. Also remember to extend the
> > +                        * polling time if we see new stall activity.
> > +                        */
> > +                       new_stall = true;
> > +
> > +                       /* Calculate growth since last update */
> > +                       growth = window_update(&t->win, now, total[t->state]);
> > +                       if (growth < t->threshold)
> > +                               continue;
> > +
> > +                       t->threshold_breach = true;
> > +               }
> >                 /* Limit event signaling to once per window */
> >                 if (now < t->last_event_time + t->win.size)
> >                         continue;
> > @@ -550,6 +555,8 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> >                 if (cmpxchg(&t->event, 0, 1) == 0)
> >                         wake_up_interruptible(&t->event_wait);
> >                 t->last_event_time = now;
> > +               /* Reset threshold breach flag once event got generated */
> > +               t->threshold_breach = false;
> >         }
> >
> >         if (new_stall)
> > @@ -1152,6 +1159,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
> >         t->last_event_time = 0;
> >         init_waitqueue_head(&t->event_wait);
> >         kref_init(&t->refcount);
> > +       t->threshold_breach = false;
> >
> >         mutex_lock(&group->trigger_lock);
> >
> > --
> > 1.9.1
> >

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

* Re: [PATCH v3] psi: fix possible trigger missing in the window
  2021-12-23  0:50   ` Zhaoyang Huang
@ 2021-12-23  1:11     ` Suren Baghdasaryan
  0 siblings, 0 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2021-12-23  1:11 UTC (permalink / raw)
  To: Zhaoyang Huang
  Cc: Johannes Weiner, Zhaoyang Huang, open list:MEMORY MANAGEMENT,
	LKML, Peter Zijlstra

On Wed, Dec 22, 2021 at 4:50 PM Zhaoyang Huang <huangzhaoyang@gmail.com> wrote:
>
> @Peter Zijlstra @Johannes Weiner
> Would you please review this patch? We would like to have it be merged
> ASAP. Thanks.

It's the holiday season, so I would not expect a quick turnaround.

>
> On Wed, Dec 22, 2021 at 8:31 AM Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > On Tue, Dec 21, 2021 at 4:24 PM Huangzhaoyang <huangzhaoyang@gmail.com> wrote:
> > >
> > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> >
> > Please remember to CC Peter.
> >
> > >
> > > When a new threshold breaching stall happens after a psi event was
> > > generated and within the window duration, the new event is not
> > > generated because the events are rate-limited to one per window. If
> > > after that no new stall is recorded then the event will not be
> > > generated even after rate-limiting duration has passed. This is
> > > happening because with no new stall, window_update will not be called
> > > even though threshold was previously breached. To fix this, record
> > > threshold breaching occurrence and generate the event once window
> > > duration is passed.
> > >
> > > Suggested-by: Suren Baghdasaryan <surenb@google.com>
> > > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > > ---
> > > v2: modify the logic according to Suren's suggestion
> > > v3: update commit message
> > > ---
> > > ---
> > >  include/linux/psi_types.h |  2 ++
> > >  kernel/sched/psi.c        | 38 +++++++++++++++++++++++---------------
> > >  2 files changed, 25 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
> > > index 0a23300..87b694a 100644
> > > --- a/include/linux/psi_types.h
> > > +++ b/include/linux/psi_types.h
> > > @@ -132,6 +132,8 @@ struct psi_trigger {
> > >
> > >         /* Refcounting to prevent premature destruction */
> > >         struct kref refcount;
> > > +
> > > +       bool threshold_breach;
> > >  };
> > >
> > >  struct psi_group {
> > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > > index 1652f2b..5c67ab9 100644
> > > --- a/kernel/sched/psi.c
> > > +++ b/kernel/sched/psi.c
> > > @@ -524,24 +524,29 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> > >          */
> > >         list_for_each_entry(t, &group->triggers, node) {
> > >                 u64 growth;
> > > +               bool trigger_stalled =
> > > +                       group->polling_total[t->state] != total[t->state];
> > >
> > > -               /* Check for stall activity */
> > > -               if (group->polling_total[t->state] == total[t->state])
> > > -                       continue;
> > > -
> > > -               /*
> > > -                * Multiple triggers might be looking at the same state,
> > > -                * remember to update group->polling_total[] once we've
> > > -                * been through all of them. Also remember to extend the
> > > -                * polling time if we see new stall activity.
> > > -                */
> > > -               new_stall = true;
> > > -
> > > -               /* Calculate growth since last update */
> > > -               growth = window_update(&t->win, now, total[t->state]);
> > > -               if (growth < t->threshold)
> > > +               /* Check for stall activity or a previous threshold breach */
> > > +               if (!trigger_stalled && !t->threshold_breach)
> > >                         continue;
> > >
> > > +               if (trigger_stalled) {
> > > +                       /*
> > > +                        * Multiple triggers might be looking at the same state,
> > > +                        * remember to update group->polling_total[] once we've
> > > +                        * been through all of them. Also remember to extend the
> > > +                        * polling time if we see new stall activity.
> > > +                        */
> > > +                       new_stall = true;
> > > +
> > > +                       /* Calculate growth since last update */
> > > +                       growth = window_update(&t->win, now, total[t->state]);
> > > +                       if (growth < t->threshold)
> > > +                               continue;
> > > +
> > > +                       t->threshold_breach = true;
> > > +               }
> > >                 /* Limit event signaling to once per window */
> > >                 if (now < t->last_event_time + t->win.size)
> > >                         continue;
> > > @@ -550,6 +555,8 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> > >                 if (cmpxchg(&t->event, 0, 1) == 0)
> > >                         wake_up_interruptible(&t->event_wait);
> > >                 t->last_event_time = now;
> > > +               /* Reset threshold breach flag once event got generated */
> > > +               t->threshold_breach = false;
> > >         }
> > >
> > >         if (new_stall)
> > > @@ -1152,6 +1159,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
> > >         t->last_event_time = 0;
> > >         init_waitqueue_head(&t->event_wait);
> > >         kref_init(&t->refcount);
> > > +       t->threshold_breach = false;
> > >
> > >         mutex_lock(&group->trigger_lock);
> > >
> > > --
> > > 1.9.1
> > >

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

end of thread, other threads:[~2021-12-23  1:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22  0:24 [PATCH v3] psi: fix possible trigger missing in the window Huangzhaoyang
2021-12-22  0:31 ` Suren Baghdasaryan
2021-12-23  0:50   ` Zhaoyang Huang
2021-12-23  1:11     ` Suren Baghdasaryan

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.