History

ftrace: Store the order of pages allocated in ftrace_page

Instead of saving the size of the records field of the ftrace_page, store the order it uses to allocate the pages, as that is what is needed to know in order to free the pages. This simplifies the code. Link: https://lore.kernel.org/lkml/CAHk-=whyMxheOqXAORt9a7JK9gc9eHTgCJ55Pgs4p=X3RrQubQ@mail.gmail.com/

Linus Torvalds committed 5 years ago

Commit db425231 parent f3ef7201 file · +17 −18Browse files

Unified · Split

kernel/trace/ftrace.c+17−18
@@ -1090,7 +1090,7 @@ struct ftrace_page { · 1089 unmodified lines
10901090 struct ftrace_page *next;
10911091 struct dyn_ftrace *records;
10921092 int index;
1093− int size;
1093+ int order;
10941094 };
10951095
10961096 #define ENTRY_SIZE sizeof(struct dyn_ftrace)
@@ -3181,7 +3181,7 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count) · 2084 unmodified lines
31813181 ftrace_number_of_groups++;
31823182
31833183 cnt = (PAGE_SIZE << order) / ENTRY_SIZE;
3184− pg->size = cnt;
3184+ pg->order = order;
31853185
31863186 if (cnt > count)
31873187 cnt = count;
@@ -3194,7 +3194,6 @@ ftrace_allocate_pages(unsigned long num_to_init) · 6 unmodified lines
31943194 {
31953195 struct ftrace_page *start_pg;
31963196 struct ftrace_page *pg;
3197− int order;
31983197 int cnt;
31993198
32003199 if (!num_to_init)
@@ -3230,13 +3229,13 @@ ftrace_allocate_pages(unsigned long num_to_init) · 29 unmodified lines
32303229 free_pages:
32313230 pg = start_pg;
32323231 while (pg) {
3233− order = get_count_order(pg->size / ENTRIES_PER_PAGE);
3234− if (order >= 0)
3235− free_pages((unsigned long)pg->records, order);
3232+ if (pg->records) {
3233+ free_pages((unsigned long)pg->records, pg->order);
3234+ ftrace_number_of_pages -= 1 << pg->order;
3235+ }
32363236 start_pg = pg->next;
32373237 kfree(pg);
32383238 pg = start_pg;
3239− ftrace_number_of_pages -= 1 << order;
32403239 ftrace_number_of_groups--;
32413240 }
32423241 pr_info("ftrace: FAILED to allocate memory for functions\n");
@@ -6188,6 +6187,7 @@ static int ftrace_process_locs(struct module *mod, · 2945 unmodified lines
61886187 p = start;
61896188 pg = start_pg;
61906189 while (p < end) {
6190+ unsigned long end_offset;
61916191 addr = ftrace_call_adjust(*p++);
61926192 /*
61936193 * Some architecture linkers will pad between
@@ -6198,7 +6198,8 @@ static int ftrace_process_locs(struct module *mod, · 4 unmodified lines
61986198 if (!addr)
61996199 continue;
62006200
6201− if (pg->index == pg->size) {
6201+ end_offset = (pg->index+1) * sizeof(pg->records[0]);
6202+ if (end_offset > PAGE_SIZE << pg->order) {
62026203 /* We should have allocated enough */
62036204 if (WARN_ON(!pg->next))
62046205 break;
@@ -6367,7 +6368,6 @@ void ftrace_release_mod(struct module *mod) · 162 unmodified lines
63676368 struct ftrace_page **last_pg;
63686369 struct ftrace_page *tmp_page = NULL;
63696370 struct ftrace_page *pg;
6370− int order;
63716371
63726372 mutex_lock(&ftrace_lock);
63736373
@@ -6418,12 +6418,12 @@ void ftrace_release_mod(struct module *mod) · 44 unmodified lines
64186418 /* Needs to be called outside of ftrace_lock */
64196419 clear_mod_from_hashes(pg);
64206420
6421− order = get_count_order(pg->size / ENTRIES_PER_PAGE);
6422− if (order >= 0)
6423− free_pages((unsigned long)pg->records, order);
6421+ if (pg->records) {
6422+ free_pages((unsigned long)pg->records, pg->order);
6423+ ftrace_number_of_pages -= 1 << pg->order;
6424+ }
64246425 tmp_page = pg->next;
64256426 kfree(pg);
6426− ftrace_number_of_pages -= 1 << order;
64276427 ftrace_number_of_groups--;
64286428 }
64296429 }
@@ -6741,7 +6741,6 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr) · 311 unmodified lines
67416741 struct ftrace_mod_map *mod_map = NULL;
67426742 struct ftrace_init_func *func, *func_next;
67436743 struct list_head clear_hash;
6744− int order;
67456744
67466745 INIT_LIST_HEAD(&clear_hash);
67476746
@@ -6779,10 +6778,10 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr) · 31 unmodified lines
67796778 ftrace_update_tot_cnt--;
67806779 if (!pg->index) {
67816780 *last_pg = pg->next;
6782− order = get_count_order(pg->size / ENTRIES_PER_PAGE);
6783− if (order >= 0)
6784− free_pages((unsigned long)pg->records, order);
6785− ftrace_number_of_pages -= 1 << order;
6781+ if (pg->records) {
6782+ free_pages((unsigned long)pg->records, pg->order);
6783+ ftrace_number_of_pages -= 1 << pg->order;
6784+ }
67866785 ftrace_number_of_groups--;
67876786 kfree(pg);
67886787 pg = container_of(last_pg, struct ftrace_page, next);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t