netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: sched: use kvmalloc() for class hash tables
@ 2017-08-22 19:26 Eric Dumazet
  2017-08-22 21:21 ` Alexei Starovoitov
  2017-08-22 21:38 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2017-08-22 19:26 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Jamal Hadi Salim, Cong Wang, Jiri Pirko

From: Eric Dumazet <edumazet@google.com>

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>
---
 net/sched/sch_api.c |   22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 0fea0c50b7636b75b57ddf408c45ecce344813f4..aaf552b8e1205f29e0d95e943898bea35b647299 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -621,14 +621,10 @@ EXPORT_SYMBOL(qdisc_watchdog_cancel);
 
 static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
 {
-	unsigned int size = n * sizeof(struct hlist_head), i;
 	struct hlist_head *h;
+	unsigned int i;
 
-	if (size <= PAGE_SIZE)
-		h = kmalloc(size, GFP_KERNEL);
-	else
-		h = (struct hlist_head *)
-			__get_free_pages(GFP_KERNEL, get_order(size));
+	h = kvmalloc_array(n, sizeof(struct hlist_head), GFP_KERNEL);
 
 	if (h != NULL) {
 		for (i = 0; i < n; i++)
@@ -637,16 +633,6 @@ static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
 	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)
 {
 	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;
 	sch_tree_unlock(sch);
 
-	qdisc_class_hash_free(ohash, osize);
+	kvfree(ohash);
 }
 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)
 {
-	qdisc_class_hash_free(clhash->hash, clhash->hashsize);
+	kvfree(clhash->hash);
 }
 EXPORT_SYMBOL(qdisc_class_hash_destroy);
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: sched: use kvmalloc() for class hash tables
  2017-08-22 19:26 [PATCH net-next] net: sched: use kvmalloc() for class hash tables Eric Dumazet
@ 2017-08-22 21:21 ` Alexei Starovoitov
  2017-08-22 21:38 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2017-08-22 21:21 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, netdev, Jamal Hadi Salim, Cong Wang, Jiri Pirko

On Tue, Aug 22, 2017 at 12:26:46PM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> 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>

Thanks for fixing these issues.
Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: sched: use kvmalloc() for class hash tables
  2017-08-22 19:26 [PATCH net-next] net: sched: use kvmalloc() for class hash tables Eric Dumazet
  2017-08-22 21:21 ` Alexei Starovoitov
@ 2017-08-22 21:38 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-08-22 21:38 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, jhs, xiyou.wangcong, jiri

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 22 Aug 2017 12:26:46 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> 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>

Applied, thanks Eric.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-22 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-22 19:26 [PATCH net-next] net: sched: use kvmalloc() for class hash tables Eric Dumazet
2017-08-22 21:21 ` Alexei Starovoitov
2017-08-22 21:38 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).