Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5648366img; Wed, 27 Mar 2019 12:24:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXolrAjw12JHhXuNEG0h4+U5AmK/JfVoWD69aKS2Kw74oW2Cc3zN5XtEp3YW+o2PEASRGQ X-Received: by 2002:a17:902:eb84:: with SMTP id cx4mr29700342plb.52.1553714666735; Wed, 27 Mar 2019 12:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714666; cv=none; d=google.com; s=arc-20160816; b=SMpJ0hf1/gZPjV20wV0eg+xCif56ii3K/mNlITiA8GdtfdQQ1QFw3wlfMJ4Nmid+/i VyhmNd1xuRY+m0ZReY07JjwrBU9jvcVxHT3R+9k0Cd+Sk06YeEQ+wQpVbAv5Bo75MGGe BS2D1nUeDCLt6/zBC8Cb8V2cABbTW3smtYWuGTQdNvsmxmUGHhIkf/mHNMbz7JTJSYfK FT2OPkKyyjbB0FVl7lo9LgDqeJwom9vYGJpJXmcuqaH6XvgeoNoDeX5M2PSdTY3Mc9lN ZRI8TJwiHtG5Oa6TTkSgFk9SgzVF2LTcIp2VA6cG7SVDV/wVmvHus+xh+4lO3OR2rpJt bfnA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vqhan5Mk59+8fMps6liLGehiiBjUQd9CrdBxCKi1Y0s=; b=kxi+TTYLrccEAXMFXQ+OmFJZkBpKpGrByte6nu8iVMt+w3G7JvrqCVjoeumnIILgZj j4YSPP9Vyj8GClfXzQ5AMY+C08L26/eWPh/wJVmAawrUYNr5/d54pr0JVYd1C/owkd6O UnVEKZu6KEvhh4S4Nk4NMwV5q3s6WJaFsekoRrq982phT0gC4rIF6sVtYy+WZDUj++ZF pstg5dkiV/fZ2JDwQQnDEJk86nmZeBZUKfguDNn1OC/daKt37yIGfZm0TeYmll3kwIHz JHWoqH52N/cJdVprT5AaoGSeKFOhFPj5vVfyVjaBuTIO2VCGaKhfHpwI+Rz4faVNF15A eBfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T+Mejj2l; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si11660442plo.166.2019.03.27.12.24.11; Wed, 27 Mar 2019 12:24:26 -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=T+Mejj2l; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388054AbfC0TXh (ORCPT + 99 others); Wed, 27 Mar 2019 15:23:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:47428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387830AbfC0SGA (ORCPT ); Wed, 27 Mar 2019 14:06:00 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A3D221734; Wed, 27 Mar 2019 18:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709959; bh=pylpkBLNcCZBLgMSDbploWxJ69hWPZeS0H5eeVswZy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+Mejj2lrNbtgd5j/iaQ/kU1D54sTpO+YpP53CSU/0Ep+sQLRxbWU/TOhcHbdegSv H8HbQlNHJFLktHktOYMzHZfQqDJiUwQsnFPfRgWZhVGML8bf1s8jj60KcgDJpjM8Fh 6GVuZbIWXtxbNsqd6ZgCz6TYGSSsIgbRFNTO5TiM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tejun Heo , Sasha Levin , cgroups@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 133/262] cgroup, rstat: Don't flush subtree root unless necessary Date: Wed, 27 Mar 2019 13:59:48 -0400 Message-Id: <20190327180158.10245-133-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo [ 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