Skip to content

Commit da6bc57

Browse files
Michal Hockotorvalds
authored andcommitted
net: use kvmalloc with __GFP_REPEAT rather than open coded variant
fq_alloc_node, alloc_netdev_mqs and netif_alloc* open code kmalloc with vmalloc fallback. Use the kvmalloc variant instead. Keep the __GFP_REPEAT flag based on explanation from Eric: "At the time, tests on the hardware I had in my labs showed that vmalloc() could deliver pages spread all over the memory and that was a small penalty (once memory is fragmented enough, not at boot time)" The way how the code is constructed means, however, that we prefer to go and hit the OOM killer before we fall back to the vmalloc for requests <=32kB (with 4kB pages) in the current code. This is rather disruptive for something that can be achived with the fallback. On the other hand __GFP_REPEAT doesn't have any useful semantic for these requests. So the effect of this patch is that requests which fit into 32kB will fall back to vmalloc easier now. Link: http://lkml.kernel.org/r/20170306103327.2766-3-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Eric Dumazet <edumazet@google.com> Cc: David Miller <davem@davemloft.net> Cc: Shakeel Butt <shakeelb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 752ade6 commit da6bc57

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

net/core/dev.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7264,12 +7264,10 @@ static int netif_alloc_rx_queues(struct net_device *dev)
72647264

72657265
BUG_ON(count < 1);
72667266

7267-
rx = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
7268-
if (!rx) {
7269-
rx = vzalloc(sz);
7270-
if (!rx)
7271-
return -ENOMEM;
7272-
}
7267+
rx = kvzalloc(sz, GFP_KERNEL | __GFP_REPEAT);
7268+
if (!rx)
7269+
return -ENOMEM;
7270+
72737271
dev->_rx = rx;
72747272

72757273
for (i = 0; i < count; i++)
@@ -7306,12 +7304,10 @@ static int netif_alloc_netdev_queues(struct net_device *dev)
73067304
if (count < 1 || count > 0xffff)
73077305
return -EINVAL;
73087306

7309-
tx = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
7310-
if (!tx) {
7311-
tx = vzalloc(sz);
7312-
if (!tx)
7313-
return -ENOMEM;
7314-
}
7307+
tx = kvzalloc(sz, GFP_KERNEL | __GFP_REPEAT);
7308+
if (!tx)
7309+
return -ENOMEM;
7310+
73157311
dev->_tx = tx;
73167312

73177313
netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL);
@@ -7845,9 +7841,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
78457841
/* ensure 32-byte alignment of whole construct */
78467842
alloc_size += NETDEV_ALIGN - 1;
78477843

7848-
p = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
7849-
if (!p)
7850-
p = vzalloc(alloc_size);
7844+
p = kvzalloc(alloc_size, GFP_KERNEL | __GFP_REPEAT);
78517845
if (!p)
78527846
return NULL;
78537847

net/sched/sch_fq.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -624,16 +624,6 @@ static void fq_rehash(struct fq_sched_data *q,
624624
q->stat_gc_flows += fcnt;
625625
}
626626

627-
static void *fq_alloc_node(size_t sz, int node)
628-
{
629-
void *ptr;
630-
631-
ptr = kmalloc_node(sz, GFP_KERNEL | __GFP_REPEAT | __GFP_NOWARN, node);
632-
if (!ptr)
633-
ptr = vmalloc_node(sz, node);
634-
return ptr;
635-
}
636-
637627
static void fq_free(void *addr)
638628
{
639629
kvfree(addr);
@@ -650,7 +640,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
650640
return 0;
651641

652642
/* If XPS was setup, we can allocate memory on right NUMA node */
653-
array = fq_alloc_node(sizeof(struct rb_root) << log,
643+
array = kvmalloc_node(sizeof(struct rb_root) << log, GFP_KERNEL | __GFP_REPEAT,
654644
netdev_queue_numa_node_read(sch->dev_queue));
655645
if (!array)
656646
return -ENOMEM;

0 commit comments

Comments
 (0)