Better linked-list traversal in BPF
Better linked-list traversal in BPF
Posted Mar 8, 2024 18:14 UTC (Fri) by mb (subscriber, #50428)In reply to: Better linked-list traversal in BPF by epa
Parent article: Better linked-list traversal in BPF
if (curr->next == curr + 1) ++curr;
else curr = curr->next;
But I don't get why that would help.
You can just say curr = curr->next, because you need to load the next pointer anyway.
I wouldn't be surprised if the compiler would optimize it into that.
Posted Mar 9, 2024 6:36 UTC (Sat)
by epa (subscriber, #39769)
[Link] (1 responses)
If the flag to say “just increment” were included in a part of the data structure you have to load anyway, then it might save some memory access too.
Posted Mar 9, 2024 18:08 UTC (Sat)
by Baughn (subscriber, #124425)
[Link]
This isn’t a new approach, by the way. LISP famously uses lists a lot, and LISP machines needed to process them quickly. Even with memory latency at the time being much lower relative to CPU speeds, laying them out contiguously in memory was a standard trick. One way to do that is to use a copying garbage collector, which if coded correctly will automatically defragment the lists when they’re copied.
Better linked-list traversal in BPF
Better linked-list traversal in BPF