summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2023-06-20 19:40:22 +0000
committerCherrypicker Worker <android-build-cherrypicker-worker@google.com>2023-10-09 11:08:38 +0000
commit53d77df5114329ca04155c4be7c284acede78b6c (patch)
tree5ee46399332940970bb6cb3ef48096b8e41dfa25
parentdbe70cc96aa42c4c762df60c9604a8b0286ec358 (diff)
downloadbpf-53d77df5114329ca04155c4be7c284acede78b6c.tar.gz
add a comment about page size vs bpf ring buffer sizing
As requested by Patrick on: https://android-review.git.corp.google.com/c/platform/system/bpf/+/2628969 bpfLoader: automatically bump ringbuffer size up to page size Test: N/A, comment only Signed-off-by: Maciej Żenczykowski <maze@google.com> (cherry picked from https://android-review.googlesource.com/q/commit:28f01bb027e5daf9793ed9a436bf735942cd423e) Merged-In: Ibbce6a72e5e25bf18bb89bca2f00d332ef824f73 Change-Id: Ibbce6a72e5e25bf18bb89bca2f00d332ef824f73
-rw-r--r--libbpf_android/Loader.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index 231fe39..83f6a88 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -707,6 +707,9 @@ static bool mapMatchesExpectations(const unique_fd& fd, const string& mapName,
if (type == BPF_MAP_TYPE_DEVMAP || type == BPF_MAP_TYPE_DEVMAP_HASH)
desired_map_flags |= BPF_F_RDONLY_PROG;
+ // The .h file enforces that this is a power of two, and page size will
+ // also always be a power of two, so this logic is actually enough to
+ // force it to be a multiple of the page size, as required by the kernel.
unsigned int desired_max_entries = mapDef.max_entries;
if (type == BPF_MAP_TYPE_RINGBUF) {
if (desired_max_entries < page_size) desired_max_entries = page_size;
@@ -849,6 +852,9 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>&
type = BPF_MAP_TYPE_HASH;
}
+ // The .h file enforces that this is a power of two, and page size will
+ // also always be a power of two, so this logic is actually enough to
+ // force it to be a multiple of the page size, as required by the kernel.
unsigned int max_entries = md[i].max_entries;
if (type == BPF_MAP_TYPE_RINGBUF) {
if (max_entries < page_size) max_entries = page_size;