Skip to content

Conversation

NoNickeD
Copy link
Contributor

Summary

This PR adds support for the MapExtra field and bloom filter maps, addressing issue #669.

Changes Made

  • Add MapExtra field to MapSpec struct for map-specific configuration
  • Update map creation to pass MapExtra to kernel via sys.MapCreateAttr
  • Handle map_extra field in BTF map definitions (elf_reader.go)
  • Add NewBloomFilter helper function for creating bloom filter maps
  • Add tests for bloom filter functionality

Notes

  • Bloom filters available from Linux 5.16+
  • Uses lower 4 bits of MapExtra to specify 1-15 hash functions (default: 5)
  • Backward compatible - existing code unaffected

@NoNickeD NoNickeD requested a review from a team as a code owner August 20, 2025 06:00
@NoNickeD NoNickeD force-pushed the add-bloom-filter-support branch from 937ed79 to f079fc5 Compare August 20, 2025 06:03
Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! However, I have some changes to request.

I think the change to parse the MapExtra from ELF makes sense. The addition of the constructor does not.

All of the test logic added tests this constructor. I suggest you remove it, and instead extend TestLoadCollectionSpec to test parsing of map extra from ELF. You would do so my adding a new map definition to testdata/loader.c and then adding a new expected MapSpec.

NoNickeD added a commit to NoNickeD/ebpf that referenced this pull request Sep 2, 2025
Per review feedback, removing the NewBloomFilter constructor as it adds
unnecessary API surface area. MapSpec fields are public and can be used
directly to create bloom filter maps.

The MapExtra field parsing from ELF is already implemented and working
in the ELF loader, so bloom filters can be loaded from BPF programs.

Fixes cilium#1856
NoNickeD added a commit to NoNickeD/ebpf that referenced this pull request Sep 2, 2025
Per review feedback, removing the NewBloomFilter constructor as it adds
unnecessary API surface area. MapSpec fields are public and can be used
directly to create bloom filter maps.

The MapExtra field parsing from ELF is already implemented and working
in the ELF loader, so bloom filters can be loaded from BPF programs.

Fixes cilium#1856

Signed-off-by: nikos.nikolakakis <[email protected]>
@NoNickeD NoNickeD force-pushed the add-bloom-filter-support branch from a847beb to aff2768 Compare September 2, 2025 09:43
@NoNickeD
Copy link
Contributor Author

NoNickeD commented Sep 2, 2025

Hello @dylandreimerink,

Thanks for the feedback! I have removed the NewBloomFilter constructor and all associated tests as requested. The MapExtra parsing from ELF was already implemented in the existing code, so bloom filters can still be created by setting the MapSpec fields directly.

The changes have been pushed and the PR is ready for another review.

@dylandreimerink
Copy link
Member

The MapExtra parsing from ELF was already implemented in the existing code

Yea, passing from MapSpec was already there, but this addition is needed to make ELF -> MapSpec work properly.

Thank you for the changes. Please don't forget about extending the tests to cover this new behavior https://github.com/cilium/ebpf/blob/main/elf_reader_test.go#L48 + https://github.com/cilium/ebpf/blob/main/testdata/loader.c

That way we can assert this stays working if we ever have to make modifications in the future.

@NoNickeD NoNickeD force-pushed the add-bloom-filter-support branch from 7a34fb0 to e3207a9 Compare September 2, 2025 13:46
@ti-mo ti-mo force-pushed the add-bloom-filter-support branch from 3a8f119 to 1c30f3e Compare September 9, 2025 12:35
@ti-mo ti-mo changed the title Add MapExtra support and bloom filter maps map: add MapSpec.MapExtra field Sep 9, 2025
NoNickeD and others added 2 commits September 9, 2025 14:49
Bloom filter maps were introduced in Linux 5.16 and use the map_extra field to
specify the number of hash functions (lower 4 bits, 1-15 range). Parse this
field from the ELF and pass it through to the kernel.

Fixes cilium#669

Signed-off-by: nikos.nikolakakis <[email protected]>
Co-authored-by: Timo Beckers <[email protected]>
This commit teaches ebpf-go to understand the __ulong BTF map definition macro
and uses it to specify a 64-bit value for map_extra in an arena map, defining
the start of the mmap region for the Collection's arena.

Signed-off-by: Timo Beckers <[email protected]>
@ti-mo ti-mo force-pushed the add-bloom-filter-support branch from 1c30f3e to 6c09c28 Compare September 9, 2025 12:49
@ti-mo ti-mo merged commit dc25617 into cilium:main Sep 9, 2025
5 checks passed
@ti-mo
Copy link
Collaborator

ti-mo commented Sep 9, 2025

@NoNickeD Thanks for picking this up! I ended up moving things around a bit and added separate testdata for arena maps since loader.c needs to work on all kernels in the matrix. I'm planning on doing more arena-related work, so it made sense long-term.

Arenas also need the __ulong macro for map_extra since the kernel's field is a 64-bit value, added support for that as well. Bloom filters should work just fine, though. Didn't end up needing extra testing there.

@ti-mo ti-mo linked an issue Sep 9, 2025 that may be closed by this pull request
@NoNickeD
Copy link
Contributor Author

NoNickeD commented Sep 9, 2025

@ti-mo Thanks for merging and improving this! The separate arena testdata and __ulong macro support for 64-bit map_extra make sense. Learned a lot from your restructuring.

Thanks for the guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for MapExtra and bloom filter maps
3 participants