Commit 69bc599
kallsyms: cache bpf symbols to avoid quadratic iteration
The existing code iterates the whole list of bpf ksyms until the right
one is found, which means quadratic complexity on top of linked list
pointer chasing under rcu. This is't noticeable for most installations,
but when one has 10000 bpf programs loaded, things start to add up and
reading from `/proc/kallsyms` slows down a lot.
Instead of doing that, we can cache the list of bpf symbols in linear
time when `/proc/kallsyms` is opened, which makes the whole thing fast.
Reading `/proc/kallsyms` on Apple M3 Pro in a VM and measuring system time:
Before:
* 15 bpf symbols: ~35ms
* 10015 bpf symbols: ~1250ms
After:
* 15 bpf symbols: ~35ms
* 10015 bpf symbols: ~50ms
Testing in production on v6.12 series (with ~10000 bpf ksyms as well):
* On AMD EPYC 9684X (Zen4): ~870ms -> ~100ms
* On Ampere Altra Max M128-30: ~4650ms -> ~70ms
Signed-off-by: Ivan Babrou <[email protected]>1 parent af9bd6d commit 69bc599
3 files changed
+94
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
651 | 656 | | |
652 | 657 | | |
653 | 658 | | |
| |||
1381 | 1386 | | |
1382 | 1387 | | |
1383 | 1388 | | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
1384 | 1392 | | |
1385 | 1393 | | |
1386 | 1394 | | |
| |||
1449 | 1457 | | |
1450 | 1458 | | |
1451 | 1459 | | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
1452 | 1468 | | |
1453 | 1469 | | |
1454 | 1470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
825 | 825 | | |
826 | 826 | | |
827 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
828 | 874 | | |
829 | 875 | | |
830 | 876 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| 569 | + | |
| 570 | + | |
569 | 571 | | |
570 | 572 | | |
571 | 573 | | |
| |||
603 | 605 | | |
604 | 606 | | |
605 | 607 | | |
| 608 | + | |
606 | 609 | | |
607 | 610 | | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
608 | 626 | | |
609 | 627 | | |
610 | | - | |
| 628 | + | |
611 | 629 | | |
612 | 630 | | |
613 | 631 | | |
| |||
862 | 880 | | |
863 | 881 | | |
864 | 882 | | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
865 | 886 | | |
866 | 887 | | |
867 | 888 | | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
868 | 898 | | |
869 | 899 | | |
870 | 900 | | |
| |||
889 | 919 | | |
890 | 920 | | |
891 | 921 | | |
892 | | - | |
| 922 | + | |
893 | 923 | | |
894 | 924 | | |
895 | 925 | | |
| |||
0 commit comments