From patchwork Tue Mar 17 01:28:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11441613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0DE0913 for ; Tue, 17 Mar 2020 01:28:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5EE94206C0 for ; Tue, 17 Mar 2020 01:28:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LIRr+yri" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EE94206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 90A5C6B0005; Mon, 16 Mar 2020 21:28:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8BBED6B0006; Mon, 16 Mar 2020 21:28:37 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 783B06B0007; Mon, 16 Mar 2020 21:28:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 5E5346B0005 for ; Mon, 16 Mar 2020 21:28:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1B5F5613E for ; Tue, 17 Mar 2020 01:28:37 +0000 (UTC) X-FDA: 76603119474.09.tree68_4b34ce5e0e822 X-Spam-Summary: 2,0,0,df41895025da4cea,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1345:1437:1535:1544:1605:1711:1730:1747:1777:1792:2393:2559:2562:2901:2910:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4118:4250:4321:4605:5007:6119:6261:6653:6737:7514:7903:9413:10004:10226:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12663:12895:12986:13138:13161:13229:13231:13972:14096:14181:14394:14687:14721:14877:21080:21444:21450:21451:21627:21666:21966:21990:30003:30045:30054,0,RBL:209.85.210.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: tree68_4b34ce5e0e822 X-Filterd-Recvd-Size: 7753 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Mar 2020 01:28:36 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id 3so3133782pff.4 for ; Mon, 16 Mar 2020 18:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Va5UX5LTG/PbDYFMWXp7ney7E1y0v7mEaerBejG/K4E=; b=LIRr+yriG6pj/VMT+1Pr//O7xrgS8MHGcxzp9wJOkKNBLJ5jmwhfxjtZvJcJzjrt7x sHKxBEZGEST4LY6FPAH/7JM0QjxPsDf/NbMTp6RJZPBHxL2MgcY8CUavdovsCw6aDCR4 YapO6UGg00zAy1zsDmEhtu6dMETR11zmqPfFhGbM6SHlda+SkjrENUR9eEwvNqKmPxYl CJEDUIFNYpa6SF+JTuIYV1fjuSchFv3Y11P/7DAz4mluZbH9cTPV70BXWNMynikt4hYj XZJi+ZFWVe4XQbm0+2rpTNIp97NPJW45YMWIIk+7u/tglVbouPnvue4OlvDA+Xhhay0m v+Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Va5UX5LTG/PbDYFMWXp7ney7E1y0v7mEaerBejG/K4E=; b=t2NNyH86EZdon+q02J5i2R7b0n3ww+VQIrPICzppbTud//e0ZuaZhmMdATyt/3eUIH 8idn+P/FNA/l/5MPk0kAlufNTlm721gbhmNXEOCwowkCfusJPBW+Mfmv2wRxCRtw4f6d gS7xtMIQXMdSuY3/C9Om5VSIW+4kYQyNpoeu/x9n4bAawMErJoDtsyDGAUzQKTk+iB5j 60gRvstd33WBMfRe03naWlgLuLVZIP7ClHuyOia7rmdcKJ8Wp2sJoCeIQO7KcCjvlBiD +R7UZ+zx3jFoEaLXYMiEINSUOFvJcSt5PtBZC0QuetVc0F53+OpT6gTPkriXghZBhExy 8+Xw== X-Gm-Message-State: ANhLgQ1jcR5tIJx6E+WlVYAXtT4BdnlnuR43lJAys8imz99wOk3zJ2p/ cBRUDbVqEtVNpUIBqsEuBhk= X-Google-Smtp-Source: ADFU+vsPf8UE++tkaMdzY8hRCKV9M94sAGnlJksmoCNjQGnxI5MTQofGsQO60+VW3X7RnDrk/pBqBw== X-Received: by 2002:a63:1459:: with SMTP id 25mr2641053pgu.427.1584408515489; Mon, 16 Mar 2020 18:28:35 -0700 (PDT) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id p8sm1062687pff.26.2020.03.16.18.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2020 18:28:34 -0700 (PDT) From: Yafang Shao To: hannes@cmpxchg.org, willy@infradead.org, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH v2] psi: move PF_MEMSTALL out of task->flags Date: Mon, 16 Mar 2020 21:28:05 -0400 Message-Id: <1584408485-1921-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Johannes Weiner Cc: Matthew Wilcox Signed-off-by: Yafang Shao --- include/linux/sched.h | 6 ++++-- kernel/sched/psi.c | 12 ++++++------ kernel/sched/stats.h | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 0d84f8f..c429e97 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -783,9 +783,12 @@ struct task_struct { unsigned frozen:1; #endif #ifdef CONFIG_BLK_CGROUP - /* 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 +1493,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 */