net: sctp: wake up all assocs if sndbuf policy is per socket
Subsystems (3)
PATCH 1/1 net: sctp: wake up all assocs if sndbuf policy is per socket
SCTP charges chunks for wmem accounting via skb->truesize in sctp_set_owner_w(), and sctp_wfree() respectively as the reverse operation. If a sender runs out of wmem, it needs to wait via sctp_wait_for_sndbuf(), and gets woken up by a call to __sctp_write_space() mostly via sctp_wfree().
__sctp_write_space() is being called per association. Although we assign sk->sk_write_space() to sctp_write_space(), which is then being done per socket, it is only used if send space is increased per socket option (SO_SNDBUF), as SOCK_USE_WRITE_QUEUE is set and therefore not invoked in sock_wfree().
Commit 4c3a5bdae293 ("sctp: Don't charge for data in sndbuf again when transmitting packet") fixed an issue where in case sctp_packet_transmit() manages to queue up more than sndbuf bytes, sctp_wait_for_sndbuf() will never be woken up again unless it is interrupted by a signal. However, a still remaining issue is that if net.sctp.sndbuf_policy=0, that is accounting per socket, and one-to-many sockets are in use, the reclaimed write space from sctp_wfree() is 'unfairly' handed back on the server to the association that is the lucky one to be woken up again via __sctp_write_space(), while the remaining associations are never be woken up again (unless by a signal).
The effect disappears with net.sctp.sndbuf_policy=1, that is wmem accounting per association, as it guarantees a fair share of wmem among associations.
Therefore, if we have reclaimed memory in case of per socket accouting, wake all related associations to a socket in a fair manner, that is, traverse the socket association list starting from the current neighbour of the association and issue a __sctp_write_space() to everyone until we end up waking ourselves. This guarantees that no association is preferred over another and even if more associations are taken into the one-to-many session, all receivers will get messages from the server and are not stalled forever on high load. This setting still leaves the advantage of per socket accounting in touch as an association can still use up global limits if unused by others.
---
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]
net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
net/sctp/socket.c +30 -1
@@ -6593,6 +6593,35 @@ static void __sctp_write_space(struct sctp_association *asoc) } } +static void sctp_wake_up_waiters (struct sock *sk, +struct sctp_association *asoc) +{ +struct sctp_association *tmp = asoc; + +/* We do accounting for the sndbuf space per association, +* so we only need to wake our own association. +*/ +if (asoc->ep->sndbuf_policy) +return __sctp_write_space (asoc); + +/* Accounting for the sndbuf space is per socket, so we need +* to wake up others, try to be fair and in case of other +* associations, let them have a go first instead of just +* doing a sctp_write_space() call. +*/ +for (tmp =list_next_entry (tmp, asocs);1 ; + tmp =list_next_entry (tmp, asocs)) { +/* Manually skip the head element. */ +if (&tmp->asocs = &((sctp_sk (sk))->ep->asocs)) +continue ; +/* Wake up association. */ +__sctp_write_space (tmp); +/* We've reached the end. */ +if (tmp = asoc) +break ; + } +} +/* Do accounting for the sndbuf space. * Decrement the used sndbuf space of the corresponding association by the * data size which was just transmitted(freed).
@@ -6620,7 +6649,7 @@ static void sctp_wfree(struct sk_buff *skb)sk_mem_uncharge (sk, skb->truesize);sock_wfree (skb); -__sctp_write_space (asoc); +sctp_wake_up_waiters (sk, asoc);sctp_association_put (asoc); }
Signature · 1 line
1.7.11.7
Quoted 68 lines · Daniel Borkmann
SCTP charges chunks for wmem accounting via
skb->truesizeinsctp_set_owner_w(), andsctp_wfree()respectively as the reverse operation. If a sender runs out of wmem, it needs to wait viasctp_wait_for_sndbuf(), and gets woken up by a call to__sctp_write_space()mostly viasctp_wfree().
__sctp_write_space()is being called per association. Although we assignsk->sk_write_space()tosctp_write_space(), which is then being done per socket, it is only used if send space is increased per socket option (SO_SNDBUF), asSOCK_USE_WRITE_QUEUEis set and therefore not invoked insock_wfree().Commit
4c3a5bdae293("sctp: Don't charge for data in sndbuf again when transmitting packet") fixed an issue where in casesctp_packet_transmit()manages to queue up more than sndbuf bytes,sctp_wait_for_sndbuf()will never be woken up again unless it is interrupted by a signal. However, a still remaining issue is that if net.sctp.sndbuf_policy=0, that is accounting per socket, and one-to-many sockets are in use, the reclaimed write space fromsctp_wfree()is 'unfairly' handed back on the server to the association that is the lucky one to be woken up again via__sctp_write_space(), while the remaining associations are never be woken up again (unless by a signal).The effect disappears with net.sctp.sndbuf_policy=1, that is wmem accounting per association, as it guarantees a fair share of wmem among associations.
Therefore, if we have reclaimed memory in case of per socket accouting, wake all related associations to a socket in a fair manner, that is, traverse the socket association list starting from the current neighbour of the association and issue a
__sctp_write_space()to everyone until we end up waking ourselves. This guarantees that no association is preferred over another and even if more associations are taken into the one-to-many session, all receivers will get messages from the server and are not stalled forever on high load. This setting still leaves the advantage of per socket accounting in touch as an association can still use up global limits if unused by others.Fixes 4eb701dfc618 ("[SCTP] Fix SCTP sendbuffer accouting.")Signed-off-by Daniel Borkmann <[email protected]>Cc Thomas Graf <[email protected]>Cc Neil Horman <[email protected]>---
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)net/sctp/socket.c +6
-0@@ -6593,6 +6593,35 @@ static void __sctp_write_space(struct sctp_association *asoc) } } +static void sctp_wake_up_waiters (struct sock *sk, +struct sctp_association *asoc) +{ +struct sctp_association *tmp = asoc; + +/* We do accounting for the sndbuf space per association,
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6611
Quoted 10 lines
net/sctp/socket.c +10
-0+* so we only need to wake our own association. +*/ +if (asoc->ep->sndbuf_policy) +return __sctp_write_space (asoc); + +/* Accounting for the sndbuf space is per socket, so we need +* to wake up others, try to be fair and in case of other +* associations, let them have a go first instead of just +* doing a sctp_write_space() call. +*/
May be a note saying that we are here only when association frees queued up chunks and thus we are under lock and the list is guaranteed not to change.
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6612
Quoted 1 line
net/sctp/socket.c +1
-0+ for (tmp = list_next_entry(tmp, asocs); 1;
Why not change the stop condition to tmp = asoc. It should work since it will not be head pointer.
-vlad
Quoted 25 lines
net/sctp/socket.c +13
-1+ tmp = list_next_entry(tmp, asocs)) { +/* Manually skip the head element. */ +if (&tmp->asocs = &((sctp_sk (sk))->ep->asocs)) +continue ; +/* Wake up association. */ +__sctp_write_space (tmp); +/* We've reached the end. */ +if (tmp = asoc) +break ; + } +} +/* Do accounting for the sndbuf space. * Decrement the used sndbuf space of the corresponding association by the * data size which was just transmitted(freed). @@ -6620,7 +6649,7 @@ static void sctp_wfree(struct sk_buff *skb)sk_mem_uncharge (sk, skb->truesize);sock_wfree (skb); -__sctp_write_space (asoc); +sctp_wake_up_waiters (sk, asoc);sctp_association_put (asoc); }
Quoted 75 lines · Vlad Yasevich
Quoted 74 lines · Daniel Borkmann
SCTP charges chunks for wmem accounting via
skb->truesizeinsctp_set_owner_w(), andsctp_wfree()respectively as the reverse operation. If a sender runs out of wmem, it needs to wait viasctp_wait_for_sndbuf(), and gets woken up by a call to__sctp_write_space()mostly viasctp_wfree().
__sctp_write_space()is being called per association. Although we assignsk->sk_write_space()tosctp_write_space(), which is then being done per socket, it is only used if send space is increased per socket option (SO_SNDBUF), asSOCK_USE_WRITE_QUEUEis set and therefore not invoked insock_wfree().Commit
4c3a5bdae293("sctp: Don't charge for data in sndbuf again when transmitting packet") fixed an issue where in casesctp_packet_transmit()manages to queue up more than sndbuf bytes,sctp_wait_for_sndbuf()will never be woken up again unless it is interrupted by a signal. However, a still remaining issue is that if net.sctp.sndbuf_policy=0, that is accounting per socket, and one-to-many sockets are in use, the reclaimed write space fromsctp_wfree()is 'unfairly' handed back on the server to the association that is the lucky one to be woken up again via__sctp_write_space(), while the remaining associations are never be woken up again (unless by a signal).The effect disappears with net.sctp.sndbuf_policy=1, that is wmem accounting per association, as it guarantees a fair share of wmem among associations.
Therefore, if we have reclaimed memory in case of per socket accouting, wake all related associations to a socket in a fair manner, that is, traverse the socket association list starting from the current neighbour of the association and issue a
__sctp_write_space()to everyone until we end up waking ourselves. This guarantees that no association is preferred over another and even if more associations are taken into the one-to-many session, all receivers will get messages from the server and are not stalled forever on high load. This setting still leaves the advantage of per socket accounting in touch as an association can still use up global limits if unused by others.Fixes 4eb701dfc618 ("[SCTP] Fix SCTP sendbuffer accouting.")Signed-off-by Daniel Borkmann <[email protected]>Cc Thomas Graf <[email protected]>Cc Neil Horman <[email protected]>---
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)net/sctp/socket.c +12
-0@@ -6593,6 +6593,35 @@ static void __sctp_write_space(struct sctp_association *asoc) } } +static void sctp_wake_up_waiters (struct sock *sk, +struct sctp_association *asoc) +{ +struct sctp_association *tmp = asoc; + +/* We do accounting for the sndbuf space per association, +* so we only need to wake our own association. +*/ +if (asoc->ep->sndbuf_policy) +return __sctp_write_space (asoc); + +/* Accounting for the sndbuf space is per socket, so we need
Quoted 8 lines
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6611
Quoted 4 lines
net/sctp/socket.c +4
-0+* to wake up others, try to be fair and in case of other +* associations, let them have a go first instead of just +* doing a sctp_write_space() call. +*/ May be a note saying that we are here only when association frees queued up chunks and thus we are under lock and the list is guaranteed not to change.
Ok, will add that to the comment and respin, thanks Vlad.
Quoted 4 lines
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6612
Quoted 1 line
net/sctp/socket.c +1
-0+ for (tmp = list_next_entry(tmp, asocs); 1;Why not change the stop condition to tmp = asoc. It should work since it will not be head pointer.
If I see this correctly, wouldn't we then exclude to eventually call __sctp_write_space(tmp) on ourselves as we also need to make sure to wake us up?
Quoted 28 lines
-vlad
Quoted 25 lines
net/sctp/socket.c +13
-1+ tmp = list_next_entry(tmp, asocs)) { +/* Manually skip the head element. */ +if (&tmp->asocs = &((sctp_sk (sk))->ep->asocs)) +continue ; +/* Wake up association. */ +__sctp_write_space (tmp); +/* We've reached the end. */ +if (tmp = asoc) +break ; + } +} +/* Do accounting for the sndbuf space. * Decrement the used sndbuf space of the corresponding association by the * data size which was just transmitted(freed). @@ -6620,7 +6649,7 @@ static void sctp_wfree(struct sk_buff *skb)sk_mem_uncharge (sk, skb->truesize);sock_wfree (skb); -__sctp_write_space (asoc); +sctp_wake_up_waiters (sk, asoc);sctp_association_put (asoc); }
Quoted 88 lines · Daniel Borkmann
Quoted 76 lines · Vlad Yasevich
Quoted 75 lines · Daniel Borkmann
SCTP charges chunks for wmem accounting via
skb->truesizeinsctp_set_owner_w(), andsctp_wfree()respectively as the reverse operation. If a sender runs out of wmem, it needs to wait viasctp_wait_for_sndbuf(), and gets woken up by a call to__sctp_write_space()mostly viasctp_wfree().
__sctp_write_space()is being called per association. Although we assignsk->sk_write_space()tosctp_write_space(), which is then being done per socket, it is only used if send space is increased per socket option (SO_SNDBUF), asSOCK_USE_WRITE_QUEUEis set and therefore not invoked insock_wfree().Commit
4c3a5bdae293("sctp: Don't charge for data in sndbuf again when transmitting packet") fixed an issue where in casesctp_packet_transmit()manages to queue up more than sndbuf bytes,sctp_wait_for_sndbuf()will never be woken up again unless it is interrupted by a signal. However, a still remaining issue is that if net.sctp.sndbuf_policy=0, that is accounting per socket, and one-to-many sockets are in use, the reclaimed write space fromsctp_wfree()is 'unfairly' handed back on the server to the association that is the lucky one to be woken up again via__sctp_write_space(), while the remaining associations are never be woken up again (unless by a signal).The effect disappears with net.sctp.sndbuf_policy=1, that is wmem accounting per association, as it guarantees a fair share of wmem among associations.
Therefore, if we have reclaimed memory in case of per socket accouting, wake all related associations to a socket in a fair manner, that is, traverse the socket association list starting from the current neighbour of the association and issue a
__sctp_write_space()to everyone until we end up waking ourselves. This guarantees that no association is preferred over another and even if more associations are taken into the one-to-many session, all receivers will get messages from the server and are not stalled forever on high load. This setting still leaves the advantage of per socket accounting in touch as an association can still use up global limits if unused by others.Fixes 4eb701dfc618 ("[SCTP] Fix SCTP sendbuffer accouting.")Signed-off-by Daniel Borkmann <[email protected]>Cc Thomas Graf <[email protected]>Cc Neil Horman <[email protected]>---
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)net/sctp/socket.c +12
-0@@ -6593,6 +6593,35 @@ static void __sctp_write_space(struct sctp_association *asoc) } } +static void sctp_wake_up_waiters (struct sock *sk, +struct sctp_association *asoc) +{ +struct sctp_association *tmp = asoc; + +/* We do accounting for the sndbuf space per association, +* so we only need to wake our own association. +*/ +if (asoc->ep->sndbuf_policy) +return __sctp_write_space (asoc); + +/* Accounting for the sndbuf space is per socket, so we need Quoted 8 lines
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6611
Quoted 4 lines
net/sctp/socket.c +4
-0+* to wake up others, try to be fair and in case of other +* associations, let them have a go first instead of just +* doing a sctp_write_space() call. +*/ May be a note saying that we are here only when association frees queued up chunks and thus we are under lock and the list is guaranteed not to change.
Ok, will add that to the comment and respin, thanks Vlad.
Quoted 9 lines
Quoted 4 lines
net/sctp/socket.c static void __sctp_write_space(struct sctp_association *asoc) · line 6612
Quoted 1 line
net/sctp/socket.c +1
-0+ for (tmp = list_next_entry(tmp, asocs); 1;Why not change the stop condition to tmp = asoc. It should work since it will not be head pointer.
If I see this correctly, wouldn't we then exclude to eventually call
__sctp_write_space(tmp)on ourselves as we also need to make sure to wake us up?
Ahh, yes. You are right.
This is yet another list traversal with skip_head. I am going to resurrect that code for net-next.
-vlad
Quoted 29 lines
Quoted 29 lines
-vlad
Quoted 26 lines
net/sctp/socket.c +12
-0+ tmp = list_next_entry(tmp, asocs)) { +/* Manually skip the head element. */ +if (&tmp->asocs = &((sctp_sk (sk))->ep->asocs)) +continue ; +/* Wake up association. */ +__sctp_write_space (tmp); +/* We've reached the end. */ +if (tmp = asoc) +break ; + } +} +/* Do accounting for the sndbuf space. * Decrement the used sndbuf space of the corresponding association by the
* data size which was just transmitted(freed).net/sctp/socket.c +1
-1@@ -6620,7 +6649,7 @@ static void sctp_wfree(struct sk_buff *skb)sk_mem_uncharge (sk, skb->truesize);sock_wfree (skb); -__sctp_write_space (asoc); +sctp_wake_up_waiters (sk, asoc);sctp_association_put (asoc); }
On 04/08/2014 05:26 PM, Vlad Yasevich wrote:
...
Quoted 2 lines
This is yet another list traversal with
skip_head. I am going to resurrect that code for net-next.
Sounds good! I actually had a look longer time ago, to squeeze all that logic into a list macro, but so far I didn't find something clean without appending an if-clause to it that tests for head element - and that I don't like as it can happen that unintentionally users could run into a dangling else. In the end it all looked more complicated than the current code was, so I wasn't really satisfied and therefore didn't post a patch. ;)
Cheers,
Daniel
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Tue, 8 Apr 2014 15:33:57 +0200
Quoted 3 lines
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]
I don't think you need a new list interface.
Instead, just have a back pointer to the sctp_sk() from the asoc, then you can do normal list traversals over the asocs.
Quoted 11 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Tue, 8 Apr 2014 15:33:57 +0200Quoted 3 lines
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]I don't think you need a new list interface.
Instead, just have a back pointer to the
sctp_sk()from the asoc, then you can do normal list traversals over the asocs.
We already have that, but doing so will give preference to first association and possibly starving the last one.
This starvation avoidance is the whole point of having a per-association accounting.
-vlad
David Miller
maintainerFrom: Vlad Yasevich <[email protected]>
Date: Tue, 08 Apr 2014 13:13:46 -0400
Quoted 10 lines · David Miller
Quoted 9 lines
From: Daniel Borkmann <[email protected]>
Date: Tue, 8 Apr 2014 15:33:57 +0200Quoted 3 lines
[ When net-next opens up again, we need to think how
we can ideally make a new list interface and simplify both open-coded list traversals. ]I don't think you need a new list interface.
Quoted 8 lines
Quoted 2 lines
Instead, just have a back pointer to the
sctp_sk()from the asoc, then you can do normal list traversals over the asocs.We already have that, but doing so will give preference to first association and possibly starving the last one.
This starvation avoidance is the whole point of having a per-association accounting.
I see, thanks for explaining.