Skip to content

Commit 7a3fb8b

Browse files
captain5050acmel
authored andcommitted
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>
1 parent d9c26d4 commit 7a3fb8b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/lib/api/fs/cgroup.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct cgroupfs_cache_entry {
1414
};
1515

1616
/* just cache last used one */
17-
static struct cgroupfs_cache_entry cached;
17+
static struct cgroupfs_cache_entry *cached;
1818

1919
int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys)
2020
{
@@ -24,9 +24,9 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys)
2424
char *p, *path;
2525
char mountpoint[PATH_MAX];
2626

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);
3030
return 0;
3131
}
3232
return -1;
@@ -91,8 +91,13 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys)
9191
free(line);
9292
fclose(fp);
9393

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+
}
96101

97102
if (mountpoint[0] && strlen(mountpoint) < maxlen) {
98103
strcpy(buf, mountpoint);

0 commit comments

Comments
 (0)