Skip to content

Commit 1066d1b

Browse files
laoarPeter Zijlstra
authored andcommitted
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 <[email protected]> Signed-off-by: Yafang Shao <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Johannes Weiner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a0fe6ba commit 1066d1b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

include/linux/sched.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,12 @@ struct task_struct {
785785
unsigned frozen:1;
786786
#endif
787787
#ifdef CONFIG_BLK_CGROUP
788-
/* to be used once the psi infrastructure lands upstream. */
789788
unsigned use_memdelay:1;
790789
#endif
790+
#ifdef CONFIG_PSI
791+
/* Stalled due to lack of memory */
792+
unsigned in_memstall:1;
793+
#endif
791794

792795
unsigned long atomic_flags; /* Flags requiring atomic access. */
793796

@@ -1480,7 +1483,6 @@ extern struct pid *cad_pid;
14801483
#define PF_KTHREAD 0x00200000 /* I am a kernel thread */
14811484
#define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */
14821485
#define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
1483-
#define PF_MEMSTALL 0x01000000 /* Stalled due to lack of memory */
14841486
#define PF_UMH 0x02000000 /* I'm an Usermodehelper process */
14851487
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */
14861488
#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */

kernel/sched/psi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,17 +865,17 @@ void psi_memstall_enter(unsigned long *flags)
865865
if (static_branch_likely(&psi_disabled))
866866
return;
867867

868-
*flags = current->flags & PF_MEMSTALL;
868+
*flags = current->in_memstall;
869869
if (*flags)
870870
return;
871871
/*
872-
* PF_MEMSTALL setting & accounting needs to be atomic wrt
872+
* in_memstall setting & accounting needs to be atomic wrt
873873
* changes to the task's scheduling state, otherwise we can
874874
* race with CPU migration.
875875
*/
876876
rq = this_rq_lock_irq(&rf);
877877

878-
current->flags |= PF_MEMSTALL;
878+
current->in_memstall = 1;
879879
psi_task_change(current, 0, TSK_MEMSTALL);
880880

881881
rq_unlock_irq(rq, &rf);
@@ -898,13 +898,13 @@ void psi_memstall_leave(unsigned long *flags)
898898
if (*flags)
899899
return;
900900
/*
901-
* PF_MEMSTALL clearing & accounting needs to be atomic wrt
901+
* in_memstall clearing & accounting needs to be atomic wrt
902902
* changes to the task's scheduling state, otherwise we could
903903
* race with CPU migration.
904904
*/
905905
rq = this_rq_lock_irq(&rf);
906906

907-
current->flags &= ~PF_MEMSTALL;
907+
current->in_memstall = 0;
908908
psi_task_change(current, TSK_MEMSTALL, 0);
909909

910910
rq_unlock_irq(rq, &rf);
@@ -970,7 +970,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to)
970970
} else if (task->in_iowait)
971971
task_flags = TSK_IOWAIT;
972972

973-
if (task->flags & PF_MEMSTALL)
973+
if (task->in_memstall)
974974
task_flags |= TSK_MEMSTALL;
975975

976976
if (task_flags)

kernel/sched/stats.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
7070
return;
7171

7272
if (!wakeup || p->sched_psi_wake_requeue) {
73-
if (p->flags & PF_MEMSTALL)
73+
if (p->in_memstall)
7474
set |= TSK_MEMSTALL;
7575
if (p->sched_psi_wake_requeue)
7676
p->sched_psi_wake_requeue = 0;
@@ -90,7 +90,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
9090
return;
9191

9292
if (!sleep) {
93-
if (p->flags & PF_MEMSTALL)
93+
if (p->in_memstall)
9494
clear |= TSK_MEMSTALL;
9595
} else {
9696
/*
@@ -117,14 +117,14 @@ static inline void psi_ttwu_dequeue(struct task_struct *p)
117117
* deregister its sleep-persistent psi states from the old
118118
* queue, and let psi_enqueue() know it has to requeue.
119119
*/
120-
if (unlikely(p->in_iowait || (p->flags & PF_MEMSTALL))) {
120+
if (unlikely(p->in_iowait || p->in_memstall)) {
121121
struct rq_flags rf;
122122
struct rq *rq;
123123
int clear = 0;
124124

125125
if (p->in_iowait)
126126
clear |= TSK_IOWAIT;
127-
if (p->flags & PF_MEMSTALL)
127+
if (p->in_memstall)
128128
clear |= TSK_MEMSTALL;
129129

130130
rq = __task_rq_lock(p, &rf);
@@ -149,7 +149,7 @@ static inline void psi_task_tick(struct rq *rq)
149149
if (static_branch_likely(&psi_disabled))
150150
return;
151151

152-
if (unlikely(rq->curr->flags & PF_MEMSTALL))
152+
if (unlikely(rq->curr->in_memstall))
153153
psi_memstall_tick(rq->curr, cpu_of(rq));
154154
}
155155
#else /* CONFIG_PSI */

0 commit comments

Comments
 (0)