On Thu, Dec 05, 2024 at 04:24:17PM -0800, Andrii Nakryiko wrote: > Instead of constantly allocating and freeing very short-lived > struct return_instance, reuse it as much as possible within current > task. For that, store a linked list of reusable return_instances within > current->utask. > > The only complication is that ri_timer() might be still processing such > return_instance. And so while the main uretprobe processing logic might > be already done with return_instance and would be OK to immediately > reuse it for the next uretprobe instance, it's not correct to > unconditionally reuse it just like that. > > Instead we make sure that ri_timer() can't possibly be processing it by > using seqcount_t, with ri_timer() being "a writer", while > free_ret_instance() being "a reader". If, after we unlink return > instance from utask->return_instances list, we know that ri_timer() > hasn't gotten to processing utask->return_instances yet, then we can be > sure that immediate return_instance reuse is OK, and so we put it > onto utask->ri_pool for future (potentially, almost immediate) reuse. > > This change shows improvements both in single CPU performance (by > avoiding relatively expensive kmalloc/free combon) and in terms of > multi-CPU scalability, where you can see that per-CPU throughput doesn't > decline as steeply with increased number of CPUs (which were previously > attributed to kmalloc()/free() through profiling): > > BASELINE (latest perf/core) > =========================== > uretprobe-nop ( 1 cpus): 1.898 ± 0.002M/s ( 1.898M/s/cpu) > uretprobe-nop ( 2 cpus): 3.574 ± 0.011M/s ( 1.787M/s/cpu) > uretprobe-nop ( 3 cpus): 5.279 ± 0.066M/s ( 1.760M/s/cpu) > uretprobe-nop ( 4 cpus): 6.824 ± 0.047M/s ( 1.706M/s/cpu) > uretprobe-nop ( 5 cpus): 8.339 ± 0.060M/s ( 1.668M/s/cpu) > uretprobe-nop ( 6 cpus): 9.812 ± 0.047M/s ( 1.635M/s/cpu) > uretprobe-nop ( 7 cpus): 11.030 ± 0.048M/s ( 1.576M/s/cpu) > uretprobe-nop ( 8 cpus): 12.453 ± 0.126M/s ( 1.557M/s/cpu) > uretprobe-nop (10 cpus): 14.838 ± 0.044M/s ( 1.484M/s/cpu) > uretprobe-nop (12 cpus): 17.092 ± 0.115M/s ( 1.424M/s/cpu) > uretprobe-nop (14 cpus): 19.576 ± 0.022M/s ( 1.398M/s/cpu) > uretprobe-nop (16 cpus): 22.264 ± 0.015M/s ( 1.391M/s/cpu) > uretprobe-nop (24 cpus): 33.534 ± 0.078M/s ( 1.397M/s/cpu) > uretprobe-nop (32 cpus): 43.262 ± 0.127M/s ( 1.352M/s/cpu) > uretprobe-nop (40 cpus): 53.252 ± 0.080M/s ( 1.331M/s/cpu) > uretprobe-nop (48 cpus): 55.778 ± 0.045M/s ( 1.162M/s/cpu) > uretprobe-nop (56 cpus): 56.850 ± 0.227M/s ( 1.015M/s/cpu) > uretprobe-nop (64 cpus): 62.005 ± 0.077M/s ( 0.969M/s/cpu) > uretprobe-nop (72 cpus): 66.445 ± 0.236M/s ( 0.923M/s/cpu) > uretprobe-nop (80 cpus): 68.353 ± 0.180M/s ( 0.854M/s/cpu) > > THIS PATCHSET (on top of latest perf/core) > ========================================== > uretprobe-nop ( 1 cpus): 2.253 ± 0.004M/s ( 2.253M/s/cpu) > uretprobe-nop ( 2 cpus): 4.281 ± 0.003M/s ( 2.140M/s/cpu) > uretprobe-nop ( 3 cpus): 6.389 ± 0.027M/s ( 2.130M/s/cpu) > uretprobe-nop ( 4 cpus): 8.328 ± 0.005M/s ( 2.082M/s/cpu) > uretprobe-nop ( 5 cpus): 10.353 ± 0.001M/s ( 2.071M/s/cpu) > uretprobe-nop ( 6 cpus): 12.513 ± 0.010M/s ( 2.086M/s/cpu) > uretprobe-nop ( 7 cpus): 14.525 ± 0.017M/s ( 2.075M/s/cpu) > uretprobe-nop ( 8 cpus): 15.633 ± 0.013M/s ( 1.954M/s/cpu) > uretprobe-nop (10 cpus): 19.532 ± 0.011M/s ( 1.953M/s/cpu) > uretprobe-nop (12 cpus): 21.405 ± 0.009M/s ( 1.784M/s/cpu) > uretprobe-nop (14 cpus): 24.857 ± 0.020M/s ( 1.776M/s/cpu) > uretprobe-nop (16 cpus): 26.466 ± 0.018M/s ( 1.654M/s/cpu) > uretprobe-nop (24 cpus): 40.513 ± 0.222M/s ( 1.688M/s/cpu) > uretprobe-nop (32 cpus): 54.180 ± 0.074M/s ( 1.693M/s/cpu) > uretprobe-nop (40 cpus): 66.100 ± 0.082M/s ( 1.652M/s/cpu) > uretprobe-nop (48 cpus): 70.544 ± 0.068M/s ( 1.470M/s/cpu) > uretprobe-nop (56 cpus): 74.494 ± 0.055M/s ( 1.330M/s/cpu) > uretprobe-nop (64 cpus): 79.317 ± 0.029M/s ( 1.239M/s/cpu) > uretprobe-nop (72 cpus): 84.875 ± 0.020M/s ( 1.179M/s/cpu) > uretprobe-nop (80 cpus): 92.318 ± 0.224M/s ( 1.154M/s/cpu) nice! left few comments but overall lgtm thanks, jirka