sctp: Avoid enqueuing addr events redundantly
Subsystems (3)
PATCH 1/1 sctp: Avoid enqueuing addr events redundantly
Avoid modifying or enqueuing new events if it's possible to tell that no one will consume them.
Since enqueueing requires searching the current queue for opposite events for the same address, adding addresses en-masse turns this inetaddr_event into a bottle-neck, as it will get slower and slower with each address added.
--- net/sctp/protocol.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/sctp/protocol.c +14 -0
@@ -738,6 +738,20 @@ void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm*/ spin_lock_bh (&net->sctp.addr_wq_lock); + +/* Avoid searching the queue or modifying it if there are no consumers, +* as it can lead to performance degradation if addresses are modified +* en-masse. +* +* If the queue already contains some events, update it anyway to avoid +* ugly races between new sessions and new address events. +*/ +if (list_empty (&net->sctp.auto_asconf_splist) && +list_empty (&net->sctp.addr_waitq)) { +spin_unlock_bh (&net->sctp.addr_wq_lock); +return ; + } +/* Offsets existing events in addr_wq */ addrw =sctp_addr_wq_lookup (net, addr);if (addrw) {
Signature · 1 line
2.46.0
Xin Long
maintainerQuoted 24 lines · Gilad Naaman
Avoid modifying or enqueuing new events if it's possible to tell that no one will consume them.
Since enqueueing requires searching the current queue for opposite events for the same address, adding addresses en-masse turns this
inetaddr_eventinto a bottle-neck, as it will get slower and slower with each address added.Signed-off-by Gilad Naaman <[email protected]>--- net/sctp/protocol.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)net/sctp/protocol.c +2
-0@@ -738,6 +738,20 @@ void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm*/ spin_lock_bh (&net->sctp.addr_wq_lock); + +/* Avoid searching the queue or modifying it if there are no consumers,
net/sctp/protocol.c void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm · line 752
Quoted 10 lines
net/sctp/protocol.c +10
-0+* as it can lead to performance degradation if addresses are modified +* en-masse. +* +* If the queue already contains some events, update it anyway to avoid +* ugly races between new sessions and new address events. +*/ +if (list_empty (&net->sctp.auto_asconf_splist) && +list_empty (&net->sctp.addr_waitq)) { +spin_unlock_bh (&net->sctp.addr_wq_lock); +return ;
What if after this but before the addr is deleted from local_addr_list in sctp_inetaddr_event(), a new SCTP association is created with these addrs in local_addr_list, will it miss this asconf addr_del?
Thanks.
Quoted 8 lines
net/sctp/protocol.c +2
-1+ } +/* Offsets existing events in addr_wq */ addrw =sctp_addr_wq_lookup (net, addr);if (addrw) { --2.46.0
Quoted 47 lines · Xin Long
CAUTION: External E-Mail - Use caution with links and attachments
Quoted 24 lines · Gilad Naaman
Avoid modifying or enqueuing new events if it's possible to tell that no one will consume them.
Since enqueueing requires searching the current queue for opposite events for the same address, adding addresses en-masse turns this
inetaddr_eventinto a bottle-neck, as it will get slower and slower with each address added.Signed-off-by Gilad Naaman <[email protected]>---
net/sctp/protocol.c| 14 ++++++++++++++1 file changed, 14 insertions(+)net/sctp/protocol.c +2
-0@@ -738,6 +738,20 @@ void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm*/ spin_lock_bh (&net->sctp.addr_wq_lock); + +/* Avoid searching the queue or modifying it if there are no consumers, net/sctp/protocol.c void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm · line 752
Quoted 10 lines
net/sctp/protocol.c +10
-0+* as it can lead to performance degradation if addresses are modified +* en-masse. +* +* If the queue already contains some events, update it anyway to avoid +* ugly races between new sessions and new address events. +*/ +if (list_empty (&net->sctp.auto_asconf_splist) && +list_empty (&net->sctp.addr_waitq)) { +spin_unlock_bh (&net->sctp.addr_wq_lock); +return ;What if after this but before the addr is deleted from
local_addr_listinsctp_inetaddr_event(), a new SCTP association is created with these addrs inlocal_addr_list, will it miss this asconfaddr_del?
Quoted 1 line
Thanks.
Great point.
I think this can be solved by making sure list_del_rcu(&addr->list); is called before sctp_addr_wq_mgmt.
I’ll resend this after I manage to un-bork my git-send-email config.
Thank you!
Quoted 9 lines
Quoted 9 lines
net/sctp/protocol.c +2
-1+ } +/* Offsets existing events in addr_wq */ addrw =sctp_addr_wq_lookup (net, addr);if (addrw) { --2.46.0