Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools api fs: Dynamically allocate cgroupfs mount point cache, removing 4128 bytes from .bss

Move the cgroupfs_cache_entry 4128 byte array out of .bss.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Ross Zwisler <zwisler@chromium.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230526183401.2326121-15-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
7a3fb8b5 d9c26d45

+11 -6
+11 -6
tools/lib/api/fs/cgroup.c
··· 14 14 }; 15 15 16 16 /* just cache last used one */ 17 - static struct cgroupfs_cache_entry cached; 17 + static struct cgroupfs_cache_entry *cached; 18 18 19 19 int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) 20 20 { ··· 24 24 char *p, *path; 25 25 char mountpoint[PATH_MAX]; 26 26 27 - if (!strcmp(cached.subsys, subsys)) { 28 - if (strlen(cached.mountpoint) < maxlen) { 29 - strcpy(buf, cached.mountpoint); 27 + if (cached && !strcmp(cached->subsys, subsys)) { 28 + if (strlen(cached->mountpoint) < maxlen) { 29 + strcpy(buf, cached->mountpoint); 30 30 return 0; 31 31 } 32 32 return -1; ··· 91 91 free(line); 92 92 fclose(fp); 93 93 94 - strncpy(cached.subsys, subsys, sizeof(cached.subsys) - 1); 95 - strcpy(cached.mountpoint, mountpoint); 94 + if (!cached) 95 + cached = calloc(1, sizeof(*cached)); 96 + 97 + if (cached) { 98 + strncpy(cached->subsys, subsys, sizeof(cached->subsys) - 1); 99 + strcpy(cached->mountpoint, mountpoint); 100 + } 96 101 97 102 if (mountpoint[0] && strlen(mountpoint) < maxlen) { 98 103 strcpy(buf, mountpoint);