forked from mirrors/linux
		
	net: allow large number of tx queues
netif_alloc_netdev_queues() uses kcalloc() to allocate memory for the "struct netdev_queue *_tx" array. For large number of tx queues, kcalloc() might fail, so this patch does a fallback to vzalloc(). As vmalloc() adds overhead on a critical network path, add __GFP_REPEAT to kzalloc() flags to do this fallback only when really needed. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									b0b02c77d7
								
							
						
					
					
						commit
						60877a32bc
					
				
					 1 changed files with 19 additions and 7 deletions
				
			
		| 
						 | 
					@ -130,6 +130,7 @@
 | 
				
			||||||
#include <linux/cpu_rmap.h>
 | 
					#include <linux/cpu_rmap.h>
 | 
				
			||||||
#include <linux/static_key.h>
 | 
					#include <linux/static_key.h>
 | 
				
			||||||
#include <linux/hashtable.h>
 | 
					#include <linux/hashtable.h>
 | 
				
			||||||
 | 
					#include <linux/vmalloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "net-sysfs.h"
 | 
					#include "net-sysfs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5253,17 +5254,28 @@ static void netdev_init_one_queue(struct net_device *dev,
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void netif_free_tx_queues(struct net_device *dev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (is_vmalloc_addr(dev->_tx))
 | 
				
			||||||
 | 
							vfree(dev->_tx);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							kfree(dev->_tx);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int netif_alloc_netdev_queues(struct net_device *dev)
 | 
					static int netif_alloc_netdev_queues(struct net_device *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned int count = dev->num_tx_queues;
 | 
						unsigned int count = dev->num_tx_queues;
 | 
				
			||||||
	struct netdev_queue *tx;
 | 
						struct netdev_queue *tx;
 | 
				
			||||||
 | 
						size_t sz = count * sizeof(*tx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUG_ON(count < 1);
 | 
						BUG_ON(count < 1 || count > 0xffff);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx = kcalloc(count, sizeof(struct netdev_queue), GFP_KERNEL);
 | 
						tx = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
 | 
				
			||||||
 | 
						if (!tx) {
 | 
				
			||||||
 | 
							tx = vzalloc(sz);
 | 
				
			||||||
		if (!tx)
 | 
							if (!tx)
 | 
				
			||||||
			return -ENOMEM;
 | 
								return -ENOMEM;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	dev->_tx = tx;
 | 
						dev->_tx = tx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL);
 | 
						netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL);
 | 
				
			||||||
| 
						 | 
					@ -5811,7 +5823,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
free_pcpu:
 | 
					free_pcpu:
 | 
				
			||||||
	free_percpu(dev->pcpu_refcnt);
 | 
						free_percpu(dev->pcpu_refcnt);
 | 
				
			||||||
	kfree(dev->_tx);
 | 
						netif_free_tx_queues(dev);
 | 
				
			||||||
#ifdef CONFIG_RPS
 | 
					#ifdef CONFIG_RPS
 | 
				
			||||||
	kfree(dev->_rx);
 | 
						kfree(dev->_rx);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -5836,7 +5848,7 @@ void free_netdev(struct net_device *dev)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	release_net(dev_net(dev));
 | 
						release_net(dev_net(dev));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kfree(dev->_tx);
 | 
						netif_free_tx_queues(dev);
 | 
				
			||||||
#ifdef CONFIG_RPS
 | 
					#ifdef CONFIG_RPS
 | 
				
			||||||
	kfree(dev->_rx);
 | 
						kfree(dev->_rx);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue