Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Have histogram types be constant when possible

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().

Link: https://lkml.kernel.org/r/20210722142837.280718447@goodmis.org

Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+14 -18
+14 -18
kernel/trace/trace_events_hist.c
··· 1616 1616 1617 1617 kfree(hist_field->var.name); 1618 1618 kfree(hist_field->name); 1619 - kfree(hist_field->type); 1619 + 1620 + /* Can likely be a const */ 1621 + kfree_const(hist_field->type); 1620 1622 1621 1623 kfree(hist_field->system); 1622 1624 kfree(hist_field->event_name); ··· 1675 1673 if (flags & HIST_FIELD_FL_HITCOUNT) { 1676 1674 hist_field->fn = hist_field_counter; 1677 1675 hist_field->size = sizeof(u64); 1678 - hist_field->type = kstrdup("u64", GFP_KERNEL); 1679 - if (!hist_field->type) 1680 - goto free; 1676 + hist_field->type = "u64"; 1681 1677 goto out; 1682 1678 } 1683 1679 ··· 1690 1690 hist_field_bucket; 1691 1691 hist_field->operands[0] = create_hist_field(hist_data, field, fl, NULL); 1692 1692 hist_field->size = hist_field->operands[0]->size; 1693 - hist_field->type = kstrdup(hist_field->operands[0]->type, GFP_KERNEL); 1693 + hist_field->type = kstrdup_const(hist_field->operands[0]->type, GFP_KERNEL); 1694 1694 if (!hist_field->type) 1695 1695 goto free; 1696 1696 goto out; ··· 1699 1699 if (flags & HIST_FIELD_FL_TIMESTAMP) { 1700 1700 hist_field->fn = hist_field_timestamp; 1701 1701 hist_field->size = sizeof(u64); 1702 - hist_field->type = kstrdup("u64", GFP_KERNEL); 1703 - if (!hist_field->type) 1704 - goto free; 1702 + hist_field->type = "u64"; 1705 1703 goto out; 1706 1704 } 1707 1705 1708 1706 if (flags & HIST_FIELD_FL_CPU) { 1709 1707 hist_field->fn = hist_field_cpu; 1710 1708 hist_field->size = sizeof(int); 1711 - hist_field->type = kstrdup("unsigned int", GFP_KERNEL); 1712 - if (!hist_field->type) 1713 - goto free; 1709 + hist_field->type = "unsigned int"; 1714 1710 goto out; 1715 1711 } 1716 1712 ··· 1719 1723 flags |= HIST_FIELD_FL_STRING; 1720 1724 1721 1725 hist_field->size = MAX_FILTER_STR_VAL; 1722 - hist_field->type = kstrdup(field->type, GFP_KERNEL); 1726 + hist_field->type = kstrdup_const(field->type, GFP_KERNEL); 1723 1727 if (!hist_field->type) 1724 1728 goto free; 1725 1729 ··· 1732 1736 } else { 1733 1737 hist_field->size = field->size; 1734 1738 hist_field->is_signed = field->is_signed; 1735 - hist_field->type = kstrdup(field->type, GFP_KERNEL); 1739 + hist_field->type = kstrdup_const(field->type, GFP_KERNEL); 1736 1740 if (!hist_field->type) 1737 1741 goto free; 1738 1742 ··· 1818 1822 } 1819 1823 } 1820 1824 1821 - ref_field->type = kstrdup(var_field->type, GFP_KERNEL); 1825 + ref_field->type = kstrdup_const(var_field->type, GFP_KERNEL); 1822 1826 if (!ref_field->type) { 1823 1827 err = -ENOMEM; 1824 1828 goto free; ··· 2211 2215 expr->operands[0] = operand1; 2212 2216 expr->operator = FIELD_OP_UNARY_MINUS; 2213 2217 expr->name = expr_str(expr, 0); 2214 - expr->type = kstrdup(operand1->type, GFP_KERNEL); 2218 + expr->type = kstrdup_const(operand1->type, GFP_KERNEL); 2215 2219 if (!expr->type) { 2216 2220 ret = -ENOMEM; 2217 2221 goto free; ··· 2351 2355 2352 2356 expr->operator = field_op; 2353 2357 expr->name = expr_str(expr, 0); 2354 - expr->type = kstrdup(operand1->type, GFP_KERNEL); 2358 + expr->type = kstrdup_const(operand1->type, GFP_KERNEL); 2355 2359 if (!expr->type) { 2356 2360 ret = -ENOMEM; 2357 2361 goto free; ··· 2739 2743 var->var.hist_data = var->hist_data = hist_data; 2740 2744 var->size = size; 2741 2745 var->var.name = kstrdup(name, GFP_KERNEL); 2742 - var->type = kstrdup(type, GFP_KERNEL); 2746 + var->type = kstrdup_const(type, GFP_KERNEL); 2743 2747 if (!var->var.name || !var->type) { 2748 + kfree_const(var->type); 2744 2749 kfree(var->var.name); 2745 - kfree(var->type); 2746 2750 kfree(var); 2747 2751 var = ERR_PTR(-ENOMEM); 2748 2752 }