如何使用tc和cgroup对数据包进行优先处理 [英] How to priotize packets using tc and cgroups

查看:544
本文介绍了如何使用tc和cgroup对数据包进行优先处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对从特定进程组生成的数据包进行优先级排序,以便首先选择它们以从PC传输出去.我的目标是通过使用cgroups和tc来做到这一点,但似乎行不通.

I am trying to prioritize the packets that are generated from a certain process group so that they'll be picked first to be transmitted from the PC. I aim to do this by using cgroups and tc, but it seems not to work.

首先,我在ubuntu上设置cgroup,如下所示:

First I set up cgroups on ubuntu as follows,

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中浏览并运行后,

and after browsing in firefox and running,

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中流动,我在做什么错了?

Instead I want the traffic to flow in handle 10, what am I doing wrong?

推荐答案

执行此操作的正确方法要求告知tc您将使用cgroup.在3.10内核的Ubuntu 12.04上已对此进行了验证.

The correct way to do this requires informing tc that you are to be using cgroups. This has been verified on Ubuntu 12.04 with a 3.10 kernel.

$ 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

如果没有,

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

Just put all these options in your .config. These appear not to exist in 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

然后制作并安装.

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

创建测试cgroup并进行设置

如果未设置cpuset,则某些cgroup设置会抱怨通用错误.您还必须将主要和次要tc类ID转换为0xAAAABBBB的十六进制,其中AAAA为主要,BBBB为次要.

Create the test cgroup and set it up

Some cgroup setups complain with generic errors if cpuset is not set. You also must convert your major and minor tc class ID into hex of 0xAAAABBBB where AAAA is major and BBBB is minor.

# 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 tasks into cgroup

(but only one at a time)

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

修改tc类

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

我无法使用Ingress进行这项工作.仅出口(上载)似乎正在运行. tc似乎不带有带有ingress的cgroup选项.

I have been unable to make this work with ingress. Only egress (upload) appears to be working. tc does not appear to take the cgroup option with ingress.

这篇关于如何使用tc和cgroup对数据包进行优先处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆