linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tom Zanussi <zanussi@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH v2 1/2] tracing: Have histogram types be constant when possible
Date: Fri, 23 Jul 2021 00:24:33 +0900	[thread overview]
Message-ID: <20210723002433.8abeddba573035f0b7b21739@kernel.org> (raw)
In-Reply-To: <20210722142837.280718447@goodmis.org>

On Thu, 22 Jul 2021 10:27:06 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Instead of kstrdup("const", GFP_KERNEL), have the hist_field type simply
> assign the constant hist_field->type = "const"; And when the value passed
> to it is a variable, use "kstrdup_const(var, GFP_KERNEL);" which will just
> copy the value if the variable is already a constant. This saves on having
> to allocate when not needed.
> 
> All frees of the hist_field->type will need to use kfree_const().
> 

Thanks! This looks good to me.

Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>


> Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  kernel/trace/trace_events_hist.c | 32 ++++++++++++++------------------
>  1 file changed, 14 insertions(+), 18 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 34325f41ebc0..5c9082201bc2 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -1589,7 +1589,9 @@ static void __destroy_hist_field(struct hist_field *hist_field)
>  
>  	kfree(hist_field->var.name);
>  	kfree(hist_field->name);
> -	kfree(hist_field->type);
> +
> +	/* Can likely be a const */
> +	kfree_const(hist_field->type);
>  
>  	kfree(hist_field->system);
>  	kfree(hist_field->event_name);
> @@ -1646,9 +1648,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
>  	if (flags & HIST_FIELD_FL_HITCOUNT) {
>  		hist_field->fn = hist_field_counter;
>  		hist_field->size = sizeof(u64);
> -		hist_field->type = kstrdup("u64", GFP_KERNEL);
> -		if (!hist_field->type)
> -			goto free;
> +		hist_field->type = "u64";
>  		goto out;
>  	}
>  
> @@ -1662,7 +1662,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
>  		hist_field->fn = hist_field_log2;
>  		hist_field->operands[0] = create_hist_field(hist_data, field, fl, NULL);
>  		hist_field->size = hist_field->operands[0]->size;
> -		hist_field->type = kstrdup(hist_field->operands[0]->type, GFP_KERNEL);
> +		hist_field->type = kstrdup_const(hist_field->operands[0]->type, GFP_KERNEL);
>  		if (!hist_field->type)
>  			goto free;
>  		goto out;
> @@ -1671,18 +1671,14 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
>  	if (flags & HIST_FIELD_FL_TIMESTAMP) {
>  		hist_field->fn = hist_field_timestamp;
>  		hist_field->size = sizeof(u64);
> -		hist_field->type = kstrdup("u64", GFP_KERNEL);
> -		if (!hist_field->type)
> -			goto free;
> +		hist_field->type = "u64";
>  		goto out;
>  	}
>  
>  	if (flags & HIST_FIELD_FL_CPU) {
>  		hist_field->fn = hist_field_cpu;
>  		hist_field->size = sizeof(int);
> -		hist_field->type = kstrdup("unsigned int", GFP_KERNEL);
> -		if (!hist_field->type)
> -			goto free;
> +		hist_field->type = "unsigned int";
>  		goto out;
>  	}
>  
> @@ -1695,7 +1691,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
>  		flags |= HIST_FIELD_FL_STRING;
>  
>  		hist_field->size = MAX_FILTER_STR_VAL;
> -		hist_field->type = kstrdup(field->type, GFP_KERNEL);
> +		hist_field->type = kstrdup_const(field->type, GFP_KERNEL);
>  		if (!hist_field->type)
>  			goto free;
>  
> @@ -1708,7 +1704,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
>  	} else {
>  		hist_field->size = field->size;
>  		hist_field->is_signed = field->is_signed;
> -		hist_field->type = kstrdup(field->type, GFP_KERNEL);
> +		hist_field->type = kstrdup_const(field->type, GFP_KERNEL);
>  		if (!hist_field->type)
>  			goto free;
>  
> @@ -1794,7 +1790,7 @@ static int init_var_ref(struct hist_field *ref_field,
>  		}
>  	}
>  
> -	ref_field->type = kstrdup(var_field->type, GFP_KERNEL);
> +	ref_field->type = kstrdup_const(var_field->type, GFP_KERNEL);
>  	if (!ref_field->type) {
>  		err = -ENOMEM;
>  		goto free;
> @@ -2163,7 +2159,7 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data,
>  	expr->operands[0] = operand1;
>  	expr->operator = FIELD_OP_UNARY_MINUS;
>  	expr->name = expr_str(expr, 0);
> -	expr->type = kstrdup(operand1->type, GFP_KERNEL);
> +	expr->type = kstrdup_const(operand1->type, GFP_KERNEL);
>  	if (!expr->type) {
>  		ret = -ENOMEM;
>  		goto free;
> @@ -2289,7 +2285,7 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
>  	expr->operands[1] = operand2;
>  	expr->operator = field_op;
>  	expr->name = expr_str(expr, 0);
> -	expr->type = kstrdup(operand1->type, GFP_KERNEL);
> +	expr->type = kstrdup_const(operand1->type, GFP_KERNEL);
>  	if (!expr->type) {
>  		ret = -ENOMEM;
>  		goto free;
> @@ -2677,10 +2673,10 @@ static struct hist_field *create_var(struct hist_trigger_data *hist_data,
>  	var->var.hist_data = var->hist_data = hist_data;
>  	var->size = size;
>  	var->var.name = kstrdup(name, GFP_KERNEL);
> -	var->type = kstrdup(type, GFP_KERNEL);
> +	var->type = kstrdup_const(type, GFP_KERNEL);
>  	if (!var->var.name || !var->type) {
> +		kfree_const(var->type);
>  		kfree(var->var.name);
> -		kfree(var->type);
>  		kfree(var);
>  		var = ERR_PTR(-ENOMEM);
>  	}
> -- 
> 2.30.2


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2021-07-22 15:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 14:27 [PATCH v2 0/2] tracing: Allow execnames to be passed as args for synthetic events Steven Rostedt
2021-07-22 14:27 ` [PATCH v2 1/2] tracing: Have histogram types be constant when possible Steven Rostedt
2021-07-22 15:24   ` Masami Hiramatsu [this message]
2021-07-22 22:11   ` Tom Zanussi
2021-07-22 14:27 ` [PATCH v2 2/2] tracing: Allow execnames to be passed as args for synthetic events Steven Rostedt
2021-07-22 16:19   ` Masami Hiramatsu
2021-07-22 16:32     ` Steven Rostedt
2021-07-23  1:11       ` Masami Hiramatsu
2021-07-23  1:22         ` Masami Hiramatsu
2021-07-23  1:26           ` Steven Rostedt
2021-07-23  1:24         ` Steven Rostedt
2021-07-24 10:31           ` Masami Hiramatsu
2021-07-25  2:18             ` Masami Hiramatsu
2021-07-25  3:45               ` Masami Hiramatsu
2021-07-26 13:28                 ` Steven Rostedt
2021-07-27 22:54                   ` Masami Hiramatsu
2021-07-22 22:09   ` Tom Zanussi
2021-07-22 15:14 ` [PATCH v2 0/2] " 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=20210723002433.8abeddba573035f0b7b21739@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).