gpt4 book ai didi

linux - 如何使用 tc 和 cgroups 对数据包进行优先级排序

转载 作者:IT王子 更新时间:2023-10-29 01:24:24 26 4
gpt4 key购买 nike

我正在尝试对从某个进程组生成的数据包进行优先级排序,以便首先挑选它们从 PC 传输。我打算通过使用 cgroups 和 tc 来做到这一点,但它似乎不起作用。

首先我在ubuntu上设置cgroups如下,

modprobe cls_cgroup # load this module to get net_cls

mkdir /sys/fs/cgroup/net_cls # mount point

mount -t cgroup net_cls -onet_cls /sys/fs/cgroup/net_cls/

mkdir /sys/fs/cgroup/net_cls/foo # new cgroup

echo 0x00010001 > /sys/fs/cgroup/foo/net_cls.classid # echo in a class id

echo 2348 > /sys/fs/cgroup/net_cls/foo/tasks # echo in pid of firefox

tc qdisc add dev eth0 root handle 1: pri

tc qdisc add dev eth0 parent 1:1 handle 10: sfq

tc qdisc add dev eth0 parent 1:2 handle 20: sfq

tc qdisc add dev eth0 parent 1:3 handle 30: sfq

在 firefox 中浏览并运行后,

tc -s qdisc ls dev eth0

我明白了,

qdisc prio 1: root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 29351 bytes 154 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 10: parent 1:1 limit 127p quantum 1514b divisor 1024
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 20: parent 1:2 limit 127p quantum 1514b divisor 1024
Sent 27873 bytes 143 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 30: parent 1:3 limit 127p quantum 1514b divisor 1024
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0

相反,我希望流量流入句柄 10,我做错了什么?

最佳答案

执行此操作的正确方法需要通知 tc 您将使用 cgroups。这已在具有 3.10 内核的 Ubuntu 12.04 上得到验证。

确保你有 net_cls 支持

$ cat /proc/cgroups 
#subsys_name hierarchy num_cgroups enabled
cpuset 1 2 1
cpu 1 2 1
cpuacct 1 2 1
memory 1 2 1
net_cls 1 2 1
blkio 1 2 1

如果没有,

编译带有 net_cls 支持的内核

只需将所有这些选项放入您的 .config 中即可。这些似乎不存在于 menuconfig 中。

CONFIG_NET_CLS=y
CONFIG_NET_CLS_BASIC=m
CONFIG_NET_CLS_TCINDEX=m
CONFIG_NET_CLS_ROUTE4=m
CONFIG_NET_CLS_FW=m
CONFIG_NET_CLS_U32=m
CONFIG_NET_CLS_RSVP=m
CONFIG_NET_CLS_RSVP6=m
CONFIG_NET_CLS_FLOW=m
CONFIG_NET_CLS_CGROUP=y
CONFIG_NET_CLS_ACT=y
CONFIG_NET_CLS_IND=y

然后制作并安装。

确保您有/etc/fstab 条目

# echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
# reboot

创建测试cgroup并设置

如果未设置 cpuset,某些 cgroup 设置会报出一般性错误。您还必须将您的主要和次要 tc 类 ID 转换为 0xAAAABBBB 的十六进制,其中 AAAA 是主要的,BBBB 是次要的。

# mkdir /sys/fs/cgroup/clstest
# /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.mems
# /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.cpus
# /bin/echo 0x100001 > /sys/fs/cgroup/clstest/net_cls.classid

配置tc

# tc qdisc add dev eth2 root handle 10: htb
# tc class add dev eth2 parent 10: classid 10:1 htb rate 10mbit
# tc filter add dev eth2 parent 10: protocol ip prio 10 handle 1: cgroup

将任务回显到cgroup

(但一次只有一个)

# echo $FIREFOX_PID > /sys/fs/cgroup/clstest/tasks

修改tc类

# tc class change dev eth2 parent 10: classid 10:1 htb rate 40mbit

编辑:

我一直无法使用 ingress 进行这项工作。只有导出(上传)似乎在工作。 tc 似乎没有采用带有入口的 cgroup 选项。

关于linux - 如何使用 tc 和 cgroups 对数据包进行优先级排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9904016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com