* [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly
@ 2024-11-04 8:35 Gilad Naaman
2024-11-07 14:38 ` Xin Long
2024-11-07 14:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Gilad Naaman @ 2024-11-04 8:35 UTC (permalink / raw)
To: Marcelo Ricardo Leitner, Xin Long, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-sctp, netdev
Cc: 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_event into a bottle-neck, as it will get slower and slower
with each address added.
Signed-off-by: Gilad Naaman <gnaaman@drivenets.com>
---
Changes in v2:
- Reorder list removal to avoid race with new sessions
---
net/sctp/ipv6.c | 2 +-
net/sctp/protocol.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index f7b809c0d142..b96c849545ae 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -103,10 +103,10 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
ipv6_addr_equal(&addr->a.v6.sin6_addr,
&ifa->addr) &&
addr->a.v6.sin6_scope_id == ifa->idev->dev->ifindex) {
- sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
found = 1;
addr->valid = 0;
list_del_rcu(&addr->list);
+ sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
break;
}
}
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 39ca5403d4d7..8b9a1b96695e 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -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) {
@@ -808,10 +822,10 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
if (addr->a.sa.sa_family == AF_INET &&
addr->a.v4.sin_addr.s_addr ==
ifa->ifa_local) {
- sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
found = 1;
addr->valid = 0;
list_del_rcu(&addr->list);
+ sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
break;
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly
2024-11-04 8:35 [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly Gilad Naaman
@ 2024-11-07 14:38 ` Xin Long
2024-11-07 14:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Xin Long @ 2024-11-07 14:38 UTC (permalink / raw)
To: Gilad Naaman
Cc: Marcelo Ricardo Leitner, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-sctp, netdev
On Mon, Nov 4, 2024 at 3:36 AM Gilad Naaman <gnaaman@drivenets.com> wrote:
>
>
> 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.
>
> Signed-off-by: Gilad Naaman <gnaaman@drivenets.com>
Acked-by: Xin Long <lucien.xin@gmail.com>
Thanks.
> ---
> Changes in v2:
> - Reorder list removal to avoid race with new sessions
> ---
> net/sctp/ipv6.c | 2 +-
> net/sctp/protocol.c | 16 +++++++++++++++-
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
> index f7b809c0d142..b96c849545ae 100644
> --- a/net/sctp/ipv6.c
> +++ b/net/sctp/ipv6.c
> @@ -103,10 +103,10 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
> ipv6_addr_equal(&addr->a.v6.sin6_addr,
> &ifa->addr) &&
> addr->a.v6.sin6_scope_id == ifa->idev->dev->ifindex) {
> - sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
> found = 1;
> addr->valid = 0;
> list_del_rcu(&addr->list);
> + sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
> break;
> }
> }
> diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
> index 39ca5403d4d7..8b9a1b96695e 100644
> --- a/net/sctp/protocol.c
> +++ b/net/sctp/protocol.c
> @@ -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) {
> @@ -808,10 +822,10 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
> if (addr->a.sa.sa_family == AF_INET &&
> addr->a.v4.sin_addr.s_addr ==
> ifa->ifa_local) {
> - sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
> found = 1;
> addr->valid = 0;
> list_del_rcu(&addr->list);
> + sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
> break;
> }
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly
2024-11-04 8:35 [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly Gilad Naaman
2024-11-07 14:38 ` Xin Long
@ 2024-11-07 14:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-07 14:50 UTC (permalink / raw)
To: Gilad Naaman
Cc: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni, horms,
linux-sctp, netdev
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 4 Nov 2024 08:35:44 +0000 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [net-next,v2] sctp: Avoid enqueuing addr events redundantly
https://git.kernel.org/netdev/net-next/c/702c290a1cb1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-07 14:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04 8:35 [PATCH net-next v2] sctp: Avoid enqueuing addr events redundantly Gilad Naaman
2024-11-07 14:38 ` Xin Long
2024-11-07 14:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).