Skip to content

Commit da537f0

Browse files
committed
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: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 77ac117 commit da537f0

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,8 @@ static void ftrace_shutdown_sysctl(void)
29912991

29922992
static u64 ftrace_update_time;
29932993
unsigned long ftrace_update_tot_cnt;
2994+
unsigned long ftrace_number_of_pages;
2995+
unsigned long ftrace_number_of_groups;
29942996

29952997
static inline int ops_traces_mod(struct ftrace_ops *ops)
29962998
{
@@ -3115,6 +3117,9 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count)
31153117
goto again;
31163118
}
31173119

3120+
ftrace_number_of_pages += 1 << order;
3121+
ftrace_number_of_groups++;
3122+
31183123
cnt = (PAGE_SIZE << order) / ENTRY_SIZE;
31193124
pg->size = cnt;
31203125

@@ -3170,6 +3175,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
31703175
start_pg = pg->next;
31713176
kfree(pg);
31723177
pg = start_pg;
3178+
ftrace_number_of_pages -= 1 << order;
3179+
ftrace_number_of_groups--;
31733180
}
31743181
pr_info("ftrace: FAILED to allocate memory for functions\n");
31753182
return NULL;
@@ -6173,6 +6180,8 @@ void ftrace_release_mod(struct module *mod)
61736180
free_pages((unsigned long)pg->records, order);
61746181
tmp_page = pg->next;
61756182
kfree(pg);
6183+
ftrace_number_of_pages -= 1 << order;
6184+
ftrace_number_of_groups--;
61766185
}
61776186
}
61786187

@@ -6514,6 +6523,8 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
65146523
*last_pg = pg->next;
65156524
order = get_count_order(pg->size / ENTRIES_PER_PAGE);
65166525
free_pages((unsigned long)pg->records, order);
6526+
ftrace_number_of_pages -= 1 << order;
6527+
ftrace_number_of_groups--;
65176528
kfree(pg);
65186529
pg = container_of(last_pg, struct ftrace_page, next);
65196530
if (!(*last_pg))
@@ -6569,6 +6580,9 @@ void __init ftrace_init(void)
65696580
__start_mcount_loc,
65706581
__stop_mcount_loc);
65716582

6583+
pr_info("ftrace: allocated %ld pages with %ld groups\n",
6584+
ftrace_number_of_pages, ftrace_number_of_groups);
6585+
65726586
set_ftrace_early_filters();
65736587

65746588
return;

‎kernel/trace/trace.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7583,14 +7583,23 @@ static ssize_t
75837583
tracing_read_dyn_info(struct file *filp, char __user *ubuf,
75847584
size_t cnt, loff_t *ppos)
75857585
{
7586-
unsigned long *p = filp->private_data;
7587-
char buf[64]; /* Not too big for a shallow stack */
7586+
ssize_t ret;
7587+
char *buf;
75887588
int r;
75897589

7590-
r = scnprintf(buf, 63, "%ld", *p);
7591-
buf[r++] = '\n';
7590+
/* 256 should be plenty to hold the amount needed */
7591+
buf = kmalloc(256, GFP_KERNEL);
7592+
if (!buf)
7593+
return -ENOMEM;
75927594

7593-
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
7595+
r = scnprintf(buf, 256, "%ld pages:%ld groups: %ld\n",
7596+
ftrace_update_tot_cnt,
7597+
ftrace_number_of_pages,
7598+
ftrace_number_of_groups);
7599+
7600+
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
7601+
kfree(buf);
7602+
return ret;
75947603
}
75957604

75967605
static const struct file_operations tracing_dyn_info_fops = {
@@ -8782,7 +8791,7 @@ static __init int tracer_init_tracefs(void)
87828791

87838792
#ifdef CONFIG_DYNAMIC_FTRACE
87848793
trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
8785-
&ftrace_update_tot_cnt, &tracing_dyn_info_fops);
8794+
NULL, &tracing_dyn_info_fops);
87868795
#endif
87878796

87888797
create_trace_instances(d_tracer);

‎kernel/trace/trace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
804804

805805
#ifdef CONFIG_DYNAMIC_FTRACE
806806
extern unsigned long ftrace_update_tot_cnt;
807+
extern unsigned long ftrace_number_of_pages;
808+
extern unsigned long ftrace_number_of_groups;
807809
void ftrace_init_trace_array(struct trace_array *tr);
808810
#else
809811
static inline void ftrace_init_trace_array(struct trace_array *tr) { }

0 commit comments

Comments
 (0)