net: xsk: add two sysctl knobs
Subsystems (4)
cover net: xsk: add two sysctl knobs
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Jason Xing (2):
net: xsk: make MAX_PER_SOCKET_BUDGET tunable
net: xsk: make xsk_tx_batch_size tunable
include/net/hotdata.h | 2 ++ net/core/hotdata.c | 4 +++- net/core/sysctl_net_core.c | 15 +++++++++++++++ net/xdp/xsk.c | 10 +++++----- 4 files changed, 25 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.5
PATCH 1/2 net: xsk: make MAX_PER_SOCKET_BUDGET tunable
From: Jason Xing <[email protected]>
Make MAX_PER_SOCKET_BUDGET tunable and let users decide how many descs they expect to peek at one time.
--- include/net/hotdata.h | 1 + net/core/hotdata.c | 3 ++- net/core/sysctl_net_core.c | 7 +++++++ net/xdp/xsk.c | 6 ++++-- 4 files changed, 14 insertions(+), 3 deletions(-)
include/net/hotdata.h +1 -0
@@ -40,6 +40,7 @@ struct net_hotdata {int sysctl_max_skb_frags;int sysctl_skb_defer_max;int sysctl_mem_pcpu_rsv; +int sysctl_xsk_max_per_socket_budget; };#define inet_ehash_secret net_hotdata.tcp_protocol.secret
net/core/hotdata.c +2 -1
@@ -19,6 +19,7 @@ struct net_hotdata net_hotdata __cacheline_aligned = { .dev_rx_weight = 64, .sysctl_max_skb_frags = MAX_SKB_FRAGS, .sysctl_skb_defer_max = 64, - .sysctl_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE + .sysctl_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE, + .sysctl_xsk_max_per_socket_budget = 32 };EXPORT_SYMBOL (net_hotdata);
net/core/sysctl_net_core.c +7 -0
@@ -640,6 +640,13 @@ static struct ctl_table net_core_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, + { + .procname = "xsk_max_per_socket_budget", + .data = &net_hotdata.sysctl_xsk_max_per_socket_budget, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, }; static struct ctl_table netns_core_table[] = {
net/xdp/xsk.c +4 -2
@@ -28,13 +28,13 @@#include <net/netdev_lock.h> #include <net/netdev_rx_queue.h> #include <net/xdp.h> +#include <net/hotdata.h> #include "xsk_queue.h" #include "xdp_umem.h" #include "xsk.h" #define TX_BATCH_SIZE 32 -#define MAX_PER_SOCKET_BUDGET (TX_BATCH_SIZE)void xsk_set_rx_need_wakeup (struct xsk_buff_pool *pool) {
@@ -424,7 +424,9 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)rcu_read_lock (); again:list_for_each_entry_rcu (xs, &pool->xsk_tx_list, tx_list) { -if (xs->tx_budget_spent >=MAX_PER_SOCKET_BUDGET ) { +int max_budget =READ_ONCE (net_hotdata.sysctl_xsk_max_per_socket_budget); + +if (xs->tx_budget_spent >= max_budget) { budget_exhausted = true;continue ; }
Signature · 1 line
2.43.5
PATCH 2/2 net: xsk: make xsk_tx_batch_size tunable
In reply to Jason XingFrom: Jason Xing <[email protected]>
In some cases, users probably expect to see xsk_generic_xmit() can handle more desc at one time. Make it tunable and it would be similar with how dev_tx_weight works in xsk path.
--- include/net/hotdata.h | 1 + net/core/hotdata.c | 3 ++- net/core/sysctl_net_core.c | 8 ++++++++ net/xdp/xsk.c | 4 +--- 4 files changed, 12 insertions(+), 4 deletions(-)
include/net/hotdata.h +1 -0
@@ -41,6 +41,7 @@ struct net_hotdata {int sysctl_skb_defer_max;int sysctl_mem_pcpu_rsv;int sysctl_xsk_max_per_socket_budget; +int sysctl_xsk_tx_batch_size; };#define inet_ehash_secret net_hotdata.tcp_protocol.secret
net/core/hotdata.c +2 -1
@@ -20,6 +20,7 @@ struct net_hotdata net_hotdata __cacheline_aligned = { .sysctl_max_skb_frags = MAX_SKB_FRAGS, .sysctl_skb_defer_max = 64, .sysctl_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE, - .sysctl_xsk_max_per_socket_budget = 32 + .sysctl_xsk_max_per_socket_budget = 32, + .sysctl_xsk_tx_batch_size = 32 };EXPORT_SYMBOL (net_hotdata);
net/core/sysctl_net_core.c +8 -0
@@ -647,6 +647,14 @@ static struct ctl_table net_core_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xsk_tx_batch_size", + .data = &net_hotdata.sysctl_xsk_tx_batch_size, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, + }; static struct ctl_table netns_core_table[] = {
net/xdp/xsk.c +1 -3
@@ -34,8 +34,6 @@#include "xdp_umem.h" #include "xsk.h" -#define TX_BATCH_SIZE 32 -void xsk_set_rx_need_wakeup (struct xsk_buff_pool *pool) {if (pool->cached_need_wakeup &XDP_WAKEUP_RX )
@@ -780,8 +778,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,static int __xsk_generic_xmit (struct sock *sk) { +u32 max_batch =READ_ONCE (net_hotdata.sysctl_xsk_tx_batch_size);struct xdp_sock *xs =xdp_sk (sk); -u32 max_batch =TX_BATCH_SIZE ;bool sent_frame = false;struct xdp_desc desc;struct sk_buff *skb;
Signature · 1 line
2.43.5
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
Also, can we put these settings into the socket instead of (global/ns) sysctl?
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
Quoted 3 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
As to MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.
Thanks,
Jason
Quoted 25 lines · Jason Xing
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
As to
MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.
I'm suggesting something along these lines (see below). And then add some way to configure it (plus, obviously, set the default value on init). There is also a question on whether you need separate values for MAX_PER_SOCKET_BUDGET and TX_BATCH_SIZE, and if yes, then why.
net/xdp/xsk.c +2 -3
@@ -424,7 +424,7 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)rcu_read_lock (); again:list_for_each_entry_rcu (xs, &pool->xsk_tx_list, tx_list) { -if (xs->tx_budget_spent >=MAX_PER_SOCKET_BUDGET ) { +if (xs->tx_budget_spent >= xs->max_tx_budget) { budget_exhausted = true;continue ; }
@@ -779,7 +779,6 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,static int __xsk_generic_xmit (struct sock *sk) {struct xdp_sock *xs =xdp_sk (sk); -u32 max_batch =TX_BATCH_SIZE ;bool sent_frame = false;struct xdp_desc desc;struct sk_buff *skb;
@@ -797,7 +796,7 @@ static int __xsk_generic_xmit(struct sock *sk) goto out;while (xskq_cons_peek_desc (xs->tx, &desc, xs->pool)) { -if (max_batch-- ==0 ) { +if (xs->max_tx_budget-- ==0 ) { err = -EAGAIN ; goto out; }
Quoted 6 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
Quoted 3 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
Quoted 6 lines
Quoted 2 lines
As to
MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.I'm suggesting something along these lines (see below). And then add some way to configure it (plus, obviously, set the default value on init).
+1 from me on making this per-socket instead of global with sysfs.
I feel like the direction networking has taken lately (netdev-genl, for example) is to make things more granular instead of global.
Quoted 11 lines · Joe Damato
Quoted 9 lines · Stanislav Fomichev
Quoted 6 lines · Jason Xing
Quoted 3 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
As to
MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.
Quoted 8 lines
Quoted 3 lines
I'm suggesting something along these lines (see below). And then add some way to configure it (plus, obviously, set the default value on init).
+1 from me on making this per-socket instead of global with sysfs.
I feel like the direction networking has taken lately (netdev-genl, for example) is to make things more granular instead of global.
Agree. Previously I missed using sock_net(sk)->core->xxx to make it namespecified :(
Thanks,
Jason
Quoted 27 lines · Stanislav Fomichev
Quoted 25 lines · Jason Xing
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
As to
MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.
To add to that, after digging into this part, I realized that we're able to use sock_net(sk)->core.max_tx_budget directly to finish the namespace stuff because xsk_create() calls sk_alloc() which correlates its netns in the sk->sk_net. Sounds reasonable?
Quoted 5 lines
I'm suggesting something along these lines (see below). And then add some way to configure it (plus, obviously, set the default value on init). There is also a question on whether you need separate values for
MAX_PER_SOCKET_BUDGETandTX_BATCH_SIZE, and if yes,
For now, actually I don't see a specific reason to separate them, so let me use a single one in V2. My use case only expects to see the TX_BATCH_SIZE adjustment.
net/xdp/xsk.c bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) · line 427
Quoted 12 lines
then why.
net/xdp/xsk.c +1
-1@@ -424,7 +424,7 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)rcu_read_lock (); again:list_for_each_entry_rcu (xs, &pool->xsk_tx_list, tx_list) { -if (xs->tx_budget_spent >=MAX_PER_SOCKET_BUDGET ) { +if (xs->tx_budget_spent >= xs->max_tx_budget) {
If we implement it like this, xs->max_tx_budget has to read a per-netns from somewhere and then initialize it. The core problem still remains: where to store the per netns value.
Do you think using the aforementioned sock_net(sk)->core.max_tx_budget is possible?
Thanks,
Jason
Quoted 20 lines
net/xdp/xsk.c +1
-2budget_exhausted = true;continue ; }@@ -779,7 +779,6 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,static int __xsk_generic_xmit (struct sock *sk) {struct xdp_sock *xs =xdp_sk (sk); -u32 max_batch =TX_BATCH_SIZE ;bool sent_frame = false;struct xdp_desc desc;struct sk_buff *skb;@@ -797,7 +796,7 @@ static int __xsk_generic_xmit(struct sock *sk) goto out;while (xskq_cons_peek_desc (xs->tx, &desc, xs->pool)) { -if (max_batch-- ==0 ) { +if (xs->max_tx_budget-- ==0 ) { err = -EAGAIN ; goto out; }
Quoted 32 lines · Jason Xing
Quoted 30 lines · Stanislav Fomichev
Quoted 28 lines · Jason Xing
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
Quoted 3 lines
Also, can we put these settings into the socket instead of (global/ns) sysctl?
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
As to
MAX_PER_SOCKET_BUDGET, it seems not easy to get its corresponding netns? I have no strong opinion on this point for now.To add to that, after digging into this part, I realized that we're able to use sock_net(sk)->core.max_tx_budget directly to finish the namespace stuff because
xsk_create()callssk_alloc()which correlates its netns in thesk->sk_net. Sounds reasonable?
Updated patch here:
https://lore.kernel.org/all/[email protected]/
Please review :0
Thanks,
Jason
Quoted 54 lines
Quoted 6 lines
I'm suggesting something along these lines (see below). And then add some way to configure it (plus, obviously, set the default value on init). There is also a question on whether you need separate values for
MAX_PER_SOCKET_BUDGETandTX_BATCH_SIZE, and if yes,For now, actually I don't see a specific reason to separate them, so let me use a single one in V2. My use case only expects to see the
TX_BATCH_SIZEadjustment.net/xdp/xsk.c bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) · line 427
Quoted 12 lines
then why.
net/xdp/xsk.c +1
-1@@ -424,7 +424,7 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)rcu_read_lock (); again:list_for_each_entry_rcu (xs, &pool->xsk_tx_list, tx_list) { -if (xs->tx_budget_spent >=MAX_PER_SOCKET_BUDGET ) { +if (xs->tx_budget_spent >= xs->max_tx_budget) {If we implement it like this,
xs->max_tx_budgethas to read a per-netns from somewhere and then initialize it. The core problem still remains: where to store the per netns value.Do you think using the aforementioned sock_net(sk)->core.max_tx_budget is possible?
Thanks,
JasonQuoted 20 lines
net/xdp/xsk.c +1
-2budget_exhausted = true;continue ; }@@ -779,7 +779,6 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,static int __xsk_generic_xmit (struct sock *sk) {struct xdp_sock *xs =xdp_sk (sk); -u32 max_batch =TX_BATCH_SIZE ;bool sent_frame = false;struct xdp_desc desc;struct sk_buff *skb;@@ -797,7 +796,7 @@ static int __xsk_generic_xmit(struct sock *sk) goto out;while (xskq_cons_peek_desc (xs->tx, &desc, xs->pool)) { -if (max_batch-- ==0 ) { +if (xs->max_tx_budget-- ==0 ) { err = -EAGAIN ; goto out; }
Quoted 12 lines · Jason Xing
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
Quoted 11 lines
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
It would be informative to include this in the commit.
Or more broadly: suggestions for when and how to pick good settings for these new tunables.
Quoted 26 lines · Willem de Bruijn
Quoted 12 lines · Jason Xing
Hi Stanislav,
Quoted 8 lines · Stanislav Fomichev
Quoted 4 lines · Jason Xing
From: Jason Xing <[email protected]>
Introduce a control method in the xsk path to let users have the chance to tune it manually.
Can you expand more on why the defaults don't work for you?
Quoted 11 lines
We use a user-level tcp stack with xsk to transmit packets that have higher priorities than other normal kernel tcp flows. It turns out that enlarging the number can minimize times of triggering sendto sysctl, which contributes to faster transmission. it's very easy to hit the upper bound (namely, 32) if you log the return value of sendto. I mentioned a bit about this in the second patch, saying that we can have a similar knob already appearing in the qdisc layer. Furthermore, exposing important parameters can help applications complete their AI/auto-tuning to judge which one is the best fit in their production workload. That is also one of the promising tendencies :)
Quoted 1 line
It would be informative to include this in the commit.
Sure, I will add more in V3.
Quoted 3 lines
Or more broadly: suggestions for when and how to pick good settings for these new tunables.
I'm not sure what is a good setting in general. But I will try to describe how I use it and what my understanding of it is in the commit message.
Thanks,
Jason