Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp859401rwe; Thu, 25 Aug 2022 10:19:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR5d8f4Rv6f+fW5PrbMDNwkMKRjvz0LPTu4VjHMlewGrAT0+R5LbMGZtlTXOPKI2G2EHo8tR X-Received: by 2002:a63:4501:0:b0:42b:609d:2fe6 with SMTP id s1-20020a634501000000b0042b609d2fe6mr115635pga.242.1661447953288; Thu, 25 Aug 2022 10:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661447953; cv=none; d=google.com; s=arc-20160816; b=AwrY2QJfgnQ8bkFxjKvEwe8EGIwIeGEPhqJwjiVDPq6EwGIU62EGed8nqrrxaaf1QQ mec11vtF72qgK9iaPsLRPqbRrJJYnMqI0M2dw4jbBX194c9ubgpSs6WFGnRdqwnxXhPd hgFkpOf+CoV68yBqds+JH6LoPe+qMqXPab2B86IizhMXt8a216izjN7YonNJDaKtbaKS nAUNJbU8wONkzf80U+/MtbiymLDv3vHgiHDPdt+fY5dl2y/SEBxj2/kBQt0qcE+XZm/k ED27rnvM8I9ZD+VJYk476qAF/l7BiyMO0+4JnAHqJigobmnZYyP4OvCajg0pbNWwHVGY R+EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3kaoHrknD8P9F02t3vtvA1BMAXsONZRXU6MvhQ9cGm0=; b=SQb8iq2kDSPyI6D2i319veU6uN665/loyW9FFLiXNpZfrMHw+z5NN9jE/XN/U/E5hF OFxdmhtYo/LGQFuz7ujtmE2XwfPdImNxO6b5lUzxOfU+WNlIJX+Q9FoX8zogHzT68f/T BRfkupZLeE8eOqMjXquxJK4dGp15hBnyWphGIZlmdTBBAKK7pkVrhYH1tEYlmlwWNy/T lWAIV5mKV2H+ljVJrZS0KC05N3Zk1++PM8FBGMSpagChJt+tNX91NjpXP0pU62Gcw7QP CVxyAfByXm6V4A5AFhd/F1HyxE9x76eKuvwBHJMb8hp1BaBwWS7luF9G6H6nyXcFZyJc EGUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Kx3Dht7p; 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=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a056a0021c800b0052dccbf4079si19553511pfj.220.2022.08.25.10.19.01; Thu, 25 Aug 2022 10:19:13 -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=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Kx3Dht7p; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237660AbiHYRQO (ORCPT + 99 others); Thu, 25 Aug 2022 13:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235860AbiHYRQN (ORCPT ); Thu, 25 Aug 2022 13:16:13 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0163B978 for ; Thu, 25 Aug 2022 10:16:10 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id kk26so11146547ejc.11 for ; Thu, 25 Aug 2022 10:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=3kaoHrknD8P9F02t3vtvA1BMAXsONZRXU6MvhQ9cGm0=; b=Kx3Dht7p+xMwF8txIAf16o45Jbd5BarQhl+hTLnStlK+dnLu8CQHK2RcIzo9QNnbV0 c4gNp7qmdE6YOchm2Gy+iMBaiQVOUufrpkH6vQ/g5W8LOb06aqEzTPQqYRVpm9jkNh1Q pKL1ofb86P3CBoNgi9kLOEAga5m+GZYCXEisz54+F706FD11ImkP96ot3klNK/RKOwDP g1Rp3pJ8PohBavZvYluu6a6WR2jA0Heg8yn0gy44KXBhLY5RlMCoFZxdnKx3/6Tgi3QF I52eXYKkogKjti2J+zLJZSiwMpBbRBET5warOvEzaVmiiMqQqz8dUTwQejSwcp+Pu6ji Z+8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=3kaoHrknD8P9F02t3vtvA1BMAXsONZRXU6MvhQ9cGm0=; b=basL5DheifT0LvXRgNhtytnHvdeb5AYAZdr9moYWunEJUrm2Xh+tLjVWjbBjn3HvGM a6E7b1a0sSe6vmf5CSD8A5ALMeUe+p/Sb9VnDm9ydHuj114otObSLC7uOvBXNrBUgKyg OmssnIzaPsYgTGGUElQQ6KM57I1o1UGLxFai8YypxikqEzprRTmSEKVgJ0y8gJWGb2iD iPrs8ZWVae/DDr4JoAjG92Nxg7XKD72YqfyNu/LAB/xSBnrzb8TXcmWvX08H0BudX+td 3WJ3XWVHslRwJQ+l5+LOY9QcTvkpEMltVt67oh3uqCGv8okacuWaIMd47wzhBmWF8tZS tslQ== X-Gm-Message-State: ACgBeo2khI4b/ybpO+WmHk1T0S5pJ68pqI9EilazGh6R3/xS2p0WitOG y56g9+u2Th6k9NwfD2H1cSkquQ== X-Received: by 2002:a17:907:72cf:b0:73d:d007:e249 with SMTP id du15-20020a17090772cf00b0073dd007e249mr2803387ejc.500.1661447768985; Thu, 25 Aug 2022 10:16:08 -0700 (PDT) Received: from localhost ([2a02:8070:6389:a4c0:2ca9:6d59:782b:fff3]) by smtp.gmail.com with ESMTPSA id i15-20020a0564020f0f00b0043cab10f702sm5199485eda.90.2022.08.25.10.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 10:16:08 -0700 (PDT) Date: Thu, 25 Aug 2022 13:16:07 -0400 From: Johannes Weiner To: Chengming Zhou Cc: tj@kernel.org, mkoutny@suse.com, surenb@google.com, mingo@redhat.com, peterz@infradead.org, gregkh@linuxfoundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, songmuchun@bytedance.com Subject: Re: [PATCH v4 05/10] sched/psi: optimize task switch inside shared cgroups again Message-ID: References: <20220825164111.29534-1-zhouchengming@bytedance.com> <20220825164111.29534-6-zhouchengming@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220825164111.29534-6-zhouchengming@bytedance.com> 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 On Fri, Aug 26, 2022 at 12:41:06AM +0800, Chengming Zhou wrote: > Way back when PSI_MEM_FULL was accounted from the timer tick, task > switching could simply iterate next and prev to the common ancestor to > update TSK_ONCPU and be done. > > Then memstall ticks were replaced with checking curr->in_memstall > directly in psi_group_change(). That meant that now if the task switch > was between a memstall and a !memstall task, we had to iterate through > the common ancestors at least ONCE to fix up their state_masks. > > We added the identical_state filter to make sure the common ancestor > elimination was skipped in that case. It seems that was always a > little too eager, because it caused us to walk the common ancestors > *twice* instead of the required once: the iteration for next could > have stopped at the common ancestor; prev could have updated TSK_ONCPU > up to the common ancestor, then finish to the root without changing > any flags, just to get the new curr->in_memstall into the state_masks. > > This patch recognizes this and makes it so that we walk to the root > exactly once if state_mask needs updating, which is simply catching up > on a missed optimization that could have been done in commit 7fae6c8171d2 > ("psi: Use ONCPU state tracking machinery to detect reclaim") directly. > > Apart from this, it's also necessary for the next patch "sched/psi: remove > NR_ONCPU task accounting". Suppose we walk the common ancestors twice: > > (1) psi_group_change(.clear = 0, .set = TSK_ONCPU) > (2) psi_group_change(.clear = TSK_ONCPU, .set = 0) > > We previously used tasks[NR_ONCPU] to record TSK_ONCPU, tasks[NR_ONCPU]++ > in (1) then tasks[NR_ONCPU]-- in (2), so tasks[NR_ONCPU] still be correct. > > The next patch change to use one bit in state mask to record TSK_ONCPU, > PSI_ONCPU bit will be set in (1), but then be cleared in (2), which cause > the psi_group_cpu has task running on CPU but without PSI_ONCPU bit set! > > With this patch, we will never walk the common ancestors twice, so won't > have above problem. > > Suggested-by: Johannes Weiner > Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner