Re: [PATCH 1/2] udp: Move the udp sysctl to namespace.

2018-03-13 Thread Tonghao Zhang
On Tue, Mar 13, 2018 at 7:36 PM, Paolo Abeni  wrote:
> Hi,
>
> On Tue, 2018-03-13 at 02:57 -0700, Tonghao Zhang wrote:
>> This patch moves the udp_rmem_min, udp_wmem_min
>> to namespace and init the udp_l3mdev_accept explicitly.
>
> Can you please be a little more descriptive on why this is
> needed/helpful?
Thanks for your reply. In our machine, there are many dockers. The different
dockers may run the different services which require rx queue.

All the dockers in a machine share the .sysctl_mem, so we can mov the
udp_wmem_min/udp_rmem_min, which affect rx queue,  to namespace,
then docker can set it differently.

>> Signed-off-by: Tonghao Zhang 
>> ---
>>  include/net/netns/ipv4.h   |  3 ++
>>  net/ipv4/sysctl_net_ipv4.c | 32 -
>>  net/ipv4/udp.c | 86 
>> +++---
>>  net/ipv6/udp.c | 52 ++--
>>  4 files changed, 96 insertions(+), 77 deletions(-)
>>
>> diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
>> index 3a970e4..382bfd7 100644
>> --- a/include/net/netns/ipv4.h
>> +++ b/include/net/netns/ipv4.h
>> @@ -168,6 +168,9 @@ struct netns_ipv4 {
>>   atomic_t tfo_active_disable_times;
>>   unsigned long tfo_active_disable_stamp;
>>
>> + int sysctl_udp_wmem_min;
>> + int sysctl_udp_rmem_min;
>> +
>>  #ifdef CONFIG_NET_L3_MASTER_DEV
>>   int sysctl_udp_l3mdev_accept;
>>  #endif
>> diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
>> index 011de9a..5b72d97 100644
>> --- a/net/ipv4/sysctl_net_ipv4.c
>> +++ b/net/ipv4/sysctl_net_ipv4.c
>> @@ -520,22 +520,6 @@ static int proc_fib_multipath_hash_policy(struct 
>> ctl_table *table, int write,
>>   .mode   = 0644,
>>   .proc_handler   = proc_doulongvec_minmax,
>>   },
>> - {
>> - .procname   = "udp_rmem_min",
>> - .data   = &sysctl_udp_rmem_min,
>> - .maxlen = sizeof(sysctl_udp_rmem_min),
>> - .mode   = 0644,
>> - .proc_handler   = proc_dointvec_minmax,
>> - .extra1 = &one
>> - },
>> - {
>> - .procname   = "udp_wmem_min",
>> - .data   = &sysctl_udp_wmem_min,
>> - .maxlen = sizeof(sysctl_udp_wmem_min),
>> - .mode   = 0644,
>> - .proc_handler   = proc_dointvec_minmax,
>> - .extra1 = &one
>> - },
>>   { }
>>  };
>>
>> @@ -1167,6 +1151,22 @@ static int proc_fib_multipath_hash_policy(struct 
>> ctl_table *table, int write,
>>   .proc_handler   = proc_dointvec_minmax,
>>   .extra1 = &one,
>>   },
>> + {
>> + .procname   = "udp_rmem_min",
>> + .data   = &init_net.ipv4.sysctl_udp_rmem_min,
>> + .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
>> + .mode   = 0644,
>> + .proc_handler   = proc_dointvec_minmax,
>> + .extra1 = &one
>> + },
>> + {
>> + .procname   = "udp_wmem_min",
>> + .data   = &init_net.ipv4.sysctl_udp_wmem_min,
>> + .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
>> + .mode   = 0644,
>> + .proc_handler   = proc_dointvec_minmax,
>> + .extra1 = &one
>> + },
>>   { }
>>  };
>>
>> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
>> index 3013404..7ae77f2 100644
>> --- a/net/ipv4/udp.c
>> +++ b/net/ipv4/udp.c
>> @@ -122,12 +122,6 @@
>>  long sysctl_udp_mem[3] __read_mostly;
>>  EXPORT_SYMBOL(sysctl_udp_mem);
>>
>> -int sysctl_udp_rmem_min __read_mostly;
>> -EXPORT_SYMBOL(sysctl_udp_rmem_min);
>> -
>> -int sysctl_udp_wmem_min __read_mostly;
>> -EXPORT_SYMBOL(sysctl_udp_wmem_min);
>> -
>>  atomic_long_t udp_memory_allocated;
>>  EXPORT_SYMBOL(udp_memory_allocated);
>>
>> @@ -2533,35 +2527,35 @@ int udp_abort(struct sock *sk, int err)
>>  EXPORT_SYMBOL_GPL(udp_abort);
>>
>>  struct proto udp_prot = {
>> - .name  = "UDP",
>> - .owner = THIS_MODULE,
>> - .close = udp_lib_close,
>> - .connect   = ip4_datagram_connect,
>> - .disconnect= udp_disconnect,
>> - .ioctl = udp_ioctl,
>> - .init  = udp_init_sock,
>> - .destroy   = udp_destroy_sock,
>> - .setsockopt= udp_setsockopt,
>> - .getsockopt= udp_getsockopt,
>> - .sendmsg   = udp_sendmsg,
>> - .recvmsg   = udp_recvmsg,
>> - .sendpage  = udp_sendpage,
>> - .release_cb= ip4_datagram_release_cb,
>> - .hash  = udp_lib_hash,
>> - .unhash= udp_lib_unhash,
>> - .rehash= udp_v4_rehash,
>> - .get_port  = udp_v4_get_port,
>> - .memory_allocated  = &udp_memory_allocated,
>> - .sysctl_mem   

Re: [PATCH 1/2] udp: Move the udp sysctl to namespace.

2018-03-13 Thread Paolo Abeni
Hi,

On Tue, 2018-03-13 at 02:57 -0700, Tonghao Zhang wrote:
> This patch moves the udp_rmem_min, udp_wmem_min
> to namespace and init the udp_l3mdev_accept explicitly.

Can you please be a little more descriptive on why this is
needed/helpful?

> Signed-off-by: Tonghao Zhang 
> ---
>  include/net/netns/ipv4.h   |  3 ++
>  net/ipv4/sysctl_net_ipv4.c | 32 -
>  net/ipv4/udp.c | 86 
> +++---
>  net/ipv6/udp.c | 52 ++--
>  4 files changed, 96 insertions(+), 77 deletions(-)
> 
> diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
> index 3a970e4..382bfd7 100644
> --- a/include/net/netns/ipv4.h
> +++ b/include/net/netns/ipv4.h
> @@ -168,6 +168,9 @@ struct netns_ipv4 {
>   atomic_t tfo_active_disable_times;
>   unsigned long tfo_active_disable_stamp;
>  
> + int sysctl_udp_wmem_min;
> + int sysctl_udp_rmem_min;
> +
>  #ifdef CONFIG_NET_L3_MASTER_DEV
>   int sysctl_udp_l3mdev_accept;
>  #endif
> diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
> index 011de9a..5b72d97 100644
> --- a/net/ipv4/sysctl_net_ipv4.c
> +++ b/net/ipv4/sysctl_net_ipv4.c
> @@ -520,22 +520,6 @@ static int proc_fib_multipath_hash_policy(struct 
> ctl_table *table, int write,
>   .mode   = 0644,
>   .proc_handler   = proc_doulongvec_minmax,
>   },
> - {
> - .procname   = "udp_rmem_min",
> - .data   = &sysctl_udp_rmem_min,
> - .maxlen = sizeof(sysctl_udp_rmem_min),
> - .mode   = 0644,
> - .proc_handler   = proc_dointvec_minmax,
> - .extra1 = &one
> - },
> - {
> - .procname   = "udp_wmem_min",
> - .data   = &sysctl_udp_wmem_min,
> - .maxlen = sizeof(sysctl_udp_wmem_min),
> - .mode   = 0644,
> - .proc_handler   = proc_dointvec_minmax,
> - .extra1 = &one
> - },
>   { }
>  };
>  
> @@ -1167,6 +1151,22 @@ static int proc_fib_multipath_hash_policy(struct 
> ctl_table *table, int write,
>   .proc_handler   = proc_dointvec_minmax,
>   .extra1 = &one,
>   },
> + {
> + .procname   = "udp_rmem_min",
> + .data   = &init_net.ipv4.sysctl_udp_rmem_min,
> + .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
> + .mode   = 0644,
> + .proc_handler   = proc_dointvec_minmax,
> + .extra1 = &one
> + },
> + {
> + .procname   = "udp_wmem_min",
> + .data   = &init_net.ipv4.sysctl_udp_wmem_min,
> + .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
> + .mode   = 0644,
> + .proc_handler   = proc_dointvec_minmax,
> + .extra1 = &one
> + },
>   { }
>  };
>  
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 3013404..7ae77f2 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -122,12 +122,6 @@
>  long sysctl_udp_mem[3] __read_mostly;
>  EXPORT_SYMBOL(sysctl_udp_mem);
>  
> -int sysctl_udp_rmem_min __read_mostly;
> -EXPORT_SYMBOL(sysctl_udp_rmem_min);
> -
> -int sysctl_udp_wmem_min __read_mostly;
> -EXPORT_SYMBOL(sysctl_udp_wmem_min);
> -
>  atomic_long_t udp_memory_allocated;
>  EXPORT_SYMBOL(udp_memory_allocated);
>  
> @@ -2533,35 +2527,35 @@ int udp_abort(struct sock *sk, int err)
>  EXPORT_SYMBOL_GPL(udp_abort);
>  
>  struct proto udp_prot = {
> - .name  = "UDP",
> - .owner = THIS_MODULE,
> - .close = udp_lib_close,
> - .connect   = ip4_datagram_connect,
> - .disconnect= udp_disconnect,
> - .ioctl = udp_ioctl,
> - .init  = udp_init_sock,
> - .destroy   = udp_destroy_sock,
> - .setsockopt= udp_setsockopt,
> - .getsockopt= udp_getsockopt,
> - .sendmsg   = udp_sendmsg,
> - .recvmsg   = udp_recvmsg,
> - .sendpage  = udp_sendpage,
> - .release_cb= ip4_datagram_release_cb,
> - .hash  = udp_lib_hash,
> - .unhash= udp_lib_unhash,
> - .rehash= udp_v4_rehash,
> - .get_port  = udp_v4_get_port,
> - .memory_allocated  = &udp_memory_allocated,
> - .sysctl_mem= sysctl_udp_mem,
> - .sysctl_wmem   = &sysctl_udp_wmem_min,
> - .sysctl_rmem   = &sysctl_udp_rmem_min,
> - .obj_size  = sizeof(struct udp_sock),
> - .h.udp_table   = &udp_table,
> + .name   = "UDP",
> + .owner  = THIS_MODULE,
> + .close  = udp_lib_close,
> + .connect= ip4_datagram_connect,
> + .disconnect = udp_disconnect,
> + .ioctl   

[PATCH 1/2] udp: Move the udp sysctl to namespace.

2018-03-13 Thread Tonghao Zhang
This patch moves the udp_rmem_min, udp_wmem_min
to namespace and init the udp_l3mdev_accept explicitly.

Signed-off-by: Tonghao Zhang 
---
 include/net/netns/ipv4.h   |  3 ++
 net/ipv4/sysctl_net_ipv4.c | 32 -
 net/ipv4/udp.c | 86 +++---
 net/ipv6/udp.c | 52 ++--
 4 files changed, 96 insertions(+), 77 deletions(-)

diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 3a970e4..382bfd7 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -168,6 +168,9 @@ struct netns_ipv4 {
atomic_t tfo_active_disable_times;
unsigned long tfo_active_disable_stamp;
 
+   int sysctl_udp_wmem_min;
+   int sysctl_udp_rmem_min;
+
 #ifdef CONFIG_NET_L3_MASTER_DEV
int sysctl_udp_l3mdev_accept;
 #endif
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 011de9a..5b72d97 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -520,22 +520,6 @@ static int proc_fib_multipath_hash_policy(struct ctl_table 
*table, int write,
.mode   = 0644,
.proc_handler   = proc_doulongvec_minmax,
},
-   {
-   .procname   = "udp_rmem_min",
-   .data   = &sysctl_udp_rmem_min,
-   .maxlen = sizeof(sysctl_udp_rmem_min),
-   .mode   = 0644,
-   .proc_handler   = proc_dointvec_minmax,
-   .extra1 = &one
-   },
-   {
-   .procname   = "udp_wmem_min",
-   .data   = &sysctl_udp_wmem_min,
-   .maxlen = sizeof(sysctl_udp_wmem_min),
-   .mode   = 0644,
-   .proc_handler   = proc_dointvec_minmax,
-   .extra1 = &one
-   },
{ }
 };
 
@@ -1167,6 +1151,22 @@ static int proc_fib_multipath_hash_policy(struct 
ctl_table *table, int write,
.proc_handler   = proc_dointvec_minmax,
.extra1 = &one,
},
+   {
+   .procname   = "udp_rmem_min",
+   .data   = &init_net.ipv4.sysctl_udp_rmem_min,
+   .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
+   .mode   = 0644,
+   .proc_handler   = proc_dointvec_minmax,
+   .extra1 = &one
+   },
+   {
+   .procname   = "udp_wmem_min",
+   .data   = &init_net.ipv4.sysctl_udp_wmem_min,
+   .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
+   .mode   = 0644,
+   .proc_handler   = proc_dointvec_minmax,
+   .extra1 = &one
+   },
{ }
 };
 
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 3013404..7ae77f2 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -122,12 +122,6 @@
 long sysctl_udp_mem[3] __read_mostly;
 EXPORT_SYMBOL(sysctl_udp_mem);
 
-int sysctl_udp_rmem_min __read_mostly;
-EXPORT_SYMBOL(sysctl_udp_rmem_min);
-
-int sysctl_udp_wmem_min __read_mostly;
-EXPORT_SYMBOL(sysctl_udp_wmem_min);
-
 atomic_long_t udp_memory_allocated;
 EXPORT_SYMBOL(udp_memory_allocated);
 
@@ -2533,35 +2527,35 @@ int udp_abort(struct sock *sk, int err)
 EXPORT_SYMBOL_GPL(udp_abort);
 
 struct proto udp_prot = {
-   .name  = "UDP",
-   .owner = THIS_MODULE,
-   .close = udp_lib_close,
-   .connect   = ip4_datagram_connect,
-   .disconnect= udp_disconnect,
-   .ioctl = udp_ioctl,
-   .init  = udp_init_sock,
-   .destroy   = udp_destroy_sock,
-   .setsockopt= udp_setsockopt,
-   .getsockopt= udp_getsockopt,
-   .sendmsg   = udp_sendmsg,
-   .recvmsg   = udp_recvmsg,
-   .sendpage  = udp_sendpage,
-   .release_cb= ip4_datagram_release_cb,
-   .hash  = udp_lib_hash,
-   .unhash= udp_lib_unhash,
-   .rehash= udp_v4_rehash,
-   .get_port  = udp_v4_get_port,
-   .memory_allocated  = &udp_memory_allocated,
-   .sysctl_mem= sysctl_udp_mem,
-   .sysctl_wmem   = &sysctl_udp_wmem_min,
-   .sysctl_rmem   = &sysctl_udp_rmem_min,
-   .obj_size  = sizeof(struct udp_sock),
-   .h.udp_table   = &udp_table,
+   .name   = "UDP",
+   .owner  = THIS_MODULE,
+   .close  = udp_lib_close,
+   .connect= ip4_datagram_connect,
+   .disconnect = udp_disconnect,
+   .ioctl  = udp_ioctl,
+   .init   = udp_init_sock,
+   .destroy= udp_destroy_sock,
+   .setsockopt = udp_setsockopt,
+   .getsockopt = udp_getsockopt,
+   .sendms