Commit 046e1537 authored by Íñigo Huguet's avatar Íñigo Huguet Committed by Jakub Kicinski

net: set default rss queues num to physical cores / 2

Network drivers can call to netif_get_num_default_rss_queues to get the
default number of receive queues to use. Right now, this default number
is min(8, num_online_cpus()).

Instead, as suggested by Jakub, use the number of physical cores divided
by 2 as a way to avoid wasting CPU resources and to avoid using both CPU
threads, but still allowing to scale for high-end processors with many
cores.

As an exception, select 2 queues for processors with 2 cores, because
otherwise it won't take any advantage of RSS despite being SMP capable.

Tested: Processor Intel Xeon E5-2620 (2 sockets, 6 cores/socket, 2
threads/core). NIC Broadcom NetXtreme II BCM57810 (10GBps). Ran some
tests with `perf stat iperf3 -R`, with parallelisms of 1, 8 and 24,
getting the following results:
- Number of queues: 6 (instead of 8)
- Network throughput: not affected
- CPU usage: utilized 0.05-0.12 CPUs more than before (having 24 CPUs
  this is only 0.2-0.5% higher)
- Reduced the number of context switches by 7-50%, being more noticeable
  when using a higher number of parallel threads.
Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarÍñigo Huguet <ihuguet@redhat.com>
Link: https://lore.kernel.org/r/20220315091832.13873-1-ihuguet@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e89600eb
...@@ -3664,7 +3664,6 @@ static inline unsigned int get_netdev_rx_queue_index( ...@@ -3664,7 +3664,6 @@ static inline unsigned int get_netdev_rx_queue_index(
} }
#endif #endif
#define DEFAULT_MAX_NUM_RSS_QUEUES (8)
int netif_get_num_default_rss_queues(void); int netif_get_num_default_rss_queues(void);
enum skb_free_reason { enum skb_free_reason {
......
...@@ -2990,13 +2990,25 @@ EXPORT_SYMBOL(netif_set_real_num_queues); ...@@ -2990,13 +2990,25 @@ EXPORT_SYMBOL(netif_set_real_num_queues);
/** /**
* netif_get_num_default_rss_queues - default number of RSS queues * netif_get_num_default_rss_queues - default number of RSS queues
* *
* This routine should set an upper limit on the number of RSS queues * Default value is the number of physical cores if there are only 1 or 2, or
* used by default by multiqueue devices. * divided by 2 if there are more.
*/ */
int netif_get_num_default_rss_queues(void) int netif_get_num_default_rss_queues(void)
{ {
return is_kdump_kernel() ? cpumask_var_t cpus;
1 : min_t(int, DEFAULT_MAX_NUM_RSS_QUEUES, num_online_cpus()); int cpu, count = 0;
if (unlikely(is_kdump_kernel() || !zalloc_cpumask_var(&cpus, GFP_KERNEL)))
return 1;
cpumask_copy(cpus, cpu_online_mask);
for_each_cpu(cpu, cpus) {
++count;
cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu));
}
free_cpumask_var(cpus);
return count > 2 ? DIV_ROUND_UP(count, 2) : count;
} }
EXPORT_SYMBOL(netif_get_num_default_rss_queues); EXPORT_SYMBOL(netif_get_num_default_rss_queues);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment