Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/bpftune/libbpftune.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif

#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c)))
#endif

#define BPFTUNE_SERVER_MSG_MAX 65536

char *bpftune_state_string[] = {
Expand Down
30 changes: 27 additions & 3 deletions src/net_buffer_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static struct bpftunable_desc descs[] = {
0, 1 },
{ NETDEV_BUDGET_USECS, BPFTUNABLE_SYSCTL, "net.core.netdev_budget_usecs",
0, 1 },
{ HIGH_ORDER_ALLOC_DISABLE, BPFTUNABLE_SYSCTL, "net.core.high_order_alloc_disable",
0, 1 },
};

static struct bpftunable_scenario scenarios[] = {
Expand All @@ -33,7 +35,9 @@ static struct bpftunable_scenario scenarios[] = {
{ NETDEV_BUDGET_INCREASE, "need to increase # of packets processed per NAPI poll",
"Need to increase number of packets processed across network devices during NAPI poll to use all of net.core.netdev_budget_usecs" },
{ NETDEV_BUDGET_DECREASE, "need to decrease # of packets processed per NAPI poll",
"Need to decrease netdev_budget[_usecs] since the ratio of time spent waiting to run versus time spent running for tasks has increased as we have increased netdev budget. This indicates either our budget increases directly let to increased wait times for other tasks, or that general load has increased; either way spending too much time in NAPI processing will hurt system performance." }
"Need to decrease netdev_budget[_usecs] since the ratio of time spent waiting to run versus time spent running for tasks has increased as we have increased netdev budget. This indicates either our budget increases directly let to increased wait times for other tasks, or that general load has increased; either way spending too much time in NAPI processing will hurt system performance." },
{ HIGH_ORDER_ALLOC_ENABLE, "need to enable high-order allocation for skb page frags",
"On pre-5.14 kernels setting net.core.high_order_alloc_disable=1 reduced contention, but disabling high-order allocations lowers performance with little benefit now that frags are allocated on a pre-cpu basis and contention is minimized." }
};

int init(struct bpftuner *tuner)
Expand All @@ -42,12 +46,16 @@ int init(struct bpftuner *tuner)
long max_backlog = 0;
long budget = 0;
long budget_usecs = 0;
long high_order_alloc_disable = 0;
unsigned int kernel_version = 0;
int err;

bpftune_sysctl_read(0, "net.core.flow_limit_cpu_bitmap", &cpu_bitmap);
bpftune_sysctl_read(0, "net.core.netdev_max_backlog", &max_backlog);
bpftune_sysctl_read(0, "net.core.netdev_budget", &budget);
bpftune_sysctl_read(0, "net.core.netdev_budget_usecs", &budget_usecs);
bpftune_sysctl_read(0, "net.core.high_order_alloc_disable", &high_order_alloc_disable);

err = bpftuner_bpf_open(net_buffer, tuner);
if (err)
return err;
Expand All @@ -62,14 +70,30 @@ int init(struct bpftuner *tuner)
budget);
bpftuner_bpf_var_set(net_buffer, tuner, netdev_budget_usecs,
budget_usecs);

bpftuner_bpf_sample_add(net_buffer, tuner, drop_sample);
bpftuner_bpf_sample_add(net_buffer, tuner, napi_complete_sample);
err = bpftuner_bpf_attach(net_buffer, tuner);
if (err)
return err;

return bpftuner_tunables_init(tuner, NET_BUFFER_NUM_TUNABLES, descs,
ARRAY_SIZE(scenarios), scenarios);
err = bpftuner_tunables_init(tuner, NET_BUFFER_NUM_TUNABLES, descs,
ARRAY_SIZE(scenarios), scenarios);
if (!err && high_order_alloc_disable) {
kernel_version = bpf_object__kversion(tuner->obj);
bpftune_log(LOG_DEBUG, "high_order %ld got kver %d\n", high_order_alloc_disable, kernel_version);
if (kernel_version >= KERNEL_VERSION(5, 14, 0)) {
high_order_alloc_disable = 0;
bpftuner_tunable_sysctl_write(tuner,
HIGH_ORDER_ALLOC_DISABLE,
HIGH_ORDER_ALLOC_ENABLE,
0,
1,
&high_order_alloc_disable,
"To maximize performance, set net.core.high_order_alloc_disable=0 on more recent kernel since it is not needed as contention in high-order allocs is not present\n");
}
}
return err;
}

void fini(struct bpftuner *tuner)
Expand Down
2 changes: 2 additions & 0 deletions src/net_buffer_tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum net_buffer_tunables {
FLOW_LIMIT_CPU_BITMAP,
NETDEV_BUDGET,
NETDEV_BUDGET_USECS,
HIGH_ORDER_ALLOC_DISABLE,
NET_BUFFER_NUM_TUNABLES,
};

Expand All @@ -32,6 +33,7 @@ enum net_buffer_scenarios {
FLOW_LIMIT_CPU_SET,
NETDEV_BUDGET_INCREASE,
NETDEV_BUDGET_DECREASE,
HIGH_ORDER_ALLOC_ENABLE,
};

/* above 50msec is too high */
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ NEIGH_TABLE_TESTS = neigh_table_test neigh_table_v4only_test \
neigh_table_max_test neigh_table_max2_test \
neigh_table_legacy_test

NET_BUFFER_TESTS = budget_test backlog_test backlog_legacy_test
NET_BUFFER_TESTS = budget_test backlog_test backlog_legacy_test \
high_order_alloc_test

TCP_BUFFER_TESTS = mem_pressure_test mem_pressure_legacy_test \
mem_exhaust_test mem_exhaust_legacy_test \
Expand Down
66 changes: 66 additions & 0 deletions test/high_order_alloc_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/bash
#
# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
#
# Copyright (c) 2025, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License v2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 021110-1307, USA.
#

# run high order alloc test

. ./test_lib.sh


SLEEPTIME=10

for TUNER in net_buffer ; do

test_start "$0|high order alloc test: is high order alloc disabled for kernels > 5.14?"

test_setup "true"

orig_high_order=$(sysctl -n net.core.high_order_alloc_disable)
sysctl -w net.core.high_order_alloc_disable=1

test_run_cmd_local "$BPFTUNE -ds &" true

sleep $SETUPTIME

expected=1

case $MAJ_KVER in
2|3|4)
;;
5)
if [[ $MIN_KVER -gt 14 ]]; then
expected_high_order=0
fi
;;
*)
expected=0
;;
esac

val="$(sysctl -qn net.core.high_order_alloc_disable)"
pkill -TERM bpftune
sysctl -w net.core.high_order_alloc_disable=$orig_high_order
if [[ "$val" == "$expected" ]]; then
test_pass
fi
test_cleanup
done

test_exit