Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp336060rwe; Wed, 24 Aug 2022 01:40:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5D/T4tsZho02VD8feyeV3e627FnxbQqevr55K69ew/bXr7h1RRqjxxGq2JaJYxUTbhSJ+F X-Received: by 2002:a17:907:7e8c:b0:73d:85ec:46c with SMTP id qb12-20020a1709077e8c00b0073d85ec046cmr2063046ejc.257.1661330417960; Wed, 24 Aug 2022 01:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661330417; cv=none; d=google.com; s=arc-20160816; b=TSA8hAc6G95yOXqIfKC2UUNuoSg6uHErw8sKwym4V+dWjjsf6rugs6qT4xbO+XXdRB IkIjxwd/mbF9CbOyPIPqeyaF3WOd8v1MC2mdKYCOpHRn0V/atcI6AC7/9xM9vxl7S8bW zJKcSr4lE6W1j+FSq9+STKfdKgmqtuwhpcXdqtb8DzZG6jG3b8b8al38528ZPVUzUzOa 1IDTcSp8jaAWU/oIzjpeFy51X04rALe9yZrYEoQs7bnsG2+wzGKLQdHqr+22asYU7VyB DcoI+xyZWuOC04W7Grbjpsd4pHTEAJVO934BY/y+2+NUlBcHt6jgAszeh0jaEvQ+yK7x r0Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WejlGClWGOz4bz39sTGrt+zcC+1FgtAJxwc+yuBUn+0=; b=mKtNcnaTAW4AdJlS4RrOh8lnlx0m+270xXXVts90i7D35htL7lw/xafqTi/ulwbB4U XvdprdcVZ3AX9rWdC/16qdADUAdBETO09qWIvtkmvTDBc10OrL4kIkM+33QOpn8mpKne 6fcnA93d5+Re894I7qPE6x63KI/WHyEfL2/fMTaFI6MGiqg6AQwMrcmOvqkwgkUpRcEN j10oNhenPzk2429BGhlR0E+EsUKma5QKnvRvMLEPvsrqbzr1Zf7+xLh+sQS/kyVzuqmm OxjDyG8iq1Q9GH27BMytmX04ofCnylvdAKUflraNP4tMdhtcZVQ81ZCFeFN5wr/wvw0r eMrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QkzRNE8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js15-20020a17090797cf00b0073d83bc660asi1438770ejc.566.2022.08.24.01.39.51; Wed, 24 Aug 2022 01:40:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QkzRNE8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234996AbiHXITw (ORCPT + 99 others); Wed, 24 Aug 2022 04:19:52 -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-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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 clear, int set) { int cpu = task_cpu(task); struct psi_group *group; - bool wake_clock = true; void *iter = NULL; u64 now; @@ -806,19 +805,9 @@ void psi_task_change(struct task_struct *task, int clear, int set) psi_flags_change(task, clear, set); now = 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) == psi_avgs_work)) - wake_clock = false; while ((group = iterate_groups(task, &iter))) - psi_group_change(group, cpu, clear, set, now, wake_clock); + psi_group_change(group, cpu, clear, set, now, true); } 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 task_struct *next, if (prev->pid) { int clear = TSK_ONCPU, set = 0; + bool wake_clock = true; /* * 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 |= TSK_MEMSTALL_RUNNING; if (prev->in_iowait) set |= 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) == psi_avgs_work)) + wake_clock = false; } psi_flags_change(prev, clear, set); iter = NULL; while ((group = iterate_groups(prev, &iter)) && group != common) - psi_group_change(group, cpu, clear, set, now, true); + psi_group_change(group, cpu, clear, set, now, wake_clock); /* * 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 task_struct *next, if (sleep) { clear &= ~TSK_ONCPU; for (; group; group = iterate_groups(prev, &iter)) - psi_group_change(group, cpu, clear, set, now, true); + psi_group_change(group, cpu, clear, set, now, wake_clock); } } } -- 2.37.2