Stochastic Fair Blue queue discipline
Subsystems (3)
PATCH 1/1 Stochastic Fair Blue queue discipline
Hello,
The attached is an implementation of the Stochastic Fair Blue queue discipline for Linux.
I would like to request a review of the following code, and whether it is worthwile to add the Kconfig bits and submit it for inclusion into the mainline kernel.
You will find a ready to build tarball on
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz.asc
and a short description on
http://www.pps.jussieu.fr/~jch/software/sfb/
Thanks,
Juliusz Chroboczek
Makefile +11 -0
@@ -0,0 +1,11 @@ +KERNEL_SOURCE=/lib/modules/$(shell uname -r)/build + +obj-m += sch_sfb.o + +all: + make -C $(KERNEL_SOURCE) M=$(PWD) modules + +clean: + make -C $(KERNEL_SOURCE) M=$(PWD) clean + -rm -f *~ Module.symvers +
README +160 -0
160 lines not on this page · raw message
sch_sfb.c +687 -0
687 lines not on this page · raw message
sfb.h +52 -0
52 lines not on this page · raw message
tc/Makefile +1 -0
@@ -13,6 +13,7 @@ TCMODULES += q_tbf.o TCMODULES += q_cbq.o TCMODULES += q_rr.o TCMODULES += q_netem.o +TCMODULES += q_sfb.o TCMODULES += f_rsvp.o TCMODULES += f_u32.o TCMODULES += f_route.o
tc/q_sfb.c new file +252 -0
252 lines not on this page · raw message
Quoted 9 lines · Juliusz Chroboczek
Hello,
The attached is an implementation of the Stochastic Fair Blue queue discipline for Linux.
I would like to request a review of the following code, and whether it is worthwile to add the
Kconfigbits and submit it for inclusion into the mainline kernel.
Quoted 8 lines
You will find a ready to build tarball on
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz.ascand a short description on
Do you have some graphs or something showing the effects? I experienced with SFB myself some time ago and recall getting huge unfairness towards non-ECN connections. I can't remember exactly how good it behaved overall.
Quoted 17 lines · Patrick McHardy
Quoted 16 lines · Juliusz Chroboczek
Hello,
The attached is an implementation of the Stochastic Fair Blue queue discipline for Linux.
I would like to request a review of the following code, and whether it is worthwile to add the
Kconfigbits and submit it for inclusion into the mainline kernel.You will find a ready to build tarball on
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz
http://www.pps.jussieu.fr/~jch/software/files/sch_sfb-20080407.tar.gz.asc
Quoted 8 lines
Quoted 3 lines
and a short description on
Do you have some graphs or something showing the effects? I experienced with SFB myself some time ago and recall getting huge unfairness towards non-ECN connections. I can't remember exactly how good it behaved overall.
I just found my old tree and it was just Blue, which might explain this :) Thanks for posting this, I'll have a closer look at your patch tommorrow.
Quoted 2 lines
I experienced with SFB myself some time ago and recall getting huge unfairness towards non-ECN connections.
I've only done informal checking, but didn't test ECN against non-ECN. Will do, and I'll let you know the results.
Quoted 1 line
I just found my old tree and it was just Blue, which might explain this
Blue is supposed to be roughly fair w.r.t. TCP-compliant flows with similar RTT. If you see long-term unfairness with Blue at a single RTT, then something is wrong at the sender. I'll see if I can repeat your issues.
Earlier versions of Linux did not reduce their sending rate when they received ECE and the congestion window was just 1 MSS. I don't know if this bug has been fixed.
Juliusz
Juliusz Chroboczek <[email protected]> writes:
Have not read everything. General comment you'll likely need to do some code style cleanups (read Documentation/CodingStyle) Especially indentation should be consistent (one easy way to get that would be to run it through Lindent, although you might need to review it afterwards because Lindent sometimes does weird things)
sch_sfb.c line 58
Quoted 9 lines
sch_sfb.c +9
-0+ +static unsigned sfb_hash (struct sk_buff *skb,int hash,int filter, +struct sfb_sched_data *q) +{ +u32 h, h2; +u8 hash_type = q->hash_type; + +switch (skb->protocol) { +case __constant_htons (ETH_P_IP ):
I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
The nice property of that is that it would make it much easier to add new protocols later.
sch_sfb.c line 255
Quoted 13 lines
sch_sfb.c +13
-0+static int sfb_enqueue (struct sk_buff *skb,struct Qdisc * sch) +{ + +struct sfb_sched_data *q =qdisc_priv (sch); +struct Qdisc *child = q->qdisc; +psched_time_t now; +int filter; +u16 minprob =SFB_MAX_PROB ; +u16 minqlen = (u16)(~0 ); +u32 r; +int ret, i; + + now =psched_get_time ();
Getting high res time can be actually somewhat expensive on different platforms. I would recommend to only use it if it's actually needed in the inelastic flow case below and use jiffies to check for rehashing.
Quoted 4 lines
sch_sfb.c +4
-0+ +if (q->rehash_interval >0 ) { +psched_tdiff_t age; + age = psched_tdiff_bounded(now, q->rehash_time,
sch_sfb.c line 269
Quoted 10 lines
sch_sfb.c +10
-0+ q->rehash_interval * + PSCHED_TICKS_PER_SEC); +if (unlikely (age >= q->rehash_interval *PSCHED_TICKS_PER_SEC )) { +swap_buffers (q); + q->rehash_time = now; + } +if (unlikely (!q->double_buffering && q->db_interval >0 && + age >= (q->rehash_interval - q->db_interval) * +PSCHED_TICKS_PER_SEC )) + q->double_buffering =1 ;
/dev/random is a precious resource (some systems have very little true entropy) and getting that much data from it regularly is not a good idea because you take it away from other users who really need it (like strong cryptography)
I'm not sure if the rehash is for security or not (some comments on that would be good). But in any case it is likely better you only get the get_random_bytes() entropy once and then use that to init some kind of RNG (either a secure one if it's for security or some random fast one if it's not) and then use that output for rehashing.
-Andi
Quoted 7 lines · Andi Kleen
Juliusz Chroboczek <[email protected]> writes:
Have not read everything. General comment you'll likely need to do some code style cleanups (read
Documentation/CodingStyle) Especially indentation should be consistent (one easy way to get that would be to run it through Lindent, although you might need to review it afterwards because Lindent sometimes does
weird things)
Quoted 12 lines
sch_sfb.c line 58
Quoted 9 lines
sch_sfb.c +9
-0+ +static unsigned sfb_hash (struct sk_buff *skb,int hash,int filter, +struct sfb_sched_data *q) +{ +u32 h, h2; +u8 hash_type = q->hash_type; + +switch (skb->protocol) { +case __constant_htons (ETH_P_IP ):I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
I'd suggest to use the flow classifier for this. For simplicity you could attach a default classifier that uses the same keys as this one.
Quoted 7 lines
Quoted 3 lines
I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
I'd suggest to use the flow classifier for this. For simplicity you could attach a default classifier that uses the same keys as this one.
I'm not sure I know what you're speaking about. Could you please point me at code somewhere?
Juliusz
Quoted 10 lines · Juliusz Chroboczek
Quoted 7 lines
Quoted 3 lines
I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
I'd suggest to use the flow classifier for this. For simplicity you could attach a default classifier that uses the same keys as this one.
I'm not sure I know what you're speaking about. Could you please point me at code somewhere?
Check out a recent tree (either Linus' current tree or ideally the net-2.6.26.git tree from
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.26.git
and look at net/sched/cls_flow.c and the recent changes to net/sched/sch_sfq.c for external classifiers. There are also a number of other incompatible changes that your patch needs to be adapter to, most importantly the use of the new netlink infrastructure.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I'd suggest to use the flow classifier for this. For simplicity you could attach a default classifier that uses the same keys as this one.
I'm not sure I know what you're speaking about. Could you please point me at code somewhere?
Quoted 7 lines
Check out a recent tree (either Linus' current tree or ideally the net-2.6.26.git tree from
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.26.gitand look at
net/sched/cls_flow.cand the recent changes tonet/sched/sch_sfq.cfor external classifiers.
Thanks for the pointer. Unfortunately, it will need some changes to work with sfb -- since we do double-buffering, we need some overlap between the old and new classifiers when we choose to reclassify. I'm not quite sure how to do that.
Other than that, it will require some changes to sfb (which currently assumes we can get an arbitrary amount of hash data for a single packet, while the classifiers only give 32 bits), but these changes are a good thing -- 32 bits should be enough.
Would you have an example of how this stuff is configured from user-space?
Quoted 3 lines
There are also a number of other incompatible changes that your patch needs to be adapter to, most importantly the use of the new netlink infrastructure.
Done, thanks for the pointer.
Juliusz
Quoted 12 lines · Juliusz Chroboczek
Quoted 12 lines
Quoted 6 lines
Quoted 3 lines
I'd suggest to use the flow classifier for this. For simplicity you could attach a default classifier that uses the same keys as this one.
I'm not sure I know what you're speaking about. Could you please point me at code somewhere?
Check out a recent tree (either Linus' current tree or ideally the net-2.6.26.git tree from
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.26.git
Quoted 7 lines
Quoted 2 lines
and look at
net/sched/cls_flow.cand the recent changes tonet/sched/sch_sfq.cfor external classifiers.Thanks for the pointer. Unfortunately, it will need some changes to work with sfb -- since we do double-buffering, we need some overlap between the old and new classifiers when we choose to reclassify. I'm not quite sure how to do that.
You mean for perturbation? Yes, thats something not currently supported. I'd suggest to ignore this for now, I intend to add support, just need to figure out a way to reliably kill the timer on cleanup (can't use del_timer_sync since we're holding a lock). Shouldn't be that hard ...
Quoted 4 lines
Other than that, it will require some changes to sfb (which currently assumes we can get an arbitrary amount of hash data for a single packet, while the classifiers only give 32 bits), but these changes are a good thing -- 32 bits should be enough.
Actually its only (max) 16 bits, the qdisc handle is always encoded in the upper 16 bits. If you need more you could combine it with other data. I recall seeing a paper about bloom filters that analyzed the effectiveness of this compared to perfect hashing, they concluded that the increase in false positives is negligible.
I'll see if I can find it again in case you're interested.
Quoted 2 lines
Would you have an example of how this stuff is configured from user-space?
I'm using this for per-dst hashing to 1024 classes (1400:1 - 1400:1025).
tc filter add dev eth0 protocol ip pref 1 parent 1400: handle 1 \
flow hash keys dst divisor 1024
Quoted 1 line
(read
Documentation/CodingStyle)
Will do, thanks for the pointer.
Quoted 6 lines
sch_sfb.c line 52
Quoted 2 lines
sch_sfb.c +2
-0+static unsigned sfb_hash (struct sk_buff *skb,int hash,int filter, +struct sfb_sched_data *q)I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
I'll be glad to do so. Where shall I put it?
Quoted 3 lines
Getting high res time can be actually somewhat expensive on different platforms. I would recommend to only use it if it's actually needed in the inelastic flow case below and use jiffies to check for rehashing.
Good point.
Quoted 4 lines
/dev/randomis a precious resource (some systems have very little true entropy) and getting that much data from it regularly is not a good idea because you take it away from other users who really need it
In the default configuration, I'm getting 32 bytes every 10 minutes, which seemed reasonable. This code was copied from sch_sfq (function sfq_perturbation), which does the very same thing.
Quoted 4 lines
But in any case it is likely better you only get the
get_random_bytes()entropy once and then use that to init some kind of RNG (either a secure one if it's for security or some random fast one if it's not) and then use that output for rehashing.
Could do, but in that case the RNG should be shared between sfq and sfb. Shall I simply use net_random (which calls random32) ?
Juliusz
Quoted 5 lines · Juliusz Chroboczek
Quoted 3 lines
I think we have multiple qdiscs now doing very similar such hashes. Any chance this could be factored out into a common library function first?
I'll be glad to do so. Where shall I put it?
See Patrick's suggestion.
Quoted 7 lines
Quoted 4 lines
But in any case it is likely better you only get the
get_random_bytes()entropy once and then use that to init some kind of RNG (either a secure one if it's for security or some random fast one if it's not) and then use that output for rehashing.Could do, but in that case the RNG should be shared between sfq and sfb. Shall I simply use
net_random(which calls random32) ?
no net_random/srandom32 is per CPU and likely does the wrong thing for you.
There was a new RND being scheduled to be merged with perfmon, either use that or add a simple own (I assume your needs are not great)
-Andi
Quoted 1 line
no net_random/srandom32 is per CPU and likely does the wrong thing for you.
Why is that? I'm only using this to initialise a global data structure, why should it matter that I use per-cpu state?
Juliusz
Quoted 4 lines · Juliusz Chroboczek
Quoted 1 line
no net_random/srandom32 is per CPU and likely does the wrong thing for you.
Why is that? I'm only using this to initialise a global data structure, why should it matter that I use per-cpu state?
Because they're independent and there is no guarantee you always run on the same CPU and sampling them randomly will not necessarily give you a good random number sequence.
-Andi
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
no net_random/srandom32 is per CPU and likely does the wrong thing for you.
Why is that? I'm only using this to initialise a global data structure, why should it matter that I use per-cpu state?
Because they're independent and there is no guarantee you always run on the same CPU and sampling them randomly will not necessarily give you a good random number sequence.
I'm sorry to be such a pain, but I still don't understand.
Random32 is initialised from get_random_bytes; so the per-cpu pseudo-random sequences should be uncorrelated. I fail to see how an arbitrary interleaving of uncorrelated good pseudo-random sequences can fail to be good.
Looking at line 448 of sch_sfq.c in Linus' current HEAD, I see that somebody else thinks the same as I do. So please let me know if sfq needs fixed, or whether I can use net_random in sfb.
Thanks,
Juliusz
Quoted 4 lines
Random32 is initialised from
get_random_bytes; so the per-cpu pseudo-random sequences should be uncorrelated. I fail to see how an arbitrary interleaving of uncorrelated good pseudo-random sequences can fail to be good.
They are not necessarily uncorreleated, especially on platforms which do have poor entropy support and when your initialization happens at boot time. Take a look at how the random pool starts in random.c.
Quoted 4 lines
Looking at line 448 of
sch_sfq.cin Linus' current HEAD, I see that somebody else thinks the same as I do. So please let me know if sfq needs fixed, or whether I can usenet_randomin sfb.
A lot of people get this wrong, but this doesn't mean that the problem should be readded in new code again.
-Andi
Quoted 9 lines · Andi Kleen
Quoted 4 lines
Random32 is initialised from
get_random_bytes; so the per-cpu pseudo-random sequences should be uncorrelated. I fail to see how an arbitrary interleaving of uncorrelated good pseudo-random sequences can fail to be good.They are not necessarily uncorreleated, especially on platforms which do have poor entropy support and when your initialization happens at boot time. Take a look at how the random pool starts in
random.c.
Quoted 6 lines
Quoted 3 lines
Looking at line 448 of
sch_sfq.cin Linus' current HEAD, I see that somebody else thinks the same as I do. So please let me know if sfq needs fixed, or whether I can usenet_randomin sfb.A lot of people get this wrong, but this doesn't mean that the problem should be readded in new code again.
Well, if I'm not mistaken net_random() used to be a function (in net/core/utils.c) that didn't have this problem. So these problems seem to have been introduced by the conversion to srandom().
Quoted 14 lines · Patrick McHardy
Quoted 13 lines · Andi Kleen
Quoted 4 lines
Random32 is initialised from
get_random_bytes; so the per-cpu pseudo-random sequences should be uncorrelated. I fail to see how an arbitrary interleaving of uncorrelated good pseudo-random sequences can fail to be good.They are not necessarily uncorreleated, especially on platforms which do have poor entropy support and when your initialization happens at boot time. Take a look at how the random pool starts in
random.c.Quoted 3 lines
Looking at line 448 of
sch_sfq.cin Linus' current HEAD, I see that somebody else thinks the same as I do. So please let me know if sfq needs fixed, or whether I can usenet_randomin sfb.
Quoted 8 lines
Quoted 2 lines
A lot of people get this wrong, but this doesn't mean that the problem should be readded in new code again.
Well, if I'm not mistaken
net_random()used to be a function (innet/core/utils.c) that didn't have this problem. So these problems seem to have been introduced by the conversion tosrandom().
Two more noteworthy things:
- net_random() was intended to provide *mediocre* random, cheap to compute, not perfect. Good enough for many networking related things.
- traffic schedulers shouldn't depend on perfect random, its more about statistical multiplexing.
Quoted 2 lines
- traffic schedulers shouldn't depend on perfect random, its more about statistical multiplexing.
Okay, I've been thinking about this, and I'm not quite sure that what sfq and sfb want is a pseudo-random sequence in the first place.
Sfq and sfb only draw random numbers in order to change hashing functions periodically, so as not to have an innocent flow stuck within a hash bucket with a non-reactive flow. For sfb it doesn't matter much (collisions in a Bloom filter are so rare as to be almost nonexistent), but for sfq, it is fairly important.
Now assuming jhash is any good, i.e. that a single bit change in the input changes all output bits with roughly similar probability (and I don't know whether it is), it shouldn't matter much what sequence of u32 we use for the perturbation as long as it doesn't repeat values too often. Something as simple as a static counter might actually be good enough.
So I'd argue that the wise thing is to make sure of is that jhash is good (in the sense above), and not bother too much with the PRNG.
Juliusz
Quoted 19 lines · Juliusz Chroboczek
Quoted 2 lines
- traffic schedulers shouldn't depend on perfect random, its more about statistical multiplexing.
Okay, I've been thinking about this, and I'm not quite sure that what sfq and sfb want is a pseudo-random sequence in the first place.
Sfq and sfb only draw random numbers in order to change hashing functions periodically, so as not to have an innocent flow stuck within a hash bucket with a non-reactive flow. For sfb it doesn't matter much (collisions in a Bloom filter are so rare as to be almost nonexistent), but for sfq, it is fairly important.
Now assuming jhash is any good, i.e. that a single bit change in the input changes all output bits with roughly similar probability (and I don't know whether it is), it shouldn't matter much what sequence of u32 we use for the perturbation as long as it doesn't repeat values too often. Something as simple as a static counter might actually be good enough.
Quoted 2 lines
So I'd argue that the wise thing is to make sure of is that jhash is good (in the sense above), and not bother too much with the PRNG.
Agreed. jhash gives pretty good distribution, so we should be fine.
Quoted 24 lines · On Thu, 10 Apr 2008 03:38:13 +0200 Patrick McHardy <[email protected]> wrote:
Quoted 14 lines · Patrick McHardy
Quoted 13 lines · Andi Kleen
Quoted 4 lines
Random32 is initialised from
get_random_bytes; so the per-cpu pseudo-random sequences should be uncorrelated. I fail to see how an arbitrary interleaving of uncorrelated good pseudo-random sequences can fail to be good.They are not necessarily uncorreleated, especially on platforms which do have poor entropy support and when your initialization happens at boot time. Take a look at how the random pool starts in
random.c.Quoted 3 lines
Looking at line 448 of
sch_sfq.cin Linus' current HEAD, I see that somebody else thinks the same as I do. So please let me know if sfq needs fixed, or whether I can usenet_randomin sfb.Quoted 8 lines
Quoted 2 lines
A lot of people get this wrong, but this doesn't mean that the problem should be readded in new code again.
Well, if I'm not mistaken
net_random()used to be a function (innet/core/utils.c) that didn't have this problem. So these problems seem to have been introduced by the conversion tosrandom().
Quoted 8 lines
Two more noteworthy things:
-
net_random()was intended to provide *mediocre* random, cheap to compute, not perfect. Good enough for many networking related things.- traffic schedulers shouldn't depend on perfect random, its more about statistical multiplexing.
Anything related to random number seems to bring out the paranoia in people.
Quoted 2 lines
Well, if I'm not mistaken
net_random()used to be a function (innet/core/utils.c) that didn't have this problem.
Correct it's a regression.
Quoted 3 lines
So these
problems seem to have been introduced by the conversion tosrandom().
I think the per CPU ness was generally a mistake, it was a misguided optimization and hurts
Iff someone really needs per cpu RNDs the better way would have been to add a rand_r() like interface with explicit state and only do that in that particular caller.
Also I think a lot of get_random_bytes() shouldn't really be using it because they don't need precious cryptographically strong entropy, but rather should get their data from another RND which has been seeded once from the entropy pool only.
-Andi
sch_sfb.c
Quoted 3 lines
diff -urN
empty/sch_sfb.csch_sfb/sch_sfb.csch_sfb.c +0
-0
I wanted to review this, but the CodingStyle issues are distracting to me, so I guess I'll wait until you've done the cleanups suggested by Andi.
If you could make your next patch against a kernel tree that would be also nice.