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.
https://ebpf-go.dev
MIT License
6.35k stars 699 forks source link

map: don't unmarshal unnecessary items on batch lookup #1080

Open ti-mo opened 1 year ago

ti-mo commented 1 year ago

It does seem like Map.batchLookup() always tries to unmarshal the whole keyBuf and valueBuf regardless of the Count received from the batch syscall.

https://github.com/cilium/ebpf/blob/c739d155eacc71da9d1390b39eb23d21e95a9038/map.go#L1076-L1083

It would be nice if we instead only decoded count keys and values.

See https://github.com/cilium/ebpf/issues/1078#issuecomment-1609818046.

Hudsoncoutinho commented 2 months ago

err := sysenc.Desempacotamento(keysOut, keyBuf, count) if err != nil { return 0, err } err = sysenc.Desempacotamento(valuesOut, valueBuf, count) if err != nil { return 0, err }

I thought about providing the actual count of items that need to be unpacked, storing it in the variable count, therefore, the Desempacotamento function needs to be able to accept an item count. If this is not supported, one option would be to adjust the function so that it receives this parameter