From nobody Wed Apr 8 04:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14AA2C32793 for ; Wed, 24 Aug 2022 08:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbiHXITx (ORCPT ); Wed, 24 Aug 2022 04:19:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234979AbiHXITr (ORCPT ); Wed, 24 Aug 2022 04:19:47 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B718F65BF for ; Wed, 24 Aug 2022 01:19:45 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id r14-20020a17090a4dce00b001faa76931beso827352pjl.1 for ; Wed, 24 Aug 2022 01:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WejlGClWGOz4bz39sTGrt+zcC+1FgtAJxwc+yuBUn+0=; b=QkzRNE8TJAoxa395U9z1bSpDOL0XmFFWXvXjkujyohp4m+IMk0dOTbr8IRZfB+ovb2 k7b9W7LyHAQWVxnKxRsyM6cNd/fkAGtvvpQ6u7eLQnaTrpryXQbY/S7sweSPWZdrQxaA p8saNle7iyLF2t6eAOkcjPWOUp0UxSPvZlY3lHPdZQUKKPo4kQpgqtjgWRbmW3TtOUXn M8CXi4zUhKJxBm22fKxSgT5gUVuzLK8kcva0GCuONUwiKgY23N0MjaBgXLIlPow7U5Wa 6cXrkM0l5rSuJuxfVnjZZgsXltSOvzHEbRHM2NnBFgCdMV4KJvxvJPlsyS3r2+2n28IY uAGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WejlGClWGOz4bz39sTGrt+zcC+1FgtAJxwc+yuBUn+0=; b=kjpyHxcn8fkXOPbY0MfkWBkmxBmwluJK348sv2X1zkWqTx6wRRk61GydQviTH9xQ/M xwWcxRKbz/i+YOudaFBGKyvx8uh0Wql3iKuhWi/KFezyZHwEWMJqynJYrxY/Rwxn72c2 1VRYlbb0UoG4M7I74X9et7MsqpqKCVwuQP91bnnqhD3QQxmF+RyjwLKapBN7b3yAsONg nakNZWFMelTfa9nYa4/Uv1IqUYo25d9ySXJole2Ascdtjvf5RDvfBSTtdErbXnjIo+Nc /XP+PcgGAaEngZvp0CSqy70xmiUNgKGdv+DpaLG1P2NOyet+ugS25NIqiJ2opH2vCpnQ i8AQ== X-Gm-Message-State: ACgBeo0htlZyD7xY8jOL+vEBEC7zBZZdNSV14M/7hy+cCW5ZCJ4ixSnC 5zmbUgRGzmqbfaO3eGe+MjwEjA== X-Google-Smtp-Source: AA6agR40vU1zPgbtGYji72Q/9h5FA6BzjcQF5ct6JsOHHVEBNJqE1UnmsLnABo5S/ubOJm7FFC+OCw== X-Received: by 2002:a17:902:e88b:b0:172:fbf5:2e7c with SMTP id w11-20020a170902e88b00b00172fbf52e7cmr7955096plg.2.1661329185264; Wed, 24 Aug 2022 01:19:45 -0700 (PDT) Received: from C02CV1DAMD6P.bytedance.net ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id q31-20020a635c1f000000b00421841943dfsm10486587pgb.12.2022.08.24.01.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 01:19:44 -0700 (PDT) From: Chengming Zhou To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, surenb@google.com Cc: gregkh@linuxfoundation.org, corbet@lwn.net, mingo@redhat.com, peterz@infradead.org, songmuchun@bytedance.com, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Chengming Zhou Subject: [PATCH v3 01/10] sched/psi: fix periodic aggregation shut off Date: Wed, 24 Aug 2022 16:18:20 +0800 Message-Id: <20220824081829.33748-2-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220824081829.33748-1-zhouchengming@bytedance.com> References: <20220824081829.33748-1-zhouchengming@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We don't want to wake periodic aggregation work back up if the task change is the aggregation worker itself going to sleep, or we'll ping-pong forever. Previously, we would use psi_task_change() in psi_dequeue() when task going to sleep, so this check was put in psi_task_change(). But commit 4117cebf1a9f ("psi: Optimize task switch inside shared cgroups") defer task sleep handling to psi_task_switch(), won't go through psi_task_change() anymore. So this patch move this check to psi_task_switch(). Fixes: 4117cebf1a9f ("psi: Optimize task switch inside shared cgroups") Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner --- kernel/sched/psi.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index ecb4b4ff4ce0..39463dcc16bb 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -796,7 +796,6 @@ void psi_task_change(struct task_struct *task, int clea= r, int set) { int cpu =3D task_cpu(task); struct psi_group *group; - bool wake_clock =3D true; void *iter =3D NULL; u64 now; =20 @@ -806,19 +805,9 @@ void psi_task_change(struct task_struct *task, int cle= ar, int set) psi_flags_change(task, clear, set); =20 now =3D cpu_clock(cpu); - /* - * Periodic aggregation shuts off if there is a period of no - * task changes, so we wake it back up if necessary. However, - * don't do this if the task change is the aggregation worker - * itself going to sleep, or we'll ping-pong forever. - */ - if (unlikely((clear & TSK_RUNNING) && - (task->flags & PF_WQ_WORKER) && - wq_worker_last_func(task) =3D=3D psi_avgs_work)) - wake_clock =3D false; =20 while ((group =3D iterate_groups(task, &iter))) - psi_group_change(group, cpu, clear, set, now, wake_clock); + psi_group_change(group, cpu, clear, set, now, true); } =20 void psi_task_switch(struct task_struct *prev, struct task_struct *next, @@ -854,6 +843,7 @@ void psi_task_switch(struct task_struct *prev, struct t= ask_struct *next, =20 if (prev->pid) { int clear =3D TSK_ONCPU, set =3D 0; + bool wake_clock =3D true; =20 /* * When we're going to sleep, psi_dequeue() lets us @@ -867,13 +857,23 @@ void psi_task_switch(struct task_struct *prev, struct= task_struct *next, clear |=3D TSK_MEMSTALL_RUNNING; if (prev->in_iowait) set |=3D TSK_IOWAIT; + + /* + * Periodic aggregation shuts off if there is a period of no + * task changes, so we wake it back up if necessary. However, + * don't do this if the task change is the aggregation worker + * itself going to sleep, or we'll ping-pong forever. + */ + if (unlikely((prev->flags & PF_WQ_WORKER) && + wq_worker_last_func(prev) =3D=3D psi_avgs_work)) + wake_clock =3D false; } =20 psi_flags_change(prev, clear, set); =20 iter =3D NULL; while ((group =3D iterate_groups(prev, &iter)) && group !=3D common) - psi_group_change(group, cpu, clear, set, now, true); + psi_group_change(group, cpu, clear, set, now, wake_clock); =20 /* * TSK_ONCPU is handled up to the common ancestor. If we're tasked @@ -882,7 +882,7 @@ void psi_task_switch(struct task_struct *prev, struct t= ask_struct *next, if (sleep) { clear &=3D ~TSK_ONCPU; for (; group; group =3D iterate_groups(prev, &iter)) - psi_group_change(group, cpu, clear, set, now, true); + psi_group_change(group, cpu, clear, set, now, wake_clock); } } } --=20 2.37.2