All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: Dynamically allocate the per-elt hist_elt_data array
@ 2021-09-02 20:57 Tom Zanussi
  2021-09-03 13:52 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Zanussi @ 2021-09-02 20:57 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Artem Bityutskiy, linux-kernel

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.

Signed-off-by: Tom Zanussi <zanussi@kernel.org>
---
 kernel/trace/trace_events_hist.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 9d91b1c06957..a6061a69aa84 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -508,7 +508,8 @@ struct track_data {
 struct hist_elt_data {
 	char *comm;
 	u64 *var_ref_vals;
-	char *field_var_str[SYNTH_FIELDS_MAX];
+	char **field_var_str;
+	int n_field_var_str;
 };
 
 struct snapshot_context {
@@ -1401,9 +1402,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data)
 {
 	unsigned int i;
 
-	for (i = 0; i < SYNTH_FIELDS_MAX; i++)
+	for (i = 0; i < elt_data->n_field_var_str; i++)
 		kfree(elt_data->field_var_str[i]);
 
+	kfree(elt_data->field_var_str);
+
 	kfree(elt_data->comm);
 	kfree(elt_data);
 }
@@ -1451,6 +1454,13 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
 
 	size = STR_VAR_LEN_MAX;
 
+	elt_data->field_var_str = kcalloc(n_str, sizeof(char *), GFP_KERNEL);
+	if (!elt_data->field_var_str) {
+		hist_elt_data_free(elt_data);
+		return -EINVAL;
+	}
+	elt_data->n_field_var_str = n_str;
+
 	for (i = 0; i < n_str; i++) {
 		elt_data->field_var_str[i] = kzalloc(size, GFP_KERNEL);
 		if (!elt_data->field_var_str[i]) {
-- 
2.17.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tracing: Dynamically allocate the per-elt hist_elt_data array
  2021-09-02 20:57 [PATCH] tracing: Dynamically allocate the per-elt hist_elt_data array Tom Zanussi
@ 2021-09-03 13:52 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2021-09-03 13:52 UTC (permalink / raw)
  To: Tom Zanussi, Steven Rostedt; +Cc: linux-kernel

On Thu, 2021-09-02 at 15:57 -0500, Tom Zanussi wrote:
> 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.
> 
> Signed-off-by: Tom Zanussi <zanussi@kernel.org>

Many thanks Tom! I've tested this one.

Tested-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-03 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 20:57 [PATCH] tracing: Dynamically allocate the per-elt hist_elt_data array Tom Zanussi
2021-09-03 13:52 ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.