Skip to content

Commit eef4fee

Browse files
captain5050acmel
authored andcommitted
perf lock: Dynamically allocate lockhash_table
lockhash_table is 32,768 bytes in .bss, make it a memory allocation so that the space is freed for non-lock perf commands. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: K Prateek Nayak <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Leo Yan <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Kan Liang <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 92294b9 commit eef4fee

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tools/perf/builtin-lock.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct target target;
4848
#define LOCKHASH_BITS 12
4949
#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS)
5050

51-
static struct hlist_head lockhash_table[LOCKHASH_SIZE];
51+
static struct hlist_head *lockhash_table;
5252

5353
#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS)
5454
#define lockhashentry(key) (lockhash_table + __lockhashfn((key)))
@@ -1871,7 +1871,6 @@ static int __cmd_contention(int argc, const char **argv)
18711871
};
18721872
struct lock_contention con = {
18731873
.target = &target,
1874-
.result = &lockhash_table[0],
18751874
.map_nr_entries = bpf_map_entries,
18761875
.max_stack = max_stack_depth,
18771876
.stack_skip = stack_skip,
@@ -1880,10 +1879,17 @@ static int __cmd_contention(int argc, const char **argv)
18801879
.owner = show_lock_owner,
18811880
};
18821881

1882+
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
1883+
if (!lockhash_table)
1884+
return -ENOMEM;
1885+
1886+
con.result = &lockhash_table[0];
1887+
18831888
session = perf_session__new(use_bpf ? NULL : &data, &eops);
18841889
if (IS_ERR(session)) {
18851890
pr_err("Initializing perf session failed\n");
1886-
return PTR_ERR(session);
1891+
err = PTR_ERR(session);
1892+
goto out_delete;
18871893
}
18881894

18891895
con.machine = &session->machines.host;
@@ -1983,6 +1989,7 @@ static int __cmd_contention(int argc, const char **argv)
19831989
evlist__delete(con.evlist);
19841990
lock_contention_finish();
19851991
perf_session__delete(session);
1992+
zfree(&lockhash_table);
19861993
return err;
19871994
}
19881995

@@ -2348,6 +2355,10 @@ int cmd_lock(int argc, const char **argv)
23482355
unsigned int i;
23492356
int rc = 0;
23502357

2358+
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
2359+
if (!lockhash_table)
2360+
return -ENOMEM;
2361+
23512362
for (i = 0; i < LOCKHASH_SIZE; i++)
23522363
INIT_HLIST_HEAD(lockhash_table + i);
23532364

@@ -2369,7 +2380,7 @@ int cmd_lock(int argc, const char **argv)
23692380
rc = __cmd_report(false);
23702381
} else if (!strcmp(argv[0], "script")) {
23712382
/* Aliased to 'perf script' */
2372-
return cmd_script(argc, argv);
2383+
rc = cmd_script(argc, argv);
23732384
} else if (!strcmp(argv[0], "info")) {
23742385
if (argc) {
23752386
argc = parse_options(argc, argv,
@@ -2403,5 +2414,6 @@ int cmd_lock(int argc, const char **argv)
24032414
usage_with_options(lock_usage, lock_options);
24042415
}
24052416

2417+
zfree(&lockhash_table);
24062418
return rc;
24072419
}

0 commit comments

Comments
 (0)