mirror of https://gitee.com/openkylin/linux.git
net: sched: use kvmalloc() for class hash tables
High order GFP_KERNEL allocations can stress the host badly. Use modern kvmalloc_array()/kvfree() instead of custom allocations. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
153890b41b
commit
9695fe6f21
|
@ -621,14 +621,10 @@ EXPORT_SYMBOL(qdisc_watchdog_cancel);
|
||||||
|
|
||||||
static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
|
static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
|
||||||
{
|
{
|
||||||
unsigned int size = n * sizeof(struct hlist_head), i;
|
|
||||||
struct hlist_head *h;
|
struct hlist_head *h;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
if (size <= PAGE_SIZE)
|
h = kvmalloc_array(n, sizeof(struct hlist_head), GFP_KERNEL);
|
||||||
h = kmalloc(size, GFP_KERNEL);
|
|
||||||
else
|
|
||||||
h = (struct hlist_head *)
|
|
||||||
__get_free_pages(GFP_KERNEL, get_order(size));
|
|
||||||
|
|
||||||
if (h != NULL) {
|
if (h != NULL) {
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
@ -637,16 +633,6 @@ static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qdisc_class_hash_free(struct hlist_head *h, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int size = n * sizeof(struct hlist_head);
|
|
||||||
|
|
||||||
if (size <= PAGE_SIZE)
|
|
||||||
kfree(h);
|
|
||||||
else
|
|
||||||
free_pages((unsigned long)h, get_order(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash)
|
void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash)
|
||||||
{
|
{
|
||||||
struct Qdisc_class_common *cl;
|
struct Qdisc_class_common *cl;
|
||||||
|
@ -679,7 +665,7 @@ void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash)
|
||||||
clhash->hashmask = nmask;
|
clhash->hashmask = nmask;
|
||||||
sch_tree_unlock(sch);
|
sch_tree_unlock(sch);
|
||||||
|
|
||||||
qdisc_class_hash_free(ohash, osize);
|
kvfree(ohash);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(qdisc_class_hash_grow);
|
EXPORT_SYMBOL(qdisc_class_hash_grow);
|
||||||
|
|
||||||
|
@ -699,7 +685,7 @@ EXPORT_SYMBOL(qdisc_class_hash_init);
|
||||||
|
|
||||||
void qdisc_class_hash_destroy(struct Qdisc_class_hash *clhash)
|
void qdisc_class_hash_destroy(struct Qdisc_class_hash *clhash)
|
||||||
{
|
{
|
||||||
qdisc_class_hash_free(clhash->hash, clhash->hashsize);
|
kvfree(clhash->hash);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(qdisc_class_hash_destroy);
|
EXPORT_SYMBOL(qdisc_class_hash_destroy);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue