From: Eric Dumazet <eric.dumazet@gmail.com>
To: Willem de Bruijn <willemb@google.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, stephen@networkplumber.org
Subject: Re: [PATCH net-next v3] rps: selective flow shedding during softnet overflow
Date: Tue, 23 Apr 2013 12:18:58 -0700 [thread overview]
Message-ID: <1366744738.8964.6.camel@edumazet-glaptop> (raw)
In-Reply-To: <1366742817-8480-1-git-send-email-willemb@google.com>
Hi Willem
On Tue, 2013-04-23 at 14:46 -0400, Willem de Bruijn wrote:
> +
> +static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
> +{
> +#ifdef CONFIG_NET_FLOW_LIMIT
> + struct sd_flow_limit *fl;
> + struct softnet_data *sd;
> + unsigned int old_flow, new_flow;
> +
> + if (qlen < (netdev_max_backlog >> 1))
> + return false;
> +
> + sd = &per_cpu(softnet_data, smp_processor_id());
sd = __get_cpu_var(softnet_data);
> +
> + rcu_read_lock();
> + fl = rcu_dereference(sd->flow_limit);
> + if (fl) {
> + new_flow = skb_get_rxhash(skb) & (fl->num_buckets - 1);
> + old_flow = fl->history[fl->history_head];
> + fl->history[fl->history_head] = new_flow;
> +
> + fl->history_head++;
> + fl->history_head &= FLOW_LIMIT_HISTORY - 1;
> +
> + if (likely(fl->buckets[old_flow]))
> + fl->buckets[old_flow]--;
> +
> + if (++fl->buckets[new_flow] > (FLOW_LIMIT_HISTORY >> 1)) {
> + fl->count++;
> + rcu_read_unlock();
> + return true;
> + }
> + }
> + rcu_read_unlock();
> +#endif
> + return false;
> +}
> +
...
> +#ifdef CONFIG_NET_FLOW_LIMIT
> +static DEFINE_MUTEX(flow_limit_update_mutex);
> +
> +static int flow_limit_cpu_sysctl(ctl_table *table, int write,
> + void __user *buffer, size_t *lenp,
> + loff_t *ppos)
> +{
> + struct sd_flow_limit *cur;
> + struct softnet_data *sd;
> + cpumask_var_t mask;
> + int i, len, ret = 0;
> +
> + if (!alloc_cpumask_var(&mask, GFP_KERNEL))
> + return -ENOMEM;
> +
> + if (write) {
> + ret = cpumask_parse_user(buffer, *lenp, mask);
> + if (ret)
> + goto done;
> +
> + mutex_lock(&flow_limit_update_mutex);
> + len = sizeof(*cur) + netdev_flow_limit_table_len;
> + for_each_possible_cpu(i) {
> + sd = &per_cpu(softnet_data, i);
> + cur = rcu_dereference_protected(sd->flow_limit,
> + lockdep_is_held(flow_limit_update_mutex));
> + if (cur && !cpumask_test_cpu(i, mask)) {
> + RCU_INIT_POINTER(sd->flow_limit, NULL);
> + synchronize_rcu();
> + kfree(cur);
> + } else if (!cur && cpumask_test_cpu(i, mask)) {
> + cur = kzalloc(len, GFP_KERNEL);
> + if (!cur) {
> + /* not unwinding previous changes */
> + ret = -ENOMEM;
> + goto write_unlock;
> + }
> + cur->num_buckets = netdev_flow_limit_table_len;
> + rcu_assign_pointer(sd->flow_limit, cur);
> + }
> + }
> +write_unlock:
> + synchronize_rcu();
I believe you do not need this synchronize_rcu() call.
> + mutex_unlock(&flow_limit_update_mutex);
> + } else {
> + if (*ppos || !*lenp) {
> + *lenp = 0;
> + goto done;
> + }
> +
> + cpumask_clear(mask);
> + rcu_read_lock();
> + for_each_possible_cpu(i) {
> + sd = &per_cpu(softnet_data, i);
> + if (rcu_dereference(sd->flow_limit))
> + cpumask_set_cpu(i, mask);
> + }
> + rcu_read_unlock();
> +
> + len = cpumask_scnprintf(buffer, *lenp, mask);
> + *lenp = len + 1;
> + *ppos += len + 1;
> + }
> +
> +done:
> + free_cpumask_var(mask);
> + return ret;
> +}
> +
Thanks !
next prev parent reply other threads:[~2013-04-23 19:19 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-19 17:46 [PATCH] rps: selective flow shedding during softnet overflow Willem de Bruijn
2013-04-19 17:58 ` Eric Dumazet
2013-04-22 20:40 ` Willem de Bruijn
2013-04-22 20:46 ` [PATCH net-next v2] " Willem de Bruijn
2013-04-22 22:30 ` Eric Dumazet
2013-04-23 18:45 ` Willem de Bruijn
2013-04-23 18:46 ` [PATCH net-next v3] " Willem de Bruijn
2013-04-23 19:18 ` Eric Dumazet [this message]
2013-04-23 20:30 ` Willem de Bruijn
2013-04-23 20:31 ` [PATCH net-next v4] " Willem de Bruijn
2013-04-23 21:23 ` Stephen Hemminger
2013-04-23 21:37 ` Willem de Bruijn
2013-04-23 21:37 ` Eric Dumazet
2013-04-23 21:52 ` Stephen Hemminger
2013-04-23 22:34 ` David Miller
2013-04-24 0:09 ` Eric Dumazet
2013-04-24 0:37 ` [PATCH net-next v5] " Willem de Bruijn
2013-04-24 1:07 ` Eric Dumazet
2013-04-25 8:20 ` David Miller
2013-05-20 14:02 ` [PATCH net-next v6] " Willem de Bruijn
2013-05-20 16:00 ` Eric Dumazet
2013-05-20 16:08 ` Willem de Bruijn
2013-05-20 20:48 ` David Miller
2013-04-24 1:25 ` [PATCH net-next v4] " Jamal Hadi Salim
2013-04-24 1:32 ` Eric Dumazet
2013-04-24 1:44 ` Jamal Hadi Salim
2013-04-24 2:11 ` Eric Dumazet
2013-04-24 13:00 ` Jamal Hadi Salim
2013-04-24 14:41 ` Eric Dumazet
2013-04-23 22:33 ` David Miller
2013-04-23 21:34 ` Eric Dumazet
2013-04-23 22:41 ` David Miller
2013-04-23 23:11 ` Eric Dumazet
2013-04-23 23:15 ` David Miller
2013-04-23 23:26 ` Eric Dumazet
2013-04-24 0:03 ` Stephen Hemminger
2013-04-24 0:00 ` Willem de Bruijn
2013-04-23 20:46 ` [PATCH net-next v3] " Eric Dumazet
2013-04-19 19:03 ` [PATCH] " Stephen Hemminger
2013-04-19 19:21 ` Eric Dumazet
2013-04-19 20:11 ` Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366744738.8964.6.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox