net/smc: Unbind buffer size from clcsock and make it tunable
Subsystems (6)
Tony Lu
reviewerRFC PATCH 1/1 net/smc: Unbind buffer size from clcsock and make it tunable
SMC uses smc->sk.sk_{rcv|snd}buf to create buffer for send buffer or RMB. And the values of buffer size inherits from clcsock. The clcsock is a TCP sock which is initiated during SMC connection startup.
The inherited buffer size doesn't fit SMC well. TCP provides two sysctl knobs to tune r/w buffers, net.ipv4.tcp_{r|w}mem, and SMC use the default value from TCP. The buffer size is tuned for TCP, but not fit SMC well in some scenarios. For example, we need larger buffer of SMC for high throughput applications, and smaller buffer of SMC for saving contiguous memory. We need to adjust the buffer size apart from TCP and not to disturb TCP.
This unbinds buffer size which inherits from clcsock, and provides sysctl knobs to adjust buffer size independently. These knobs can be tuned with different values for different net namespaces for performance and flexibility.
--- Documentation/networking/smc-sysctl.rst | 20 ++++++ include/net/netns/smc.h | 5 ++ net/smc/Makefile | 2 +- net/smc/af_smc.c | 17 +++++- net/smc/smc_sysctl.c | 81 +++++++++++++++++++++++++ net/smc/smc_sysctl.h | 22 +++++++ 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 Documentation/networking/smc-sysctl.rst create mode 100644 net/smc/smc_sysctl.c create mode 100644 net/smc/smc_sysctl.h
Documentation/networking/smc-sysctl.rst new file +20 -0
@@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========= +SMC Sysctl +========= + +/proc/sys/net/smc/* Variables +============================== + +wmem_default - INTEGER + Initial size of send buffer used by SMC sockets. + The default value inherits from net.ipv4.tcp_wmem[1]. + + Default: 16K + +rmem_default - INTEGER + Initial size of receive buffer (RMB) used by SMC sockets. + The default value inherits from net.ipv4.tcp_rmem[1]. + + Default: 131072 bytes.
include/net/netns/smc.h +5 -0
@@ -12,5 +12,10 @@ struct netns_smc {/* protect fback_rsn */ struct mutex mutex_fback_rsn;struct smc_stats_rsn *fback_rsn; +#ifdef CONFIG_SYSCTL +struct ctl_table_header *smc_hdr; +#endif +int sysctl_wmem_default; + int sysctl_rmem_default; };#endif
net/smc/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_SMC) += smc.o obj-$(CONFIG_SMC_DIAG) += smc_diag.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o -smc-y += smc_tracepoint.o +smc-y += smc_tracepoint.o smc_sysctl.o
net/smc/af_smc.c +15 -2
@@ -51,6 +51,7 @@#include "smc_close.h" #include "smc_stats.h" #include "smc_tracepoint.h" +#include "smc_sysctl.h" static DEFINE_MUTEX (smc_server_lgr_pending);/* serialize link group * creation on server
@@ -2722,8 +2723,8 @@ static int smc_create(struct net *net, struct socket *sock, int protocol,sk_common_release (sk); goto out; } - smc->sk.sk_sndbuf =max (smc->clcsock->sk->sk_sndbuf,SMC_BUF_MIN_SIZE ); - smc->sk.sk_rcvbuf =max (smc->clcsock->sk->sk_rcvbuf,SMC_BUF_MIN_SIZE ); + smc->sk.sk_sndbuf =sock_net (sk)->smc.sysctl_wmem_default; + smc->sk.sk_rcvbuf =sock_net (sk)->smc.sysctl_rmem_default; out:return rc;
@@ -2739,6 +2740,11 @@ unsigned int smc_net_id;static __net_init int smc_net_init (struct net *net) { + net->smc.sysctl_wmem_default =max (net->ipv4.sysctl_tcp_wmem[1 ], +SMC_BUF_MIN_SIZE ); + net->smc.sysctl_rmem_default =max (net->ipv4.sysctl_tcp_rmem[1 ], +SMC_BUF_MIN_SIZE ); +return smc_pnet_net_init (net); }
@@ -2845,6 +2851,12 @@ static int __init smc_init(void) goto out_sock; } + rc =smc_sysctl_init (); +if (rc) { +pr_err ("%s: sysctl fails with %d\n" , __func__, rc); + goto out_sock; + } +static_branch_enable (&tcp_have_smc);return 0 ;
@@ -2885,6 +2897,7 @@ static void __exit smc_exit(void)smc_clc_exit ();unregister_pernet_subsys (&smc_net_stat_ops);unregister_pernet_subsys (&smc_net_ops); +smc_sysctl_exit ();rcu_barrier (); }
net/smc/smc_sysctl.c new file +81 -0
81 lines not on this page · raw message
net/smc/smc_sysctl.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _SMC_SYSCTL_H +#define _SMC_SYSCTL_H + +#ifdef CONFIG_SYSCTL + +int smc_sysctl_init (void ); +void smc_sysctl_exit (void ); + +#else + +int smc_sysctl_init (void ) +{ +return 0 ; +} + +void smc_sysctl_exit (void ) { } + +#endif /* CONFIG_SYSCTL */ + +#endif /* _SMC_SYSCTL_H */
Signature · 1 line
2.32.0.3.g01195cf9f
Quoted 12 lines · Tony Lu
SMC uses smc->sk.sk_{rcv|snd}buf to create buffer for send buffer or RMB. And the values of buffer size inherits from clcsock. The clcsock is a TCP sock which is initiated during SMC connection startup.
The inherited buffer size doesn't fit SMC well. TCP provides two sysctl knobs to tune r/w buffers, net.ipv4.tcp_{r|w}mem, and SMC use the default value from TCP. The buffer size is tuned for TCP, but not fit SMC well in some scenarios. For example, we need larger buffer of SMC for high throughput applications, and smaller buffer of SMC for saving contiguous memory. We need to adjust the buffer size apart from TCP and not to disturb TCP.
Quoted 8 lines
This unbinds buffer size which inherits from clcsock, and provides sysctl knobs to adjust buffer size independently. These knobs can be tuned with different values for different net namespaces for performance and flexibility.
Signed-off-by Tony Lu <[email protected]>Reviewed-by Wen Gu <[email protected]>---
To activate SMC for existing programs usually the smc_run command or the preload library (both from the smc-tools package) are used. This commit introduced support to set the send and recv window sizes using command line parameters or environment variables:
https://github.com/ibm-s390-linux/smc-tools/commit/59bfb99c588746f7dca1b3c97fd88f3f7cbc975f
Why another way to manipulate these sizes?
Your solution would stop applications to set these values.
Tony Lu
reviewerQuoted 22 lines · Karsten Graul
Quoted 12 lines · Tony Lu
SMC uses smc->sk.sk_{rcv|snd}buf to create buffer for send buffer or RMB. And the values of buffer size inherits from clcsock. The clcsock is a TCP sock which is initiated during SMC connection startup.
The inherited buffer size doesn't fit SMC well. TCP provides two sysctl knobs to tune r/w buffers, net.ipv4.tcp_{r|w}mem, and SMC use the default value from TCP. The buffer size is tuned for TCP, but not fit SMC well in some scenarios. For example, we need larger buffer of SMC for high throughput applications, and smaller buffer of SMC for saving contiguous memory. We need to adjust the buffer size apart from TCP and not to disturb TCP.
Quoted 8 lines
This unbinds buffer size which inherits from clcsock, and provides sysctl knobs to adjust buffer size independently. These knobs can be tuned with different values for different net namespaces for performance and flexibility.
Signed-off-by Tony Lu <[email protected]>Reviewed-by Wen Gu <[email protected]>---
Quoted 6 lines
To activate SMC for existing programs usually the
smc_runcommand or the preload library (both from the smc-tools package) are used. This commit introduced support to set the send and recv window sizes using command line parameters or environment variables:https://github.com/ibm-s390-linux/smc-tools/commit/59bfb99c588746f7dca1b3c97fd88f3f7cbc975f
Hi Graul,
Thanks for your advice. We are using smc-tools, it is a very useful tool, and we also use smc_run or LD_PRELOAD to help our applications to replace with SMC from TCP.
There are some differences to use SMC in our environment. The followings are our scenarios to use SMC:
1. Transparent acceleration
This approach is widely used in our environment. The main idea of transparent acceleration is not to touch the applications. The applications are usually pre-compiled and pre-packaged containers or ECS, which means the binary and the binary needed environments, like glibc and other libraries are bundled as bootstrap containers. So it is hard to inject the smc_run or LD_PRELOAD into application's containers runtime.
To solve this issue, we developed a set of patches to replace the AF_INET / SOCK_STREAM with AF_SMC / SMCPROTO_SMC{6} by configuration. So that we can control acceleration in kernel without any other changes in user-space, and won't break our application containers and publish workflow. These patches are still improving for upstream.
2. Use SMC explicitly
This approach is very straightforward. Applications just create sockets using AF_SMC and SMCPROTO_SMC{6}, and SMC works fine.
However, most of applications don't want to bind tightly to single SMC protocol. Most of them take into account compatibility, stability and flexibility.
Quoted 2 lines
Why another way to manipulate these sizes?
Your solution would stop applications to set these values.
I didn't understand it clearly about stopping applications to set there values.
IMHO, this RFC introduces two knobs for snd/rcvbuf. During the following stages, applications can set these values as expected.
1. SMC module or per-net-namespace initialized:
sysctl_{w|r}mem_default initialized in smc_net_init() when current net namespace initialized. The default values of SMC inherit from TCP, and clcsock use TCP's configures.
2. create SMC socket:
smc_create() is called, and smc->sk.sk_{snd|rcv}buf are initialized from per-netns earlier. There are no different from before. Except for changing the values of TCP after SMC initialized, users can change them with newly added two knobs.
3. applications call setsockopt() to modify SO_SNDBUF or SO_RCVBUF:
After smc_create() creates socket, applications can use setsockopt() to change the snd/rcvbuf, which called sock_setsockopt() directly. If fallback happened, setsockopt() would change clcsock's values.
In the end, we hope to provide a flexibility approach to change SMC's buffer size only and don't disturb others. Sysctl are considered as a better way to maintain and easy to use for users.
Thanks,
Tony Lu
Quoted 5 lines · Tony Lu
To solve this issue, we developed a set of patches to replace the
AF_INET/SOCK_STREAMwithAF_SMC/ SMCPROTO_SMC{6} by configuration. So that we can control acceleration in kernel without any other changes in user-space, and won't break our application containers and publish workflow. These patches are still improving for upstream.
This sounds interesting. Will this also be namespace-based like the sysctls in the current patch? Will this future change integrate nicely with the current new sysctls? This might allow to activate smc for containers, selectively.
Please send these changes in a patch series together when they are finished. We would like to review them as a whole to see how things play together.
Thank you!
Tony Lu
reviewerQuoted 7 lines · Karsten Graul
Quoted 5 lines · Tony Lu
To solve this issue, we developed a set of patches to replace the
AF_INET/SOCK_STREAMwithAF_SMC/ SMCPROTO_SMC{6} by configuration. So that we can control acceleration in kernel without any other changes in user-space, and won't break our application containers and publish workflow. These patches are still improving for upstream.
Quoted 8 lines
This sounds interesting. Will this also be namespace-based like the sysctls in the current patch? Will this future change integrate nicely with the current new sysctls? This might allow to activate smc for containers, selectively.
Please send these changes in a patch series together when they are finished. We would like to review them as a whole to see how things play together.
Thank you!
Hi Graul,
I am glad to hear that. The container, which is isolated by net-namespace, is the minimal deployment unit in our environment. The transparent replacement facility is namespace-based, so that we can control the applications behaviors according to the dimensions of containers.
The per-netns sysctl is the first step, control the applications' buffer, and not to disturb TCP connections in the same container. The container's memory is not as large as that of a physical machine, and containers might run different workload applications, so we use per-netns sysctl to adjust buffer. And it can be sent out separately.
Then, we can allow to activate SMC for some containers with transparent replacement. These patches are improving, make sure the flexible enough for containers and applications scopes, and cohesion enough for upstream.
I will send them out as the containers solutions. Thank for you advice.
Thanks,
Tony Lu
kernel test robot
build botreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross #…
Hi Tony,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tony-Lu/net-smc-Unbind-buffer-size-from-clcsock-and-make-it-tunable/20211122-215118 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 89f971182417cb27abd82cfc48a7f36b99352ddc config: parisc-randconfig-r035-20211122 (attached as .config) compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f8b865aff3164098137794ac439371b2391c836b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tony-Lu/net-smc-Unbind-buffer-size-from-clcsock-and-make-it-tunable/20211122-215118 git checkout f8b865aff3164098137794ac439371b2391c836b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> net/smc/smc_sysctl.c:73:12: warning: no previous prototype for 'smc_sysctl_init' [-Wmissing-prototypes]
73 | int __init smc_sysctl_init(void)
| ^~~~~~~~~~~~~~~
>> net/smc/smc_sysctl.c:78:6: warning: no previous prototype for 'smc_sysctl_exit' [-Wmissing-prototypes] 78 | void smc_sysctl_exit(void)
| ^~~~~~~~~~~~~~~
vim +/smc_sysctl_init +73 net/smc/smc_sysctl.c
72
> 73 int __init smc_sysctl_init(void)
74 {
75 return register_pernet_subsys(&smc_sysctl_ops);
76 }
77
> 78 void smc_sysctl_exit(void)---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross #…
Hi Tony,
[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tony-Lu/net-smc-Unbind-buffer-size-from-clcsock-and-make-it-tunable/20211122-215118 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 89f971182417cb27abd82cfc48a7f36b99352ddc config: mips-randconfig-r032-20211122 (attached as .config) compiler: mips64el-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f8b865aff3164098137794ac439371b2391c836b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tony-Lu/net-smc-Unbind-buffer-size-from-clcsock-and-make-it-tunable/20211122-215118 git checkout f8b865aff3164098137794ac439371b2391c836b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash net/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
net/smc/smc_sysctl.c: In function 'smc_sysctl_init_net':
>> net/smc/smc_sysctl.c:50:17: error: 'struct netns_smc' has no member named 'smc_hdr'
50 | net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
| ^
net/smc/smc_sysctl.c:51:22: error: 'struct netns_smc' has no member named 'smc_hdr'
51 | if (!net->smc.smc_hdr)
| ^
net/smc/smc_sysctl.c: In function 'smc_sysctl_exit_net':
net/smc/smc_sysctl.c:65:45: error: 'struct netns_smc' has no member named 'smc_hdr'
65 | unregister_net_sysctl_table(net->smc.smc_hdr);
| ^ net/smc/smc_sysctl.c: At top level:
net/smc/smc_sysctl.c:73:12: warning: no previous prototype for 'smc_sysctl_init' [-Wmissing-prototypes]
73 | int __init smc_sysctl_init(void)
| ^~~~~~~~~~~~~~~
net/smc/smc_sysctl.c:78:6: warning: no previous prototype for 'smc_sysctl_exit' [-Wmissing-prototypes]
78 | void smc_sysctl_exit(void)
| ^~~~~~~~~~~~~~~
--
In file included from net/smc/af_smc.c:54:
>> net/smc/smc_sysctl.h:13:5: warning: no previous prototype for 'smc_sysctl_init' [-Wmissing-prototypes]
13 | int smc_sysctl_init(void)
| ^~~~~~~~~~~~~~~
>> net/smc/smc_sysctl.h:18:6: warning: no previous prototype for 'smc_sysctl_exit' [-Wmissing-prototypes]
18 | void smc_sysctl_exit(void) { }
| ^~~~~~~~~~~~~~~vim +50 net/smc/smc_sysctl.c
33
34 static __net_init int smc_sysctl_init_net(struct net *net)
35 {
36 struct ctl_table *table;
37
38 table = smc_table;
39 if (!net_eq(net, &init_net)) {
40 int i;
41
42 table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
43 if (!table)
44 goto err_alloc;
45
46 for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
47 table[i].data += (void *)net - (void *)&init_net;
48 }
49
> 50 net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
51 if (!net->smc.smc_hdr)
52 goto err_reg;
53
54 return 0;
55
56 err_reg:
57 if (!net_eq(net, &init_net))
58 kfree(table);
59 err_alloc:
60 return -ENOMEM;
61 }
62 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org