psi: Move PF_MEMSTALL out of task->flags

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.
This patch also removes an out-of-date comment pointed by Matthew.

Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/1584408485-1921-1-git-send-email-laoar.shao@gmail.com
This commit is contained in:
Yafang Shao 2020-03-16 21:28:05 -04:00 committed by xxmustafacooTR
parent 8140fb8c12
commit 3893c1109c
No known key found for this signature in database
GPG key ID: 520B6FE385CBF5C9
3 changed files with 16 additions and 12 deletions

View file

@ -1760,6 +1760,11 @@ struct task_struct {
unsigned sched_contributes_to_load:1; unsigned sched_contributes_to_load:1;
unsigned sched_migrated:1; unsigned sched_migrated:1;
unsigned sched_remote_wakeup:1; unsigned sched_remote_wakeup:1;
#ifdef CONFIG_PSI
/* Stalled due to lack of memory */
unsigned in_memstall:1;
unsigned sched_psi_wake_requeue:1;
#endif
unsigned :0; /* force alignment to the next boundary */ unsigned :0; /* force alignment to the next boundary */
/* unserialized, strictly 'current' */ /* unserialized, strictly 'current' */
@ -2488,7 +2493,6 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut,
#define PF_KTHREAD 0x00200000 /* I am a kernel thread */ #define PF_KTHREAD 0x00200000 /* I am a kernel thread */
#define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */
#define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
#define PF_MEMSTALL 0x01000000 /* Stalled due to lack of memory */
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */ #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */
#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
#define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */

View file

@ -818,17 +818,17 @@ void psi_memstall_enter(unsigned long *flags)
if (static_branch_likely(&psi_disabled)) if (static_branch_likely(&psi_disabled))
return; return;
*flags = current->flags & PF_MEMSTALL; *flags = current->in_memstall;
if (*flags) if (*flags)
return; 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 * changes to the task's scheduling state, otherwise we can
* race with CPU migration. * race with CPU migration.
*/ */
rq = this_rq_lock_irq(&rf); rq = this_rq_lock_irq(&rf);
current->flags |= PF_MEMSTALL; current->in_memstall = 1;
psi_task_change(current, 0, TSK_MEMSTALL); psi_task_change(current, 0, TSK_MEMSTALL);
rq_unlock_irq(rq, &rf); rq_unlock_irq(rq, &rf);
@ -851,13 +851,13 @@ void psi_memstall_leave(unsigned long *flags)
if (*flags) if (*flags)
return; 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 * changes to the task's scheduling state, otherwise we could
* race with CPU migration. * race with CPU migration.
*/ */
rq = this_rq_lock_irq(&rf); rq = this_rq_lock_irq(&rf);
current->flags &= ~PF_MEMSTALL; current->in_memstall = 0;
psi_task_change(current, TSK_MEMSTALL, 0); psi_task_change(current, TSK_MEMSTALL, 0);
rq_unlock_irq(rq, &rf); rq_unlock_irq(rq, &rf);
@ -921,7 +921,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to)
else if (task->in_iowait) else if (task->in_iowait)
task_flags = TSK_IOWAIT; task_flags = TSK_IOWAIT;
if (task->flags & PF_MEMSTALL) if (task->in_memstall)
task_flags |= TSK_MEMSTALL; task_flags |= TSK_MEMSTALL;
if (task_flags) if (task_flags)

View file

@ -69,7 +69,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
return; return;
if (!wakeup || p->sched_psi_wake_requeue) { if (!wakeup || p->sched_psi_wake_requeue) {
if (p->flags & PF_MEMSTALL) if (p->in_memstall)
set |= TSK_MEMSTALL; set |= TSK_MEMSTALL;
if (p->sched_psi_wake_requeue) if (p->sched_psi_wake_requeue)
p->sched_psi_wake_requeue = 0; p->sched_psi_wake_requeue = 0;
@ -89,7 +89,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
return; return;
if (!sleep) { if (!sleep) {
if (p->flags & PF_MEMSTALL) if (p->in_memstall)
clear |= TSK_MEMSTALL; clear |= TSK_MEMSTALL;
} else { } else {
if (p->in_iowait) if (p->in_iowait)
@ -108,14 +108,14 @@ static inline void psi_ttwu_dequeue(struct task_struct *p)
* deregister its sleep-persistent psi states from the old * deregister its sleep-persistent psi states from the old
* queue, and let psi_enqueue() know it has to requeue. * 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_flags rf;
struct rq *rq; struct rq *rq;
int clear = 0; int clear = 0;
if (p->in_iowait) if (p->in_iowait)
clear |= TSK_IOWAIT; clear |= TSK_IOWAIT;
if (p->flags & PF_MEMSTALL) if (p->in_memstall)
clear |= TSK_MEMSTALL; clear |= TSK_MEMSTALL;
rq = __task_rq_lock(p, &rf); rq = __task_rq_lock(p, &rf);
@ -130,7 +130,7 @@ static inline void psi_task_tick(struct rq *rq)
if (static_branch_likely(&psi_disabled)) if (static_branch_likely(&psi_disabled))
return; return;
if (unlikely(rq->curr->flags & PF_MEMSTALL)) if (unlikely(rq->curr->in_memstall))
psi_memstall_tick(rq->curr, cpu_of(rq)); psi_memstall_tick(rq->curr, cpu_of(rq));
} }
#else /* CONFIG_PSI */ #else /* CONFIG_PSI */