[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Y/TnEUMQ9BT1rG3u@corigine.com>
Date: Tue, 21 Feb 2023 16:45:21 +0100
From: Simon Horman <simon.horman@...igine.com>
To: Paolo Abeni <pabeni@...hat.com>
Cc: netdev@...r.kernel.org, "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>,
Shuah Khan <shuah@...nel.org>
Subject: Re: [PATCH v2 net-next 1/2] net: make default_rps_mask a per netns
attribute
On Fri, Feb 17, 2023 at 01:28:49PM +0100, Paolo Abeni wrote:
> That really was meant to be a per netns attribute from the beginning.
>
> The idea is that once proper isolation is in place in the main
> namespace, additional demux in the child namespaces will be redundant.
> Let's make child netns default rps mask empty by default.
>
> To avoid bloating the netns with a possibly large cpumask, allocate
> it on-demand during the first write operation.
>
> Signed-off-by: Paolo Abeni <pabeni@...hat.com>
...
> diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
> index 7130e6d9e263..74842b453407 100644
> --- a/net/core/sysctl_net_core.c
> +++ b/net/core/sysctl_net_core.c
> @@ -74,24 +74,47 @@ static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
> #endif
>
> #ifdef CONFIG_RPS
> -struct cpumask rps_default_mask;
> +
> +static struct cpumask *rps_default_mask_cow_alloc(struct net *net)
> +{
> + struct cpumask *rps_default_mask;
> +
> + if (net->core.rps_default_mask)
> + return net->core.rps_default_mask;
> +
> + rps_default_mask = kzalloc(cpumask_size(), GFP_KERNEL);
> + if (!rps_default_mask)
> + return NULL;
> +
> + /* pairs with READ_ONCE in rx_queue_default_mask() */
> + WRITE_ONCE(net->core.rps_default_mask, rps_default_mask);
> + return rps_default_mask;
> +}
>
> static int rps_default_mask_sysctl(struct ctl_table *table, int write,
> void *buffer, size_t *lenp, loff_t *ppos)
> {
> + struct net *net = (struct net *)table->data;
> int err = 0;
>
> rtnl_lock();
> if (write) {
> - err = cpumask_parse(buffer, &rps_default_mask);
> + struct cpumask *rps_default_mask = rps_default_mask_cow_alloc(net);
> +
> + err = -ENOMEM;
nit: Would it be nicer to set err to -ENOMEM inside the if clause?
I think that is the only path where it is used.
> + if (!rps_default_mask)
> + goto done;
> +
> + err = cpumask_parse(buffer, rps_default_mask);
> if (err)
> goto done;
>
> - err = rps_cpumask_housekeeping(&rps_default_mask);
> + err = rps_cpumask_housekeeping(rps_default_mask);
> if (err)
> goto done;
> } else {
> - dump_cpumask(buffer, lenp, ppos, &rps_default_mask);
> + dump_cpumask(buffer, lenp, ppos,
> + net->core.rps_default_mask ? : cpu_none_mask);
> }
>
> done:
...
Powered by blists - more mailing lists