Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp207803imi; Wed, 20 Jul 2022 21:38:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vilS5F6ZlRFsOH6aHYS/FH0Q8dKq3Gago84dnxBvpcPLf4RhxlfmhZLnIJsd951doLb5O9 X-Received: by 2002:a17:907:7617:b0:72b:49fe:fdf7 with SMTP id jx23-20020a170907761700b0072b49fefdf7mr40628756ejc.25.1658378295950; Wed, 20 Jul 2022 21:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658378295; cv=none; d=google.com; s=arc-20160816; b=jUbQSK6q9z15XVPGnT7e9D/YVUqw8zEfL+g/NEoQYReL66rlU4LnnQ5PYj4OLX8Zxk 8ASbDLhRsL8hccO4KvaIFRxbOpA+DBQTuDeo6euIgtCoFeBD5bumcciDJrGEAHqFBxRH iKQ0Jx4ZNCOwIDz9EznoyQBjhhDj7hKh/XJaxo6zE1j5Tfs3B2T72iK2Zr+EG1GB6xw5 1unRhoav5Z7iy2nkcSPprLCcrR8/1IlsBwogiBEPhxI1Xd2bm1lR58/ev7ptecvSEcie Tl9R7RYKZQhvH3Xx9tG/iBxVrDZGULE4KVCNsFUiPaWQi1eFQ+xBrn9ddY0P7ny0Fus5 N8Xw== 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=dTUtciELDeUFP9YP7rSaShsOCbzI7poCIUEZlQHjgPU=; b=J8b2ibsVYRZSVRzEnmcJHwKEqO0M1oi2zhpDzFMqvuXtQ0190U16i+vlYfF3rGtyj4 7Hf8SFWAvT/4IWwEir1DkJ8esABW0JXS+CEuJpnvrFp7Jx0iWp7Ft36bp2ybO8VLvtpJ qhCzKxgMTWZiCNLkFR8DsB48IQw9mHppEzxKbkPZ8b7S1h8iBaPNHToCETiVQwPO7rR4 ROlMSchSmDCXVOnX827u4fPcyphYcnZTQMukEOTQ+BrnbYhW0evhEBMdsqcbNPBdKdmK hwaFkw6WDHBBwMBSldrf85IBOO25pbPaxd7JqoIWtsTyRZ3Q1NI2g+rzzEmlDcskVJBk yN2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=X7slEwVN; 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 dr6-20020a170907720600b0072b5cece992si1506817ejc.386.2022.07.20.21.37.50; Wed, 20 Jul 2022 21:38:15 -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=X7slEwVN; 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 S231600AbiGUEFQ (ORCPT + 99 others); Thu, 21 Jul 2022 00:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbiGUEFI (ORCPT ); Thu, 21 Jul 2022 00:05:08 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28CD1BEB for ; Wed, 20 Jul 2022 21:05:04 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id o18so511754pgu.9 for ; Wed, 20 Jul 2022 21:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dTUtciELDeUFP9YP7rSaShsOCbzI7poCIUEZlQHjgPU=; b=X7slEwVNzOA4SvR6+UzacobU5Ug/dz94gOEN7pAFTdSNd9xZdz08+zlSKHsdwOLoRt iNyy6n95zaI/xRzVsBx3OCK/CTa5pJqYfIYD5e9q+1R6fVh51E5EZrqDYAx7mP4hCYm4 MWPqJeGu0OLiIahmXD4tNDzAmeTYF+OdFLenYGIDq5uqoUPy7gXO8lRzmABO9Va4i/GI 2+1ExmHAKB+79axJoSXTeCQWRcBoMO40LGYC1IbEn6N3pXe2R14PnVUwO5ocDeGDO42o p6FPyugaUju6EfK1YwI+UYIBih58EYtCIRrNp/BsqYBsp1HfDTfujG7dgK6PxPbGb4UE 9ZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dTUtciELDeUFP9YP7rSaShsOCbzI7poCIUEZlQHjgPU=; b=h1mgln95mxzEhBGiJ1I6kDp442VY81s69FCvPCfW+EyjP4ObLJR/bUwxkQksNWOZPW HjmLT0XGVsPvAUfpJtGJwc/WOAVT7oJ3Mp6MYkuMgmDI6I2QXFGY6ofv0TXmVLwgCXEa CKG6lraToZKwJK0yDcfOE20fdFucuMY2E3wfYwZ9R6g6/GpTG1vjn+IxwZlQP5yBUsu7 M8eLiV328so/Vu/TVgdoSQL9ToeUmG7mZCigwDQkXC2dNBqkTsV/Nu9jhw/x5KnhnarV M78j1m+ESBp8ujLFaU/0o7OuIDDqW5gwA15AuxmBye+WQO/7XjQVeJCOvNMZ8m0MoGfA SNbQ== X-Gm-Message-State: AJIora+NCD3H5tI+OQsvXAV1upSNU4FtcSgbLJYzSoS/uexGj5Xb40t2 LICiWYeMX/+n+bh3vfPL7+uelA== X-Received: by 2002:a63:c15:0:b0:411:f92a:8ec7 with SMTP id b21-20020a630c15000000b00411f92a8ec7mr36026236pgl.86.1658376303964; Wed, 20 Jul 2022 21:05:03 -0700 (PDT) Received: from C02CV1DAMD6P.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id f4-20020a170902684400b0016bdf0032b9sm384368pln.110.2022.07.20.21.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 21:05:03 -0700 (PDT) From: Chengming Zhou To: hannes@cmpxchg.org, surenb@google.com, mingo@redhat.com, peterz@infradead.org, tj@kernel.org, corbet@lwn.net, akpm@linux-foundation.org, rdunlap@infradead.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, songmuchun@bytedance.com, cgroups@vger.kernel.org, Chengming Zhou Subject: [PATCH 2/9] sched/psi: optimize task switch inside shared cgroups again Date: Thu, 21 Jul 2022 12:04:32 +0800 Message-Id: <20220721040439.2651-3-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220721040439.2651-1-zhouchengming@bytedance.com> References: <20220721040439.2651-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 autolearn=unavailable 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 c8a4e644cd2c..e04041d8251b 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -823,8 +823,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 @@ -832,11 +830,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; } @@ -883,7 +879,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, true); -- 2.36.1