All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tom Zanussi <zanussi@kernel.org>,
	Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Subject: [for-next][PATCH 11/12] tracing: Dynamically allocate the per-elt hist_elt_data array
Date: Wed, 08 Sep 2021 15:19:02 -0400	[thread overview]
Message-ID: <20210908191955.156889693@goodmis.org> (raw)
In-Reply-To: 20210908191851.381347939@goodmis.org

From: Tom Zanussi <zanussi@kernel.org>

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/d52ae0ad5e1b59af7c4f54faf3fc098461fd82b3.camel@kernel.org

Signed-off-by: Tom Zanussi <zanussi@kernel.org>
Tested-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.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.32.0

  parent reply	other threads:[~2021-09-08 19:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 19:18 [for-next][PATCH 00/12] tracing: More updates for 5.15 Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 01/12] tracing: Add migrate-disabled counter to tracing output Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 02/12] tracing: Fix some alloc_event_probe() error handling bugs Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 03/12] tracing/osnoise: Fix missed cpus_read_unlock() in start_per_cpu_kthreads() Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 04/12] init: bootconfig: Remove all bootconfig data when the init memory is removed Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 05/12] init/bootconfig: Reorder init parameter from bootconfig and cmdline Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 06/12] docs: bootconfig: Add how to use bootconfig for kernel parameters Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 07/12] tools/bootconfig: Fix tracing_on option checking in ftrace2bconf.sh Steven Rostedt
2021-09-08 19:18 ` [for-next][PATCH 08/12] bootconfig: Fix missing return check of xbc_node_compose_key function Steven Rostedt
2021-09-08 19:28   ` Steven Rostedt
2021-09-08 19:19 ` [for-next][PATCH 09/12] tools/bootconfig: Show whole test command for each test case Steven Rostedt
2021-09-08 19:19 ` [for-next][PATCH 10/12] tracing: synth events: increase max fields count Steven Rostedt
2021-09-08 19:19 ` Steven Rostedt [this message]
2021-09-08 19:19 ` [for-next][PATCH 12/12] selftests/ftrace: Exclude "(fault)" in testing add/remove eprobe events Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908191955.156889693@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.