lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 29 Dec 2020 08:51:58 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Namhyung Kim <namhyung@...nel.org>
Cc:     Jiri Olsa <jolsa@...hat.com>, Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        LKML <linux-kernel@...r.kernel.org>,
        Stephane Eranian <eranian@...gle.com>,
        Ian Rogers <irogers@...gle.com>,
        Andi Kleen <ak@...ux.intel.com>
Subject: Re: [PATCH 3/3] tools/lib/fs: Cache cgroupfs mount point

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 <namhyung@...nel.org>
> ---
>  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 <string.h>
>  #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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ