Based on the following two reasones, we could simplify the calculation: - If the number after roundup count is not power of 2, we would definitely have more than 1 empty page with a higher order. - get_count_order() just return current order, so one lower order could meet the requirement. The calculation could be simplified by lower one order level when pages are not power of 2. Link: https://lkml.kernel.org/r/20200831031104.23322-5-richard.weiyang@linux.alibaba.com
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -3129,18 +3129,19 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs) · 3128 unmodified lines | ||
| 3129 | 3129 | static int ftrace_allocate_records(struct ftrace_page *pg, int count) |
| 3130 | 3130 | { |
| 3131 | 3131 | int order; |
| 3132 | − int cnt; | |
| 3132 | + int pages, cnt; | |
| 3133 | 3133 | |
| 3134 | 3134 | if (WARN_ON(!count)) |
| 3135 | 3135 | return -EINVAL; |
| 3136 | 3136 | |
| 3137 | − order = get_count_order(DIV_ROUND_UP(count, ENTRIES_PER_PAGE)); | |
| 3137 | + pages = DIV_ROUND_UP(count, ENTRIES_PER_PAGE); | |
| 3138 | + order = get_count_order(pages); | |
| 3138 | 3139 | |
| 3139 | 3140 | /* |
| 3140 | 3141 | * We want to fill as much as possible. No more than a page |
| 3141 | 3142 | * may be empty. |
| 3142 | 3143 | */ |
| 3143 | − while ((PAGE_SIZE << order) / ENTRY_SIZE >= count + ENTRIES_PER_PAGE) | |
| 3144 | + if (!is_power_of_2(pages)) | |
| 3144 | 3145 | order--; |
| 3145 | 3146 | |
| 3146 | 3147 | again: |