ftrace: Add information on number of page groups allocated

Looking for ways to shrink the size of the dyn_ftrace structure, knowing the
information about how many pages and the number of groups of those pages, is
useful in working out the best ways to save on memory.

This adds one info print on how many groups of pages were used to allocate
the ftrace dyn_ftrace structures, and also shows the number of pages and
groups in the dyn_ftrace_total_info (which is used for debugging).
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 77ac117b
...@@ -2991,6 +2991,8 @@ static void ftrace_shutdown_sysctl(void) ...@@ -2991,6 +2991,8 @@ static void ftrace_shutdown_sysctl(void)
static u64 ftrace_update_time; static u64 ftrace_update_time;
unsigned long ftrace_update_tot_cnt; unsigned long ftrace_update_tot_cnt;
unsigned long ftrace_number_of_pages;
unsigned long ftrace_number_of_groups;
static inline int ops_traces_mod(struct ftrace_ops *ops) static inline int ops_traces_mod(struct ftrace_ops *ops)
{ {
...@@ -3115,6 +3117,9 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count) ...@@ -3115,6 +3117,9 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count)
goto again; goto again;
} }
ftrace_number_of_pages += 1 << order;
ftrace_number_of_groups++;
cnt = (PAGE_SIZE << order) / ENTRY_SIZE; cnt = (PAGE_SIZE << order) / ENTRY_SIZE;
pg->size = cnt; pg->size = cnt;
...@@ -3170,6 +3175,8 @@ ftrace_allocate_pages(unsigned long num_to_init) ...@@ -3170,6 +3175,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
start_pg = pg->next; start_pg = pg->next;
kfree(pg); kfree(pg);
pg = start_pg; pg = start_pg;
ftrace_number_of_pages -= 1 << order;
ftrace_number_of_groups--;
} }
pr_info("ftrace: FAILED to allocate memory for functions\n"); pr_info("ftrace: FAILED to allocate memory for functions\n");
return NULL; return NULL;
...@@ -6173,6 +6180,8 @@ void ftrace_release_mod(struct module *mod) ...@@ -6173,6 +6180,8 @@ void ftrace_release_mod(struct module *mod)
free_pages((unsigned long)pg->records, order); free_pages((unsigned long)pg->records, order);
tmp_page = pg->next; tmp_page = pg->next;
kfree(pg); kfree(pg);
ftrace_number_of_pages -= 1 << order;
ftrace_number_of_groups--;
} }
} }
...@@ -6514,6 +6523,8 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr) ...@@ -6514,6 +6523,8 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
*last_pg = pg->next; *last_pg = pg->next;
order = get_count_order(pg->size / ENTRIES_PER_PAGE); order = get_count_order(pg->size / ENTRIES_PER_PAGE);
free_pages((unsigned long)pg->records, order); free_pages((unsigned long)pg->records, order);
ftrace_number_of_pages -= 1 << order;
ftrace_number_of_groups--;
kfree(pg); kfree(pg);
pg = container_of(last_pg, struct ftrace_page, next); pg = container_of(last_pg, struct ftrace_page, next);
if (!(*last_pg)) if (!(*last_pg))
...@@ -6569,6 +6580,9 @@ void __init ftrace_init(void) ...@@ -6569,6 +6580,9 @@ void __init ftrace_init(void)
__start_mcount_loc, __start_mcount_loc,
__stop_mcount_loc); __stop_mcount_loc);
pr_info("ftrace: allocated %ld pages with %ld groups\n",
ftrace_number_of_pages, ftrace_number_of_groups);
set_ftrace_early_filters(); set_ftrace_early_filters();
return; return;
......
...@@ -7583,14 +7583,23 @@ static ssize_t ...@@ -7583,14 +7583,23 @@ static ssize_t
tracing_read_dyn_info(struct file *filp, char __user *ubuf, tracing_read_dyn_info(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
unsigned long *p = filp->private_data; ssize_t ret;
char buf[64]; /* Not too big for a shallow stack */ char *buf;
int r; int r;
r = scnprintf(buf, 63, "%ld", *p); /* 256 should be plenty to hold the amount needed */
buf[r++] = '\n'; buf = kmalloc(256, GFP_KERNEL);
if (!buf)
return -ENOMEM;
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); r = scnprintf(buf, 256, "%ld pages:%ld groups: %ld\n",
ftrace_update_tot_cnt,
ftrace_number_of_pages,
ftrace_number_of_groups);
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
kfree(buf);
return ret;
} }
static const struct file_operations tracing_dyn_info_fops = { static const struct file_operations tracing_dyn_info_fops = {
...@@ -8782,7 +8791,7 @@ static __init int tracer_init_tracefs(void) ...@@ -8782,7 +8791,7 @@ static __init int tracer_init_tracefs(void)
#ifdef CONFIG_DYNAMIC_FTRACE #ifdef CONFIG_DYNAMIC_FTRACE
trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
&ftrace_update_tot_cnt, &tracing_dyn_info_fops); NULL, &tracing_dyn_info_fops);
#endif #endif
create_trace_instances(d_tracer); create_trace_instances(d_tracer);
......
...@@ -804,6 +804,8 @@ extern void trace_event_follow_fork(struct trace_array *tr, bool enable); ...@@ -804,6 +804,8 @@ extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
#ifdef CONFIG_DYNAMIC_FTRACE #ifdef CONFIG_DYNAMIC_FTRACE
extern unsigned long ftrace_update_tot_cnt; extern unsigned long ftrace_update_tot_cnt;
extern unsigned long ftrace_number_of_pages;
extern unsigned long ftrace_number_of_groups;
void ftrace_init_trace_array(struct trace_array *tr); void ftrace_init_trace_array(struct trace_array *tr);
#else #else
static inline void ftrace_init_trace_array(struct trace_array *tr) { } static inline void ftrace_init_trace_array(struct trace_array *tr) { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment