Commit f07d5ac
btf: Sort BTF types by name and kind to optimize btf_find_by_name_kind lookup
Currently, when the funcgraph-args feature is in use, the
btf_find_by_name_kind function is invoked quite frequently. However,
this function only supports linear search. When the number of btf_type
entries to search through is large, such as in the vmlinux BTF which
contains over 80,000 named btf_types, it consumes a significant amount
of time.
This patch optimizes the btf_find_by_name_kind lookup by sorting BTF
types according to their names and kinds. Additionally, it modifies
the search direction. Now, it first searches the BTF and then its base.
It should be noted that this change incurs some additional memory and
boot-time overhead. Therefore, the option is disabled by default.
Here is a test case:
# echo 1 > options/funcgraph-args
# echo function_graph > current_tracer
Before:
# time cat trace | wc -l
124176
real 0m16.154s
user 0m0.000s
sys 0m15.962s
After:
# time cat trace | wc -l
124176
real 0m0.948s
user 0m0.000s
sys 0m0.973s
An improvement of more than 20 times can be observed.
Cc: Eduard Zingerman <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andrii Nakryiko <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Masami Hiramatsu (Google) <[email protected]>
Cc: Steven Rostedt <[email protected]>
Signed-off-by: pengdonglin <[email protected]>
Signed-off-by: pengdonglin <[email protected]>1 parent 06bf66d commit f07d5ac
3 files changed
+165
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
104 | 117 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
253 | 258 | | |
254 | 259 | | |
255 | 260 | | |
| |||
268 | 273 | | |
269 | 274 | | |
270 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
271 | 279 | | |
272 | 280 | | |
273 | 281 | | |
| |||
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
473 | 484 | | |
474 | 485 | | |
475 | 486 | | |
| |||
544 | 555 | | |
545 | 556 | | |
546 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
547 | 563 | | |
548 | 564 | | |
549 | 565 | | |
| 566 | + | |
550 | 567 | | |
551 | 568 | | |
552 | 569 | | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
558 | 608 | | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
| 609 | + | |
| 610 | + | |
563 | 611 | | |
564 | 612 | | |
565 | 613 | | |
| |||
1737 | 1785 | | |
1738 | 1786 | | |
1739 | 1787 | | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
1740 | 1804 | | |
1741 | 1805 | | |
1742 | 1806 | | |
1743 | 1807 | | |
1744 | 1808 | | |
1745 | 1809 | | |
| 1810 | + | |
1746 | 1811 | | |
1747 | 1812 | | |
1748 | 1813 | | |
| |||
6189 | 6254 | | |
6190 | 6255 | | |
6191 | 6256 | | |
| 6257 | + | |
| 6258 | + | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
| 6272 | + | |
| 6273 | + | |
| 6274 | + | |
| 6275 | + | |
| 6276 | + | |
| 6277 | + | |
| 6278 | + | |
| 6279 | + | |
| 6280 | + | |
| 6281 | + | |
| 6282 | + | |
| 6283 | + | |
| 6284 | + | |
| 6285 | + | |
| 6286 | + | |
| 6287 | + | |
| 6288 | + | |
| 6289 | + | |
| 6290 | + | |
| 6291 | + | |
| 6292 | + | |
| 6293 | + | |
| 6294 | + | |
| 6295 | + | |
| 6296 | + | |
| 6297 | + | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
| 6302 | + | |
| 6303 | + | |
| 6304 | + | |
| 6305 | + | |
| 6306 | + | |
| 6307 | + | |
| 6308 | + | |
| 6309 | + | |
| 6310 | + | |
| 6311 | + | |
| 6312 | + | |
| 6313 | + | |
| 6314 | + | |
| 6315 | + | |
| 6316 | + | |
| 6317 | + | |
| 6318 | + | |
| 6319 | + | |
| 6320 | + | |
| 6321 | + | |
| 6322 | + | |
| 6323 | + | |
| 6324 | + | |
| 6325 | + | |
| 6326 | + | |
| 6327 | + | |
| 6328 | + | |
| 6329 | + | |
| 6330 | + | |
| 6331 | + | |
6192 | 6332 | | |
6193 | 6333 | | |
6194 | 6334 | | |
| |||
6230 | 6370 | | |
6231 | 6371 | | |
6232 | 6372 | | |
| 6373 | + | |
6233 | 6374 | | |
6234 | 6375 | | |
6235 | 6376 | | |
| |||
6362 | 6503 | | |
6363 | 6504 | | |
6364 | 6505 | | |
| 6506 | + | |
6365 | 6507 | | |
6366 | 6508 | | |
6367 | 6509 | | |
| |||
0 commit comments