Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1023595yba; Thu, 4 Apr 2019 02:39:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqIYHyO64SS7yPT0f4rr/jQR0zXuMkP7F6Hkjs9wPDtjgCNKqVwfyVW8laet2UrOBaYvfg X-Received: by 2002:a17:902:1621:: with SMTP id g30mr5256877plg.116.1554370783279; Thu, 04 Apr 2019 02:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370783; cv=none; d=google.com; s=arc-20160816; b=ihHyoQVgMSnnskLaKR6Dqwo+UVOwnDrVuY+xQE0Lo3SNlHGOzcuZXMoaPGNECPry8H 0IghgHzBWM3GblakJB9ii/qRfubXyKWLdaCxajOKPF7gzNY+fVugIQgdYRmYiNFs4tQ2 qbJttVcBjzyUZ9i/v5EjVGY2eNchbANrsx8O8HM5KfB6NP47IiNuJ6nUrYmCQ2MU3CFS st16ck34cWuBjRIF4bObPlFOGi0OIiulKDgnADDAbQQ/VUse+ka9oZkQkv5kH0ShT/mg qOgJOPzFsTg34YmNVetARoJgG9wTChrImE1TZHtrziSVXRN4t3vRDaudbJLBRIxn1XoH M1yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HWipfp2Sq5qP87/Sm1EmWsJ663j4xX2t9IJFUFsiqLQ=; b=rOEN8vj11+TjZ/gts5hwYfPsLqxsW4lLSkIMhKNDddO+eEhfEjIWZjffA1V8aRYLxn TYedjR1PQGt4GCPpGCyUj0t8q4DV7SXY7ZTM9HGW18uLHIBAV6r2dGB0NMaxXIm+sHMh 8CgWeaANfeNTRZXVsc3p4JtbjXvO3t0Wsnou9QlfEArOwUt12Qrtv7Btuh99ZIP3+Kq3 m20w4wXW95D7YqO/npm9dPNkihsQ5lJs4Fw8Uw1YvBBSX+wyCLSZXV6Q3so2RXSmk6Ya p1lJ+JwjYt/NjuLssLuGwUG2oSdipnyl7B4mxRSfJyEGmMFBcferlJbSEa4+OYp1Yv7H Y6mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jhlf5TcB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l62si7953518pgd.168.2019.04.04.02.39.27; Thu, 04 Apr 2019 02:39:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jhlf5TcB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731876AbfDDJD6 (ORCPT + 99 others); Thu, 4 Apr 2019 05:03:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:41626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731871AbfDDJDw (ORCPT ); Thu, 4 Apr 2019 05:03:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DC5A21855; Thu, 4 Apr 2019 09:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368632; bh=aN2qvTfBxzBXAMrTLUcLlfNCWAmU6bJVjF4wJOtL99s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jhlf5TcBcmKz1kDu1/qO3AYvlN2CG3DvYPB1H9A7L+FW1tQ6vtc/cQxNzLvF+uRA+ vDZ4Tc1uCL6CZheBqlA8nrZ6PBk/GeEoTousUseOrNQDqGCqtTxpI8RZ9j6LbLXxbd SL4UaNvKgwhP8N7I2nAgIh3otdw96Q2E9Dh8xg7k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Sasha Levin Subject: [PATCH 4.19 095/187] cgroup, rstat: Dont flush subtree root unless necessary Date: Thu, 4 Apr 2019 10:47:12 +0200 Message-Id: <20190404084607.635838141@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit b4ff1b44bcd384d22fcbac6ebaf9cc0d33debe50 ] cgroup_rstat_cpu_pop_updated() is used to traverse the updated cgroups on flush. While it was only visiting updated ones in the subtree, it was visiting @root unconditionally. We can easily check whether @root is updated or not by looking at its ->updated_next just as with the cgroups in the subtree. * Remove the unnecessary cgroup_parent() test. The system root cgroup is never updated and thus its ->updated_next is always NULL. No need to test whether cgroup_parent() exists in addition to ->updated_next. * Terminate traverse if ->updated_next is NULL. This can only happen for subtree @root and there's no reason to visit it if it's not marked updated. This reduces cpu consumption when reading a lot of rstat backed files. In a micro benchmark reading stat from ~1600 cgroups, the sys time was lowered by >40%. Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/cgroup/rstat.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index d503d1a9007c..bb95a35e8c2d 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -87,7 +87,6 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos, struct cgroup *root, int cpu) { struct cgroup_rstat_cpu *rstatc; - struct cgroup *parent; if (pos == root) return NULL; @@ -115,8 +114,8 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos, * However, due to the way we traverse, @pos will be the first * child in most cases. The only exception is @root. */ - parent = cgroup_parent(pos); - if (parent && rstatc->updated_next) { + if (rstatc->updated_next) { + struct cgroup *parent = cgroup_parent(pos); struct cgroup_rstat_cpu *prstatc = cgroup_rstat_cpu(parent, cpu); struct cgroup_rstat_cpu *nrstatc; struct cgroup **nextp; @@ -140,9 +139,12 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos, * updated stat. */ smp_mb(); + + return pos; } - return pos; + /* only happens for @root */ + return NULL; } /* see cgroup_rstat_flush() */ -- 2.19.1