mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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/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>
This commit is contained in:
		
							parent
							
								
									0be083cee4
								
							
						
					
					
						commit
						c910db943d
					
				
					 1 changed files with 12 additions and 2 deletions
				
			
		| 
						 | 
					@ -508,7 +508,8 @@ struct track_data {
 | 
				
			||||||
struct hist_elt_data {
 | 
					struct hist_elt_data {
 | 
				
			||||||
	char *comm;
 | 
						char *comm;
 | 
				
			||||||
	u64 *var_ref_vals;
 | 
						u64 *var_ref_vals;
 | 
				
			||||||
	char *field_var_str[SYNTH_FIELDS_MAX];
 | 
						char **field_var_str;
 | 
				
			||||||
 | 
						int n_field_var_str;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct snapshot_context {
 | 
					struct snapshot_context {
 | 
				
			||||||
| 
						 | 
					@ -1401,9 +1402,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned int i;
 | 
						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[i]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kfree(elt_data->field_var_str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kfree(elt_data->comm);
 | 
						kfree(elt_data->comm);
 | 
				
			||||||
	kfree(elt_data);
 | 
						kfree(elt_data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1451,6 +1454,13 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size = STR_VAR_LEN_MAX;
 | 
						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++) {
 | 
						for (i = 0; i < n_str; i++) {
 | 
				
			||||||
		elt_data->field_var_str[i] = kzalloc(size, GFP_KERNEL);
 | 
							elt_data->field_var_str[i] = kzalloc(size, GFP_KERNEL);
 | 
				
			||||||
		if (!elt_data->field_var_str[i]) {
 | 
							if (!elt_data->field_var_str[i]) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue