-
-
Save ilyaevseev/233aca6f689f3ee2c1defd1b3b6373f8 to your computer and use it in GitHub Desktop.
mq+fq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ue | |
# | |
# Sets up mq+$shed combo for given interface. | |
# | |
# NB! To not degrade upload speeds, fq should only be used on kernels >= 3.19: | |
# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9878196578286c5ed494778ada01da094377a686 | |
# | |
if [ $# -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then | |
echo "usage: $0 interface scheduler" >&2 | |
echo " e.g: $0 eth0 fq" >&2 | |
echo " e.g: $0 eth0 pfifo_fast" >&2 | |
exit 64 # EX_USAGE | |
fi | |
# There is a bug in our version of `tc` that prevents setting scheduler back to | |
# pfifo_fast with an error: | |
# "qdisc 'pfifo_fast' does not support option parsing" | |
# | |
# Bug was fixed here: | |
# https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/iproute2/+/e9e78b0db0e023035e346ba67de838be851eb665%5E%21/ | |
# Therefore verify that we can roll back by checking default qdisc | |
if [ "$(cat /proc/sys/net/core/default_qdisc)" != "pfifo_fast" ]; then | |
echo "default qdisc is not 'pfifo_fast'" >&2 | |
exit 2 | |
fi | |
intf="$1" | |
shed="$2" | |
cpus=(/sys/devices/system/cpu/cpu*/driver) | |
cpu_num=${#cpus[@]} | |
/sbin/tc qd del dev "$intf" root || : | |
if [ "$shed" == "pfifo_fast" ]; then | |
echo "default qdisc selected; skipping creation" >&2 | |
exit 0 | |
fi | |
/sbin/tc qd add dev "$intf" root handle 1: mq | |
for i in $(seq 1 $cpu_num); do | |
slot="$(printf %x $i)" | |
/sbin/tc qd add dev "$intf" parent 1:"$slot" "$shed" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment