Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9738941pxu; Tue, 29 Dec 2020 03:53:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR99qS/QX4oHP1z2FQTMegblj351DgElOgfwpYs0yLp6mVGsi4ntvDaCDdfgp/cLJ3tE7f X-Received: by 2002:a17:907:9627:: with SMTP id gb39mr45959896ejc.267.1609242803055; Tue, 29 Dec 2020 03:53:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609242803; cv=none; d=google.com; s=arc-20160816; b=eu7K55XkUN+ytDqSpJosBfgvt95bofdX4SuFUnm3vcc97LZOLFVzJF2x+TMMLJPKVW TlTjWyBe4b48Rsv2VR0lvwyusrmIUHAKiJ9X58uFObB9iO/ZVjCNJLT8ZR3db2aGyo4U W+AzPeKh6p6pubRJyX2zxnYUyXtP5glpoq4t9ZiXyJDZg8p9MfErJbis1B5/K3QqR+aF eLD4jGTC7m4yUDCsOAQ8a+eIC/6tJBdNa+QefTBuHitoHJhb6FhKX5OoiCp6FrZlo1oh aVZJUpfJn33GtvWW57M/D4mnHdiyx1tVcjrIR6lARoEncdbc8iqPeUDGjZC3pqBwgLw2 1HeQ== 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=yvGru5UMeULGzV0L1dFwEBQvOXIENDOJ82ED2W8T7kw=; b=sq/S/bpSZeV01rsAG2Pk6BqSi4CtgmwVN25dXYIbbe4PnezJ4S6uafILqo/4QDPedH yKZRetF6sSW3Q0dba5nFMrnbl0UUNbPymX6ddxbrvmtVb9Wq29hUQBrMEFXRSxgQ22QP F6kPaOo1+gqDyO1Pt6C5V9l6XIP90KCXGHmBwdQQ6vqX3H9yjmh6ROxHTNfJnlqFSGqt /PPQXkXh4s08F0Yhm3sl381sPJc5zkV8hB/GDJ8s7/ex+zJ9z1//tpOvCwM940Lw3eLL 3l3fxcSVM07rpYqoR6t5Fc2SBeo/4L7LjsdOtwgAc0jRbh0cmPIgpSVHCcOgJ9OHMs8e 4NcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h0Xt0F+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id b20si20999547ejk.726.2020.12.29.03.53.00; Tue, 29 Dec 2020 03:53:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h0Xt0F+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726048AbgL2LwW (ORCPT + 99 others); Tue, 29 Dec 2020 06:52:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:44478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgL2LwV (ORCPT ); Tue, 29 Dec 2020 06:52:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92A8820825; Tue, 29 Dec 2020 11:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609242700; bh=LE43JNvhJKsI7wyMokRmVvhFB60Mt6PQwR/tbJeav5w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h0Xt0F+rKbYfMo4KJCTqm8fus/HfA7VIADDVUsD7/4j3ItvNKg1c1woGDwLcyxoqM i8pgXpWrVZaEcIwQILJpoJHwl6ynsQKXKChR4rQm1upSoQWkB3sXUEzexw8H0ssbtx hiemlXe9P9fruKTEfN/GSHlpM+/j+0V+3kK8FoFjhhH3mbFvzjdQhVp3yjcOe648j3 biyWjPKdRIoaxqCxrx08Pi7JszKN90VFgydKITkt2IfudUn3HTEmgj4KARgei4VO/U rq/bcmOvO1wegwUM7s/HyhlGWazS/wPscXIDROYIw1wMtiy/8iS+viJinDbqLZGnfn ZIpW3G41DhDng== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 1BF2D411E9; Tue, 29 Dec 2020 08:51:58 -0300 (-03) Date: Tue, 29 Dec 2020 08:51:58 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , Ingo Molnar , Peter Zijlstra , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Ian Rogers , Andi Kleen Subject: Re: [PATCH 3/3] tools/lib/fs: Cache cgroupfs mount point Message-ID: <20201229115158.GH521329@kernel.org> References: <20201216090556.813996-1-namhyung@kernel.org> <20201216090556.813996-3-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201216090556.813996-3-namhyung@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Dec 16, 2020 at 06:05:56PM +0900, Namhyung Kim escreveu: > Currently it parses the /proc file everytime it opens a file in the > cgroupfs. Save the last result to avoid it (assuming it won't be > changed between the accesses). Which is the most likely case, but can't we use something like inotify to detect that and bail out or warn the user? - Arnaldo > Signed-off-by: Namhyung Kim > --- > tools/lib/api/fs/cgroup.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/tools/lib/api/fs/cgroup.c b/tools/lib/api/fs/cgroup.c > index 262a4229e293..1573dae4259d 100644 > --- a/tools/lib/api/fs/cgroup.c > +++ b/tools/lib/api/fs/cgroup.c > @@ -8,6 +8,14 @@ > #include > #include "fs.h" > > +struct cgroupfs_cache_entry { > + char subsys[32]; > + char mountpoint[PATH_MAX]; > +}; > + > +/* just cache last used one */ > +static struct cgroupfs_cache_entry cached; > + > int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) > { > FILE *fp; > @@ -16,6 +24,14 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) > char *p, *path; > char mountpoint[PATH_MAX]; > > + if (!strcmp(cached.subsys, subsys)) { > + if (strlen(cached.mountpoint) < maxlen) { > + strcpy(buf, cached.mountpoint); > + return 0; > + } > + return -1; > + } > + > fp = fopen("/proc/mounts", "r"); > if (!fp) > return -1; > @@ -75,6 +91,9 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) > free(line); > fclose(fp); > > + strncpy(cached.subsys, subsys, sizeof(cached.subsys) - 1); > + strcpy(cached.mountpoint, mountpoint); > + > if (mountpoint[0] && strlen(mountpoint) < maxlen) { > strcpy(buf, mountpoint); > return 0; > -- > 2.29.2.684.gfbc64c5ab5-goog > -- - Arnaldo