Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1013450yba; Thu, 4 Apr 2019 02:26:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrFPJ82uvVqp47CQIZJVf0nUuwNWTUyCL18E/4RQeJGKeEFY0g3E/CjmPKaIn+wPZ2NhvE X-Received: by 2002:a17:902:7247:: with SMTP id c7mr5225504pll.255.1554369962636; Thu, 04 Apr 2019 02:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369962; cv=none; d=google.com; s=arc-20160816; b=w/pDGWGpx8Swh7V+ZNKrGOqI3BgUYT4xVa6A5WNkyVyTLqdzsclOc0ZiJpiUakSuKS iwfOrxGLV2SRo4/uhGOGonIS1TXLrEE+L1QdVaxpcO3CnGouC41l7eFeATAElbV8BXER BMc9oX+ottD/WyPUZA2nsUd+ju81HNaTzAEGo9Ulw4m8vHWO3CVfl8V2yph+U/bKAwkS uM0ryG1i8FeoCQOZw3vfBVXVVIbL91g6Pw6cdUOJYK1fMxucdZQNy/JgNDXqVtgpvhwf rRZsm3b0tgaDgb9g/pxYMLlFca1Nkx3VRjtBcDmRxZlzCjd6lbSYr6V7a8OAhF1CLfis v9yA== 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=ewVC2rHLhPbMm9NMLCgqKWsjuDVzl0MGPbsRMdZPtSM=; b=gajxMqHcYn+jlDRjNDz+t+H9bqA/7Mka94wGrOS1oOCN2WmHwr7J83Ayj6ShGybwko oTeBGL/GAK3ZvC43YzqZTChBds5tNKo9+lEMjiio6DeR+GQTCE2C4fAvjBofC5Vn7SdE 4qUrR028REw0a4kSiLN1iKnAX6jFMaPB66o6Fz6CHT2StNSQtzxxNK7oCQj4Zs9UFbnf 3EAA0Do0xQg9/E3yh7ApCbQFDDZscIBTZEDBXI2J6xlWR5UrH7QWR5Kev1+LoOjBsdrF xZ9V5gxN4SXnFIBxi1jPG4z/zlhiGqRi51aFJnSCYcLyHSvZlgBUKSDBTFOjdFfPN3ZY 717g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xTE2DLXF; 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 v9si15429951pgr.462.2019.04.04.02.25.47; Thu, 04 Apr 2019 02:26:02 -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=xTE2DLXF; 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 S2387647AbfDDJOC (ORCPT + 99 others); Thu, 4 Apr 2019 05:14:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:54410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732728AbfDDJN6 (ORCPT ); Thu, 4 Apr 2019 05:13:58 -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 60EAE2054F; Thu, 4 Apr 2019 09:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369237; bh=g4uu2wiihl9udC8yRPgooMGRTHAVtKIEtVR0lWXz5Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xTE2DLXFDVvobOHnWsDp9IWhXODcAOfH8AmzXn3hw82IVbRT1PXQnXyWTRYzmQn/Q uzYD2oPVboI5nxDAbHmT4A9gvVQ0ikr6Clw8T/AI/Rnr0ngqYfyaCnVRsM87EkbSTz SG5nWmQmEqdV2Ugun/R9ltkHHqM4tqtTMHbeQH+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Sasha Levin Subject: [PATCH 5.0 125/246] cgroup, rstat: Dont flush subtree root unless necessary Date: Thu, 4 Apr 2019 10:47:05 +0200 Message-Id: <20190404084623.534823626@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@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 5.0-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