Skip to contentSkip to conversation

sch_sfq: revert dont put new flow at the end of flows

PATCH Applied Eric Dumazet 4 participants 8 messages Mar 14, 2012 – Mar 16, 2012 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/1 sch_sfq: revert dont put new flow at the end of flows

In reply to a message not in the archive

This reverts commit d47a0ac7b6 (sch_sfq: dont put new flow at the end of flows)

As Jesper found out, patch sounded great but has bad side effects.

In stress situation, pushing new flows in front of the queue can prevent old flows doing any progress. Packets can stay in SFQ queue for unlimited amount of time.

It's possible to add heuristics to limit this problem, but this would add complexity outside of SFQ scope.

A more sensible answer to Dave Taht concerns (who reported the issued I tried to solve in original commit) is probably to use a qdisc hierarchy so that high prio packets dont enter a potentially crowded SFQ qdisc.

---
I tried various tricks to avoid a revert but in the end it sounds better to use a single queue.

 net/sched/sch_sfq.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/sched/sch_sfq.c +5 -1
index 60d4718..02a21ab 100644
@@ -469,11 +469,15 @@ enqueue:
 	if (slot->qlen == 1) {		/* The flow is new */
 		if (q->tail == NULL) {	/* It is the first flow */
 			slot->next = x;
-			q->tail = slot;
 		} else {
 			slot->next = q->tail->next;
 			q->tail->next = x;
 		}
+		/* We put this flow at the end of our flow list.
+		 * This might sound unfair for a new flow to wait after old ones,
+		 * but we could endup servicing new flows only, and freeze old ones.
+		 */
+		q->tail = slot;
 		/* We could use a bigger initial quantum for new flows */
 		slot->allot = q->scaled_quantum;
 	}
#2 lore raw
Quoted 4 lines · Eric Dumazet

This reverts commit d47a0ac7b6 (sch_sfq: dont put new flow at the end of flows)

As Jesper found out, patch sounded great but has bad side effects.

Well under most circumstances it IS great.

As the depth of the sfq queue increases it gets increasingly hard to trigger the problem. I've been using values in the 200-300 range, and in combination with red, haven't seen it happen.

Also in part the sfq behavior observed is due to an interaction with htb's 'capture' of a packet rather than peek. The situation that jesper encountered this issue (trying to regulate flows to hundreds of downstream clients on a very deterministic test) was different from where I don't encounter it (trying to regulate flows up from a very few clients)

For more details:

http://www.bufferbloat.net/issues/332

But I concur in reverting this for now. Sadly. wouldn't mind if there was a way to keep it as is as an option...

Quoted 11 lines

In stress situation, pushing new flows in front of the queue can prevent old flows doing any progress. Packets can stay in SFQ queue for unlimited amount of time.

It's possible to add heuristics to limit this problem, but this would add complexity outside of SFQ scope.

A more sensible answer to Dave Taht concerns (who reported the issued I tried to solve in original commit) is probably to use a qdisc hierarchy so that high prio packets dont enter a potentially crowded SFQ qdisc.

Um, er, in today's port 80/433 world, there isn't any such thing as high prio packets.

I am curious as to whether this problem can be made to happen with qfq.

Quoted 6 lines

---
I tried various tricks to avoid a revert but in the end it sounds better to use a single queue.

I had some hope for a semi-random alternating queue

Quoted 27 lines

 net/sched/sch_sfq.c |    6 +++++-

 1 file changed, 5 insertions(+), 1 deletion(-)
net/sched/sch_sfq.c +0 -0
index 60d4718..02a21ab 100644
@@ -469,11 +469,15 @@ enqueue:

       if (slot->qlen == 1) {          /* The flow is new */
               if (q->tail == NULL) {  /* It is the first flow */ slot->next = x;
-                       q->tail = slot;
               } else {
                       slot->next = q->tail->next;
                       q->tail->next = x;
               }
+               /* We put this flow at the end of our flow list.
+                * This might sound unfair for a new flow to wait after old ones,
+                * but we could endup servicing new flows only, and freeze old ones.
+                */
+               q->tail = slot;
               /* We could use a bigger initial quantum for new flows */ slot->allot = q->scaled_quantum;
       }

Signature · 4 lines
Dave Täht
SKYPE: davetaht
US Tel: 1-239-829-5608
http://www.bufferbloat.net
#3 lore raw
Quoted 2 lines · Dave Taht

I had some hope for a semi-random alternating queue

I spent some time implementing two queues, one for new flows, one for old flows. As soon as a new flow uses its initial quantum, its moved at the tail of 'old flows queue'.

But I always could find a way to starve some flows, even adding some kind of persistence. Right now, as soon as we empty one flow, we forget its history.

Next packet coming will create a "new flow" with a full quantum credit, even if we nearly consume all flow quantum in the last micro second.

Thats definitely not a trivial problem.

#4 lore raw
Quoted 9 lines · Eric Dumazet
Quoted 2 lines · Dave Taht

I had some hope for a semi-random alternating queue

I spent some time implementing two queues, one for new flows, one for old flows. As soon as a new flow uses its initial quantum, its moved at the tail of 'old flows queue'.

Quoted 8 lines

But I always could find a way to starve some flows, even adding some kind of persistence. Right now, as soon as we empty one flow, we forget its history.

Next packet coming will create a "new flow" with a full quantum credit, even if we nearly consume all flow quantum in the last micro second.

Thats definitely not a trivial problem.

I've expended brain cells on this too (nobody has any experience with head drop, aqm managed queues!), and was unable to come up with a way of dealing with the corner case of too many new streams inside of sfq's current architecture.

But I gotta say that the overall effect of this on optimizing sparse streams (dns,dhcp,tcp syn,ra,other routing packets,gaming packets,etc) was pretty freaking amazing, and it nearly eliminated any need for classification and prioritization, BE, and BK were enough.

Ah, well. The other stuff in 3.3 is really good, too.

Sometimes you win, sometimes you lose, sometimes... it rains.

Quoted 3 lines
Signature · 4 lines
Dave Täht
SKYPE: davetaht
US Tel: 1-239-829-5608
http://www.bufferbloat.net
#5 lore raw
In reply to Dave Taht

ons, 14 03 2012 kl. 04:52 +0000, skrev Dave Taht:

Quoted 7 lines · Eric Dumazet
Quoted 4 lines

This reverts commit d47a0ac7b6 (sch_sfq: dont put new flow at the end of flows)

As Jesper found out, patch sounded great but has bad side effects.

Well under most circumstances it IS great.

Yes, I had really high hopes for this patch. It unfortunately it can cause starvation in some situations :-(.

Quoted 3 lines

As the depth of the sfq queue increases it gets increasingly hard to trigger the problem. I've been using values in the 200-300 range, and in combination with red, haven't seen it happen.

I don't think you should adjust the "depth", but instead "limit" or "flows".

The problem can be solved by SFQ parameter tuning. Perhaps, we could just change the default parameters?

The problem occurs when all flows have ONE packet, then sfq_drop() cannot find a good flow to drop packets from...

This situation can occur because the default setting is "limit=127" packets and "flows=127". If we just make sure that "limit" > "flows", then one flow with >=2 packets should exist, which is then chosen for drop.
My practical experiments show that "limit" should be between 10-20 packets larger than "flows" (I'm not completely sure why this is needed).

[cut]

Quoted 3 lines
Quoted 3 lines

In stress situation, pushing new flows in front of the queue can prevent old flows doing any progress. Packets can stay in SFQ queue for unlimited amount of time.

In my experiments, one "existing" flow would get all the bandwidth,
while other flows got starved. And new flows could not be established.

--Jesper Brouer

#6 lore raw
Quoted 16 lines · Jesper Dangaard Brouer

ons, 14 03 2012 kl. 04:52 +0000, skrev Dave Taht:

Quoted 5 lines · Eric Dumazet

As the depth of the sfq queue increases it gets increasingly hard to trigger the problem. I've been using values in the 200-300 range, and in combination with red, haven't seen it happen.

I don't think you should adjust the "depth", but instead "limit" or "flows".

The problem can be solved by SFQ parameter tuning. Perhaps, we could just change the default parameters?

The problem occurs when all flows have ONE packet, then sfq_drop() cannot find a good flow to drop packets from...

Quoted 8 lines

This situation can occur because the default setting is "limit=127" packets and "flows=127". If we just make sure that "limit" > "flows", then one flow with >=2 packets should exist, which is then chosen for drop.
My practical experiments show that "limit" should be between 10-20 packets larger than "flows" (I'm not completely sure why this is needed).

There are many ways to starve SFQ if we dont revert the patch or add new logic in linux-3.4

Even if we change default settings, we can have following situation :

SFQ in a state with several regular flows in queue, correctly behaving because they are nice.

loop repeat_as_many_times_you_can_think
enqueue : packet comes for a new flow X.
OK lets favor this new flow against 'old' ones.
dequeue : takes the packet for flow X.
forget about flow X since dequeue all its packets.
endloop

All other flows are in a frozen state.

#7 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Jesper Dangaard Brouer

ons, 14 03 2012 kl. 04:52 +0000, skrev Dave Taht:

Quoted 5 lines · Eric Dumazet

As the depth of the sfq queue increases it gets increasingly hard to trigger the problem. I've been using values in the 200-300 range, and in combination with red, haven't seen it happen.

I don't think you should adjust the "depth", but instead "limit" or "flows".

Sorry, I'd meant 'limit' above, with limiting the per flow depth (at 4Mbit depths of 12-24 are good + red doing byte limiting starting at 3000), and having lots of flows in the hash....

Anyway, as this change to sfq currently has pathological edge cases, I suggest:

1) reverting this patch (the new features of sfq - hugely increased number of flows, and increased limit, head drop/marking support, red, ecn, etc, can stay - and are rather nice in and of themselves)

2) trying again, but not in the context of sfq - starting with sfq as a base, with a copy and rename, getting the iproute infrastructure around it working, more thorough tests going. I'll note that while flow management is needed, it needent be red-based.

nsfq? efq?

Quoted 3 lines
Quoted 3 lines

The problem can be solved by SFQ parameter tuning.  Perhaps, we could just change the default parameters?

I can't think of a way to make existing users of sfq not hit this problem if they are overriding the default params in the first place. thus my suggestion we start again in a new namespace.

Quoted 10 lines
Quoted 10 lines

The problem occurs when all flows have ONE packet, then sfq_drop() cannot find a good flow to drop packets from...

This situation can occur because the default setting is "limit=127" packets and "flows=127".  If we just make sure that "limit" > "flows", then one flow with >=2 packets should exist, which is then chosen for drop.
My practical experiments show that "limit" should be between 10-20 packets larger than "flows" (I'm not completely sure why this is needed).

flows and/or depth?

if flows, then we could drop the flows parameter entirely and just use limit to calculate flows. But I think that it's more subtle than just this.

more thorough tests exploring the pathological cases are needed. I'm on it.

Quoted 10 lines
Quoted 1 line

There are many ways to starve SFQ if we dont revert the patch or add new logic in linux-3.4

Even if we change default settings, we can have following situation :

SFQ in a state with several regular flows in queue, correctly behaving because they are nice.

Quoted 8 lines

loop repeat_as_many_times_you_can_think
 enqueue : packet comes for a new flow X.
          OK lets favor this new flow against 'old' ones. dequeue : takes the packet for flow X.
          forget about flow X since dequeue all its packets. endloop

All other flows are in a frozen state.

some thoughts

1) Keeping more history around during the next X packet deliveries would help.
2) in case of being close up against various limits randomly enqueue on tail

I note that htb introduces a window for new flows to win pathologically by holding onto a packet
which perhaps it should be peeking (or so I understand it)

Quoted 3 lines
Signature · 4 lines
Dave Täht
SKYPE: davetaht
US Tel: 1-239-829-5608
http://www.bufferbloat.net
maintainer Applied
#8 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 13 Mar 2012 21:04:25 -0700

Quoted 12 lines

This reverts commit d47a0ac7b6 (sch_sfq: dont put new flow at the end of flows)

As Jesper found out, patch sounded great but has bad side effects.

In stress situation, pushing new flows in front of the queue can prevent old flows doing any progress. Packets can stay in SFQ queue for unlimited amount of time.

It's possible to add heuristics to limit this problem, but this would add complexity outside of SFQ scope.

Quoted 7 lines

A more sensible answer to Dave Taht concerns (who reported the issued I tried to solve in original commit) is probably to use a qdisc hierarchy so that high prio packets dont enter a potentially crowded SFQ qdisc.

Applied, thanks Eric.