Skip to content

Commit c910db9

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Dynamically allocate the per-elt hist_elt_data array
Setting the hist_elt_data.field_var_str[] array unconditionally to a size of SYNTH_FIELD_MAX elements wastes space unnecessarily. The actual number of elements needed can be calculated at run-time instead. In most cases, this will save a lot of space since it's a per-elt array which isn't normally close to being full. It also allows us to increase SYNTH_FIELD_MAX without worrying about even more wastage when we do that. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Tom Zanussi <[email protected]> Tested-by: Artem Bityutskiy <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 0be083c commit c910db9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ struct track_data {
508508
struct hist_elt_data {
509509
char *comm;
510510
u64 *var_ref_vals;
511-
char *field_var_str[SYNTH_FIELDS_MAX];
511+
char **field_var_str;
512+
int n_field_var_str;
512513
};
513514

514515
struct snapshot_context {
@@ -1401,9 +1402,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data)
14011402
{
14021403
unsigned int i;
14031404

1404-
for (i = 0; i < SYNTH_FIELDS_MAX; i++)
1405+
for (i = 0; i < elt_data->n_field_var_str; i++)
14051406
kfree(elt_data->field_var_str[i]);
14061407

1408+
kfree(elt_data->field_var_str);
1409+
14071410
kfree(elt_data->comm);
14081411
kfree(elt_data);
14091412
}
@@ -1451,6 +1454,13 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
14511454

14521455
size = STR_VAR_LEN_MAX;
14531456

1457+
elt_data->field_var_str = kcalloc(n_str, sizeof(char *), GFP_KERNEL);
1458+
if (!elt_data->field_var_str) {
1459+
hist_elt_data_free(elt_data);
1460+
return -EINVAL;
1461+
}
1462+
elt_data->n_field_var_str = n_str;
1463+
14541464
for (i = 0; i < n_str; i++) {
14551465
elt_data->field_var_str[i] = kzalloc(size, GFP_KERNEL);
14561466
if (!elt_data->field_var_str[i]) {

0 commit comments

Comments
 (0)