Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp357943rwe; Wed, 24 Aug 2022 02:07:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR4AXjTJmzt48bAeaQHfVAw/Q3/hY0nWkXZ7ty8I1pwoiWGkXS2TUiArLLndzHNlu5E8dq00 X-Received: by 2002:a63:6843:0:b0:422:3c40:21f7 with SMTP id d64-20020a636843000000b004223c4021f7mr23521506pgc.203.1661332058704; Wed, 24 Aug 2022 02:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661332058; cv=none; d=google.com; s=arc-20160816; b=nQ5nT94YnxE8z6lPTsjbGNeih26/hhtj+nxSx/9wes6LJQ8pB2txWBOmY/LZ18mceg 90zU5w1U3tqIMQ/MZYuAuFkMFb6Yw8cdGyrpAAr2ysYTWXy41kRRpGXtlHlUwgIsBXOB +UYnJIqIidCN7/Ze1rCV35KOgwWKY+sIXTh3eyXmDtkzXy6SjUqVN09RnMSP47xNLwzv +8zCI64RPg0XYWV3g0hgb7Rm0NJpIyA3+Y2fxJjepp7x/XbEzYbEIwtxEsNEYdSvDdaJ y9Ueg0vXdsoKWylk/m0MPeRka8O1zVBO/k36KAVMNEpxF/BG/1m+7EtsdXyH/StkaPFD CTCA== 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=h1njInj6+0OhDb5dvpxX7bRUejwiRI98B8XQXql9WZQ=; b=SQ5n8PVQbAM7WpyyRyyrJC+rULODRh5vatUM0BFD3Ii7Jx4XQvwpOxntRAaJkwxZ4a jUND/kiEoC04N1E3N8f5BDStOm1LEQ1cn5Cr6ip9lQsgSn9gW60amr/DCfSIZT4LXaOi n2DinVreIslm33fSKhfY04Z028kYqjhG22aGozpt+0cFfmSqTPjXZ83kkveGBgb6AuAB n4oVZfJyEhUYw5Q6xjNHgggUUxBCR5WhltQSGC41uZylIoXnsX1NSvTBNXU7CWrgFnYy gFRmqu+DpcRt5cq81QeUusJUkt/4kJfhHWo5qJm6athYo+D2llGQMGQLLAHtNWdz4HEL Me6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=6yf8wi5z; 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 o14-20020a635a0e000000b0041bf0a54ad0si13269526pgb.729.2022.08.24.02.07.26; Wed, 24 Aug 2022 02:07:38 -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=6yf8wi5z; 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 S235659AbiHXIUR (ORCPT + 99 others); Wed, 24 Aug 2022 04:20:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235584AbiHXIUL (ORCPT ); Wed, 24 Aug 2022 04:20:11 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F01B37FF93 for ; Wed, 24 Aug 2022 01:20:09 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id x14-20020a17090a8a8e00b001fb61a71d99so826213pjn.2 for ; Wed, 24 Aug 2022 01:20:09 -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=h1njInj6+0OhDb5dvpxX7bRUejwiRI98B8XQXql9WZQ=; b=6yf8wi5zNwzZEIkCgVGTFObmPAniOIiQplzYcLSqdfynQw4Vz6bS6N+/FmuzSny6ig IbyW0Ll7Ib5/jwQy0MXG8EzqmWCb3Z+6uOTpaat+70mhVmkKwAycfew2QvqpBorPYVpn j8UXv3nEOdb0xJXxSQbqLZu2SGvwDIRpmeOsvG6Meij2IOzxPdRcyTYoyp4tnOaBvrG0 ij0kKjV6+2yUcfuz5jgsZTb1l8Je8MXPyvvGRgtN8nbzcgBCzC+9q+XiNo6ZvIudhAV+ C3bE3iISnulIycKcpmRz9qXnmLn7bqfELsePToRk1Ibz7O2hAhd646bBzd+ws075cyUU k5Vw== 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=h1njInj6+0OhDb5dvpxX7bRUejwiRI98B8XQXql9WZQ=; b=7bVhpiNdrmTzJ/e1u1KBaScDbXMFBsLeucYCi71QRQTvvABoxQ9xYhKOuIcoP0CGoE NYuo5YAuA//JANTMhOHFlFlMqGVdTHgfqtNRSHZhUPQ9/W8n0tByjwuQIudzVXakfIGV d/AtwR/CdRMKBnL6sJf6autB6EMoD686E4YHRkmOsPzGlgG/wH4839mjCvPvd6QS8yTV kYoFRlRtoaF7oJwf3Ry1Dtxa/uG0xhY+IRoSDR1r66EPRSbtMfo0tVFUBu6yo3+zYOZF mbwz24N9mb1m4PYVC/YlMYBYDrXgVDrI/6US9NAZ86R4jA49IfL4/wYnJxqPrp4zEYVo PE3w== X-Gm-Message-State: ACgBeo0mDnXCJruAv5sHt+3JNIjZfndJkVbhkCaZy1gnMe1Y2aWmg+V/ RpX5/fwvIsRpV8rTg3dmHPb0yA== X-Received: by 2002:a17:902:cec1:b0:16d:c4f2:66c5 with SMTP id d1-20020a170902cec100b0016dc4f266c5mr27326630plg.20.1661329209524; Wed, 24 Aug 2022 01:20:09 -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.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 01:20:09 -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 05/10] sched/psi: optimize task switch inside shared cgroups again Date: Wed, 24 Aug 2022 16:18:24 +0800 Message-Id: <20220824081829.33748-6-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 commit 4117cebf1a9f ("psi: Optimize task switch inside shared cgroups") defer prev task sleep handling to psi_task_switch(), so we don't need to clear and set TSK_ONCPU state for common cgroups. A | B / \ C D / \ prev next After that commit psi_task_switch() do: 1. psi_group_change(next, .set=TSK_ONCPU) for D 2. psi_group_change(prev, .clear=TSK_ONCPU | TSK_RUNNING) for C 3. psi_group_change(prev, .clear=TSK_RUNNING) for B, A But there is a limitation "prev->psi_flags == next->psi_flags" that if not satisfied, will make this cgroups optimization unusable for both sleep switch or running switch cases. For example: prev->in_memstall != next->in_memstall when sleep switch: 1. psi_group_change(next, .set=TSK_ONCPU) for D, B, A 2. psi_group_change(prev, .clear=TSK_ONCPU | TSK_RUNNING) for C, B, A prev->in_memstall != next->in_memstall when running switch: 1. psi_group_change(next, .set=TSK_ONCPU) for D, B, A 2. psi_group_change(prev, .clear=TSK_ONCPU) for C, B, A The reason why this limitation exist is that we consider a group is PSI_MEM_FULL if the CPU is actively reclaiming and nothing productive could run even if it were runnable. So when CPU curr changed from prev to next and their in_memstall status is different, we have to change PSI_MEM_FULL status for their common cgroups. This patch remove this limitation by making psi_group_change() change PSI_MEM_FULL status depend on CPU curr->in_memstall status. Signed-off-by: Chengming Zhou --- kernel/sched/psi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 77d53c03a76f..26c03bd56b9c 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -820,8 +820,6 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, u64 now = cpu_clock(cpu); if (next->pid) { - bool identical_state; - psi_flags_change(next, 0, TSK_ONCPU); /* * When switching between tasks that have an identical @@ -829,11 +827,9 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, * we reach the first common ancestor. Iterate @next's * ancestors only until we encounter @prev's ONCPU. */ - identical_state = prev->psi_flags == next->psi_flags; iter = NULL; while ((group = iterate_groups(next, &iter))) { - if (identical_state && - per_cpu_ptr(group->pcpu, cpu)->tasks[NR_ONCPU]) { + if (per_cpu_ptr(group->pcpu, cpu)->tasks[NR_ONCPU]) { common = group; break; } @@ -880,7 +876,7 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, * TSK_ONCPU is handled up to the common ancestor. If we're tasked * with dequeuing too, finish that for the rest of the hierarchy. */ - if (sleep) { + if (sleep || unlikely(prev->in_memstall != next->in_memstall)) { clear &= ~TSK_ONCPU; for (; group; group = iterate_groups(prev, &iter)) psi_group_change(group, cpu, clear, set, now, wake_clock); -- 2.37.2