lib/sort: Clean up sort_nonatomic() and sort_r_nonatomic()
Subsystems (5)
v2 cover lib/sort: Clean up sort_nonatomic() and sort_r_nonatomic()
kernel/trace/bpf_trace.c is the sole remaining user of sort_r_nonatomic(). Switch check_dup_ids() to sort_r() to match bpf_kprobe_multi_link_attach() in the same file, which has safely used sort_r() under the same limit (1U << 20) for 4 years.
With no users left in the tree, remove the unused sort_nonatomic() and sort_r_nonatomic() APIs. This drops the __sort_r() wrapper and eliminates the may_schedule branch and cond_resched() from the inner sorting loop.
---
Changes in v2:
- Drop the already accepted arm-smmu-v3 patch.
- Convert bpf_trace.c to sort_r() instead.
Kuan-Wei Chiu (2):
bpf: Replace sort_r_nonatomic() with sort_r() in check_dup_ids() Revert "lib/sort.c: add _nonatomic() variants with cond_resched()"
include/linux/sort.h | 11 ---- kernel/trace/bpf_trace.c | 2 +- lib/sort.c | 110 +++++++++++---------------------------- 3 files changed, 32 insertions(+), 91 deletions(-)
Signature · 1 line
2.55.0.1003.g10538fe699-goog
PATCH v2 1/2 bpf: Replace sort_r_nonatomic() with sort_r() in check_dup_ids()
bpf_kprobe_multi_link_attach() in the same file has been using sort_r() under the exact same limit (1U << 20) for 4 years without issues. Switch check_dup_ids() from sort_r_nonatomic() to sort_r() to match it.
This removes the last in-tree user of sort_r_nonatomic(), allowing the unused _nonatomic() sort variants to be dropped from the core library.
---
Build test only
kernel/trace/bpf_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/bpf_trace.c +1 -1
@@ -3826,7 +3826,7 @@ static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)* and check it for duplicates. The ids and cookies arrays * are left sorted. */ -sort_r_nonatomic (ids, cnt,sizeof (ids[0 ]), ids_cmp_r, ids_swap_r, data); +sort_r (ids, cnt,sizeof (ids[0 ]), ids_cmp_r, ids_swap_r, data);for (int i =1 ; i < cnt; i++) {if (ids[i] == ids[i -1 ]) {
Signature · 1 line
2.55.0.1003.g10538fe699-goog
Re: [PATCH v2 1/2] bpf: Replace sort_r_nonatomic() with sort_r() in check_dup_ids()
Quoted 2 lines · Kuan-Wei Chiu
bpf_kprobe_multi_link_attach()in the same file has been usingsort_r()under the exact same limit (1U << 20) for 4 years without issues.
true
Quoted 1 line
Switch
check_dup_ids()fromsort_r_nonatomic()tosort_r()to match it.
I looked it up and I used that based on sashiko comment, it seems like switching to sort_r sould be fine
Quoted 7 lines
This removes the last in-tree user of
sort_r_nonatomic(), allowing the unused_nonatomic()sort variants to be dropped from the core library.Signed-off-by Kuan-Wei Chiu <[email protected]>---
Build test only
I ran bpf ci on this, it passed
jirka
Quoted 20 lines
kernel/trace/bpf_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/bpf_trace.c +1
-1@@ -3826,7 +3826,7 @@ static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)* and check it for duplicates. The ids and cookies arrays * are left sorted. */ -sort_r_nonatomic (ids, cnt,sizeof (ids[0 ]), ids_cmp_r, ids_swap_r, data); +sort_r (ids, cnt,sizeof (ids[0 ]), ids_cmp_r, ids_swap_r, data);for (int i =1 ; i < cnt; i++) {if (ids[i] == ids[i -1 ]) {Signature · 1 line
2.55.0.1003.g10538fe699-goog
PATCH v2 2/2 Revert "lib/sort.c: add _nonatomic() variants with cond_resched()"
In reply to Kuan-Wei ChiuThis reverts commit e2a33a2a3258794891cdd6ca4b1318da6594d157.
With no remaining users in the kernel tree, remove sort_nonatomic() and sort_r_nonatomic() to clean up dead code. This effectively drops the wrapper function __sort_r() and eliminates the may_schedule branch and cond_resched() call from the inner loop of the core sorting routine, slightly simplifying and optimizing the code.
---
Build test only
include/linux/sort.h | 11 ----- lib/sort.c | 110 ++++++++++++------------------------------- 2 files changed, 31 insertions(+), 90 deletions(-)
include/linux/sort.h +0 -11
@@ -23,15 +23,4 @@ void sort(void *base, size_t num, size_t size,cmp_func_t cmp_func, swap_func_t swap_func); -/* Versions that periodically call cond_resched(): */ - -void sort_r_nonatomic (void *base,size_t num,size_t size, -cmp_r_func_t cmp_func, -swap_r_func_t swap_func, -const void *priv); - -void sort_nonatomic (void *base,size_t num,size_t size, -cmp_func_t cmp_func, -swap_func_t swap_func); -#endif
lib/sort.c +31 -79
135 lines not on this page · raw message
Signature · 1 line
2.55.0.1003.g10538fe699-goog
Quoted 9 lines · Kuan-Wei Chiu
kernel/trace/bpf_trace.cis the sole remaining user ofsort_r_nonatomic(). Switchcheck_dup_ids()tosort_r()to matchbpf_kprobe_multi_link_attach()in the same file, which has safely usedsort_r()under the same limit (1U << 20) for 4 years.With no users left in the tree, remove the unused
sort_nonatomic()andsort_r_nonatomic()APIs. This drops the__sort_r()wrapper and eliminates themay_schedulebranch andcond_resched()from the inner sorting loop.
Anything else I need to do for this patchset to land?
Regards,
Kuan-Wei
Quoted 17 lines
---
Changes in v2:
- Drop the already accepted arm-smmu-v3 patch.
- Convertbpf_trace.ctosort_r()instead.Kuan-Wei Chiu (2):
bpf: Replacesort_r_nonatomic()withsort_r()incheck_dup_ids()Revert "lib/sort.c: add_nonatomic()variants withcond_resched()"include/linux/sort.h | 11 ---- kernel/trace/bpf_trace.c | 2 +- lib/sort.c | 110 +++++++++++---------------------------- 3 files changed, 32 insertions(+), 91 deletions(-)Signature · 1 line
2.55.0.1003.g10538fe699-goog