Commit 3945b37a authored by Kevin Laatz's avatar Kevin Laatz Committed by Daniel Borkmann

samples/bpf: use hugepages in xdpsock app

This patch modifies xdpsock to use mmap instead of posix_memalign. With
this change, we can use hugepages when running the application in unaligned
chunks mode. Using hugepages makes it more likely that we have physically
contiguous memory, which supports the unaligned chunk mode better.
Signed-off-by: default avatarKevin Laatz <kevin.laatz@intel.com>
Acked-by: default avatarJonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 03895e63
...@@ -70,6 +70,7 @@ static int opt_interval = 1; ...@@ -70,6 +70,7 @@ static int opt_interval = 1;
static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
static u32 opt_umem_flags; static u32 opt_umem_flags;
static int opt_unaligned_chunks; static int opt_unaligned_chunks;
static int opt_mmap_flags;
static u32 opt_xdp_bind_flags; static u32 opt_xdp_bind_flags;
static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
static int opt_timeout = 1000; static int opt_timeout = 1000;
...@@ -440,6 +441,7 @@ static void parse_command_line(int argc, char **argv) ...@@ -440,6 +441,7 @@ static void parse_command_line(int argc, char **argv)
case 'u': case 'u':
opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG; opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG;
opt_unaligned_chunks = 1; opt_unaligned_chunks = 1;
opt_mmap_flags = MAP_HUGETLB;
break; break;
case 'F': case 'F':
opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST; opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
...@@ -742,11 +744,14 @@ int main(int argc, char **argv) ...@@ -742,11 +744,14 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret = posix_memalign(&bufs, getpagesize(), /* PAGE_SIZE aligned */ /* Reserve memory for the umem. Use hugepages if unaligned chunk mode */
NUM_FRAMES * opt_xsk_frame_size); bufs = mmap(NULL, NUM_FRAMES * opt_xsk_frame_size,
if (ret) PROT_READ | PROT_WRITE,
exit_with_error(ret); MAP_PRIVATE | MAP_ANONYMOUS | opt_mmap_flags, -1, 0);
if (bufs == MAP_FAILED) {
printf("ERROR: mmap failed\n");
exit(EXIT_FAILURE);
}
/* Create sockets... */ /* Create sockets... */
umem = xsk_configure_umem(bufs, NUM_FRAMES * opt_xsk_frame_size); umem = xsk_configure_umem(bufs, NUM_FRAMES * opt_xsk_frame_size);
xsks[num_socks++] = xsk_configure_socket(umem); xsks[num_socks++] = xsk_configure_socket(umem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment