# Mitigating bufferbloat in Gentoo

## depontius

Bufferbloat has been around and recognized for some time now, but recently it's getting more attention.  (Google "bufferbloat" and see.)  Basically it happens because packet buffers are getting bigger, as well as put in every step of the stream, and they're confusing TCP's congestion and retry algorithms.  I'm typing this while working from home, watching things crawl along.  Maybe it's bufferbloat, maybe it's not, but for the moment that's something I think I can do something about.

The essence of bufferbloat mitigation is to limit your up and down transmission rates to your actual provisioned rates, instead of the bursty rates that happen as a side-effect of too many buffers in too many places.  The simple and perhaps most valuable part is limiting your uplink speed, so it just doesn't get buffered.  Limiting the downlink speed is harder, and negates PowerBoost, but I guess it's possible, basically by sending back "you're sending data too fast!" packets to your ISP.

The mechanics of this are the question.

Most of the new writings on mitigating bufferbloat are appliance-oriented - "Fill in X value in this QOS field of your router."  There's a guide that I recognize from having read years ago, here: http://lartc.org/howto/lartc.cookbook.ultimate-tc.html  But I've gotten the impression in the past that all of this stuff is evolving, and an old document may no longer work, and in fact even that documentation shows 2 ways to do the job, one involving patching the kernel.

Does anyone know what are current practices for link management, using what is available in portage?  (Best Practices??)

----------

## boerKrelis

/etc/conf.d/net:

```
ifup_eth0="ip link set \$int txqueuelen 0"
```

is a good start. First I had sound hiccups when reading DVD files off of an NFS server while streaming the audio via pulseaudio, over the network, to the same server. I still have to figure out how to fix SSH though, large transfers cause horrendous latency on my network.

----------

## depontius

Tried that already, and though maybe it helped, yesterday afternoon was pretty darned pathetic.  At the same time, ordinary web browsing had no problems whatsoever, so I still believe it may be a traffic management issue, but I guess I need to dig harder into that link I gave.

----------

## boerKrelis

I've used a variant of what you had linked to in the past. It was called the 'wondershaper'.

My current setup, based on shorewall's QoS, works better and is more flexible. It does indeed help if you limit your upload so that the queue is on your side, under your control, so you can let interactive traffic skip the queue.

And there's a new rate control mechanism for TCP coming up in new kernels - forgot its name, but there was an article on LWN about it not long ago.

EDIT Found it, it's called CHOKe, <a href="http://lwn.net/Articles/422477/">lwn article here</a>.

----------

## depontius

Any idea when it's going in?  I can wait for 2.6.38, but I'd rather not wait for anything later to fix this.  Yesterday was just plain Comcastic!

----------

## boerKrelis

I don't know when (and if) it's going in, but the patch doesn't look that invasive:

<pre>

net/sched/Kconfig     |   11 +

net/sched/Makefile    |    1 

net/sched/sch_choke.c |  527 ++++++++++++++++++++++++++++++++++++++++++++++++++

3 files changed, 539 insertions(+)

</pre>

so it's worth a try to just do the patching yourself. You'll probably still need to set up stuff using 'tc'.

----------

## dtaht

 *boerKrelis wrote:*   

> I don't know when (and if) it's going in, but the patch doesn't look that invasive:
> 
> <pre>
> 
> net/sched/Kconfig     |   11 +
> ...

 

The debloat-testing tree was announced a few days ago and contains this patch, among others. See:

https://lists.bufferbloat.net/pipermail/bloat/2011-February/000171.html

For details.

I also note that although reducing txqueuelen is a good userspace option, it is an even better idea to try

reducing the size of the DMA TX RING in the ethernet and wireless drivers themselves, to something sane.

What I've been shooting for is a compromise between throughput and latency far better than the current one. At the very least, increasing the dynamic range available to ethtool so that you can reduce the dma tx ring to below 16, is a good idea. 

Some of the patches in the tree above do that. It's usually pretty straightforward.

----------

## depontius

Where in portage do I get the "tc" command, and what kernel options to I have to activate to make the stuff work?  I can understand that the article I referenced wouldn't tell the portage package name, but I'm surprised that they didn't mention kernel options.  Also, the articl gives two methods - CQB and HTC.  Does anyone here have a feel for one vs the other?

----------

## boerKrelis

sys-apps/iproute2, and my shorewall setup seems to use sfq with htb.

The kernel stuff is under CONFIG_NET_SCHED. Do you know how to use search in 'make menuconfig' ?

----------

## depontius

I fear I admit to usually using "xconfig", and yes, I know how to search.  Incidentally, I already have iproute2 installed - I just assumed I'd have to emerge yet another package to get tc, and :

```
[user@localhost ~]$ grep CONFIG_NET_SCHED /mnt/gentoo/usr/src/linux/.config

CONFIG_NET_SCHED=y
```

----------

## dtaht

 *depontius wrote:*   

> Where in portage do I get the "tc" command, and what kernel options to I have to activate to make the stuff work?  I can understand that the article I referenced wouldn't tell the portage package name, but I'm surprised that they didn't mention kernel options.  Also, the articl gives two methods - CQB and HTC.  Does anyone here have a feel for one vs the other?

 

I note that in order to use both CHOKe and SFB schedulers effectively, 

you need the tc that is part of this set of patches to iproute2.

https://github.com/dtaht/iproute2bufferbloat

----------

## ojbyer

Apparently there's a major change going into the 3.3 kernel with regards to this issue: http://www.phoronix.com/scan.php?page=news_item&px=MTAzODg

I'd like to try this out but I really don't know about traffic control and how it interacts with whatever Shorewall sets up.

----------

