cilium / ebpf

ebpf-go is a pure-Go library to read, modify and load eBPF programs and attach them to various hooks in the Linux kernel.

Home Page:https://ebpf-go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

map: move semantics for under sized per-CPU slices out of common per CPU marshaling code

lmb opened this issue · comments

We allow updating per-CPU maps with a slice that has less than PossibleCPUs items.

k := ...
v := make([]uint32, 2) // where possibleCPUs > 2

m.Update(k, v) // this will set values for CPU >= 2 to zero

The code to do this lives in the per-CPU marshalers, and makes them harder to understand. We currently invoke the same logic for batch per-CPU updates, which doesn't make a lot of sense because our API doesn't even allow passing such slices to the batch API.

As with bcca828 we should try to move this code into updatePerCPU and other callers. This removes a special case from the batch per-CPU code paths.

I think the only remnant of this is

ebpf/marshalers.go

Lines 76 to 77 in c5e9cb3

// Ensure buf is zero-padded full size.
buf = append(buf, make([]byte, (possibleCPUs-sliceLen)*alignedElemLength)...)
which doesn't seem so bad.