linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags
@ 2020-03-16 10:46 Yafang Shao
  2020-03-16 16:13 ` Johannes Weiner
  2020-03-16 16:40 ` Matthew Wilcox
  0 siblings, 2 replies; 4+ messages in thread
From: Yafang Shao @ 2020-03-16 10:46 UTC (permalink / raw)
  To: hannes, akpm, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman
  Cc: linux-mm, linux-kernel, Yafang Shao

The task->flags is a 32-bits flag, in which 31 bits have already been
consumed. So it is hardly to introduce other new per process flag.
Currently there're still enough spaces in the bit-field section of
task_struct, so we can define the memstall state as a single bit in
task_struct instead.

Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/linux/sched.h |  5 ++++-
 kernel/sched/psi.c    | 12 ++++++------
 kernel/sched/stats.h  | 10 +++++-----
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 0d84f8f..fe8cba2 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -786,6 +786,10 @@ struct task_struct {
 	/* to be used once the psi infrastructure lands upstream. */
 	unsigned			use_memdelay:1;
 #endif
+#ifdef CONFIG_PSI
+	/* Stalled due to lack of memory */
+	unsigned			in_memstall:1;
+#endif
 
 	unsigned long			atomic_flags; /* Flags requiring atomic access. */
 
@@ -1490,7 +1494,6 @@ static inline int is_global_init(struct task_struct *tsk)
 #define PF_KTHREAD		0x00200000	/* I am a kernel thread */
 #define PF_RANDOMIZE		0x00400000	/* Randomize virtual address space */
 #define PF_SWAPWRITE		0x00800000	/* Allowed to write to swap */
-#define PF_MEMSTALL		0x01000000	/* Stalled due to lack of memory */
 #define PF_UMH			0x02000000	/* I'm an Usermodehelper process */
 #define PF_NO_SETAFFINITY	0x04000000	/* Userland is not allowed to meddle with cpus_mask */
 #define PF_MCE_EARLY		0x08000000      /* Early kill for mce process policy */
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 517e371..d068e83 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -817,17 +817,17 @@ void psi_memstall_enter(unsigned long *flags)
 	if (static_branch_likely(&psi_disabled))
 		return;
 
-	*flags = current->flags & PF_MEMSTALL;
+	*flags = current->in_memstall;
 	if (*flags)
 		return;
 	/*
-	 * PF_MEMSTALL setting & accounting needs to be atomic wrt
+	 * in_memstall setting & accounting needs to be atomic wrt
 	 * changes to the task's scheduling state, otherwise we can
 	 * race with CPU migration.
 	 */
 	rq = this_rq_lock_irq(&rf);
 
-	current->flags |= PF_MEMSTALL;
+	current->in_memstall = 1;
 	psi_task_change(current, 0, TSK_MEMSTALL);
 
 	rq_unlock_irq(rq, &rf);
@@ -850,13 +850,13 @@ void psi_memstall_leave(unsigned long *flags)
 	if (*flags)
 		return;
 	/*
-	 * PF_MEMSTALL clearing & accounting needs to be atomic wrt
+	 * in_memstall clearing & accounting needs to be atomic wrt
 	 * changes to the task's scheduling state, otherwise we could
 	 * race with CPU migration.
 	 */
 	rq = this_rq_lock_irq(&rf);
 
-	current->flags &= ~PF_MEMSTALL;
+	current->in_memstall = 0;
 	psi_task_change(current, TSK_MEMSTALL, 0);
 
 	rq_unlock_irq(rq, &rf);
@@ -920,7 +920,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to)
 	else if (task->in_iowait)
 		task_flags = TSK_IOWAIT;
 
-	if (task->flags & PF_MEMSTALL)
+	if (task->in_memstall)
 		task_flags |= TSK_MEMSTALL;
 
 	if (task_flags)
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index ba683fe..199e304 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -70,7 +70,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
 		return;
 
 	if (!wakeup || p->sched_psi_wake_requeue) {
-		if (p->flags & PF_MEMSTALL)
+		if (p->in_memstall)
 			set |= TSK_MEMSTALL;
 		if (p->sched_psi_wake_requeue)
 			p->sched_psi_wake_requeue = 0;
@@ -90,7 +90,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
 		return;
 
 	if (!sleep) {
-		if (p->flags & PF_MEMSTALL)
+		if (p->in_memstall)
 			clear |= TSK_MEMSTALL;
 	} else {
 		if (p->in_iowait)
@@ -109,14 +109,14 @@ static inline void psi_ttwu_dequeue(struct task_struct *p)
 	 * deregister its sleep-persistent psi states from the old
 	 * queue, and let psi_enqueue() know it has to requeue.
 	 */
-	if (unlikely(p->in_iowait || (p->flags & PF_MEMSTALL))) {
+	if (unlikely(p->in_iowait || p->in_memstall)) {
 		struct rq_flags rf;
 		struct rq *rq;
 		int clear = 0;
 
 		if (p->in_iowait)
 			clear |= TSK_IOWAIT;
-		if (p->flags & PF_MEMSTALL)
+		if (p->in_memstall)
 			clear |= TSK_MEMSTALL;
 
 		rq = __task_rq_lock(p, &rf);
@@ -131,7 +131,7 @@ static inline void psi_task_tick(struct rq *rq)
 	if (static_branch_likely(&psi_disabled))
 		return;
 
-	if (unlikely(rq->curr->flags & PF_MEMSTALL))
+	if (unlikely(rq->curr->in_memstall))
 		psi_memstall_tick(rq->curr, cpu_of(rq));
 }
 #else /* CONFIG_PSI */
-- 
1.8.3.1


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

* Re: [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags
  2020-03-16 10:46 [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags Yafang Shao
@ 2020-03-16 16:13 ` Johannes Weiner
  2020-03-16 16:40 ` Matthew Wilcox
  1 sibling, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2020-03-16 16:13 UTC (permalink / raw)
  To: Yafang Shao
  Cc: akpm, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, linux-mm,
	linux-kernel

On Mon, Mar 16, 2020 at 06:46:25AM -0400, Yafang Shao wrote:
> The task->flags is a 32-bits flag, in which 31 bits have already been
> consumed. So it is hardly to introduce other new per process flag.
> Currently there're still enough spaces in the bit-field section of
> task_struct, so we can define the memstall state as a single bit in
> task_struct instead.
> 
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

Thanks for reworking it. This looks good to me.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

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

* Re: [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags
  2020-03-16 10:46 [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags Yafang Shao
  2020-03-16 16:13 ` Johannes Weiner
@ 2020-03-16 16:40 ` Matthew Wilcox
  2020-03-17  1:21   ` Yafang Shao
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2020-03-16 16:40 UTC (permalink / raw)
  To: Yafang Shao
  Cc: hannes, akpm, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, linux-mm,
	linux-kernel

On Mon, Mar 16, 2020 at 06:46:25AM -0400, Yafang Shao wrote:
> +++ b/include/linux/sched.h
> @@ -786,6 +786,10 @@ struct task_struct {
>  	/* to be used once the psi infrastructure lands upstream. */

That comment looks out of date ...

>  	unsigned			use_memdelay:1;

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

* Re: [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags
  2020-03-16 16:40 ` Matthew Wilcox
@ 2020-03-17  1:21   ` Yafang Shao
  0 siblings, 0 replies; 4+ messages in thread
From: Yafang Shao @ 2020-03-17  1:21 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Johannes Weiner, Andrew Morton, mingo, Peter Zijlstra,
	juri.lelli, Vincent Guittot, dietmar.eggemann, Steven Rostedt,
	Benjamin Segall, mgorman, Linux MM, LKML

On Tue, Mar 17, 2020 at 12:40 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Mon, Mar 16, 2020 at 06:46:25AM -0400, Yafang Shao wrote:
> > +++ b/include/linux/sched.h
> > @@ -786,6 +786,10 @@ struct task_struct {
> >       /* to be used once the psi infrastructure lands upstream. */
>
> That comment looks out of date ...
>

Yes, I will remove this comment.

> >       unsigned                        use_memdelay:1;


-- 
Yafang Shao
DiDi

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

end of thread, other threads:[~2020-03-17  1:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 10:46 [PATCH 1/1] psi: move PF_MEMSTALL out of task->flags Yafang Shao
2020-03-16 16:13 ` Johannes Weiner
2020-03-16 16:40 ` Matthew Wilcox
2020-03-17  1:21   ` Yafang Shao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).