All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 2/6] netem: use vmalloc for distribution table
Date: Wed, 23 Feb 2011 15:04:18 -0800	[thread overview]
Message-ID: <20110223230534.173432150@vyatta.com> (raw)
In-Reply-To: 20110223230416.532009518@vyatta.com

[-- Attachment #1: netem-vmalloc.patch --]
[-- Type: text/plain, Size: 1760 bytes --]

The netem probability table can be large (up to 64K bytes)
which may be too large to allocate in one contiguous chunk.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

--- a/net/sched/sch_netem.c	2011-02-23 14:43:27.000000000 -0800
+++ b/net/sched/sch_netem.c	2011-02-23 14:49:07.228646202 -0800
@@ -308,6 +308,16 @@ static void netem_reset(struct Qdisc *sc
 	qdisc_watchdog_cancel(&q->watchdog);
 }
 
+static void dist_free(struct disttable *d)
+{
+	if (d) {
+		if (is_vmalloc_addr(d))
+			vfree(d);
+		else
+			kfree(d);
+	}
+}
+
 /*
  * Distribution data is a variable size payload containing
  * signed 16 bit values.
@@ -315,16 +325,20 @@ static void netem_reset(struct Qdisc *sc
 static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
 {
 	struct netem_sched_data *q = qdisc_priv(sch);
-	unsigned long n = nla_len(attr)/sizeof(__s16);
+	size_t n = nla_len(attr)/sizeof(__s16);
 	const __s16 *data = nla_data(attr);
 	spinlock_t *root_lock;
 	struct disttable *d;
 	int i;
+	size_t s;
 
 	if (n > 65536)
 		return -EINVAL;
 
-	d = kmalloc(sizeof(*d) + n*sizeof(d->table[0]), GFP_KERNEL);
+	s = sizeof(struct disttable) + n * sizeof(s16);
+	d = kmalloc(s, GFP_KERNEL);
+	if (!d)
+		d = vmalloc(s);
 	if (!d)
 		return -ENOMEM;
 
@@ -335,7 +349,7 @@ static int get_dist_table(struct Qdisc *
 	root_lock = qdisc_root_sleeping_lock(sch);
 
 	spin_lock_bh(root_lock);
-	kfree(q->delay_dist);
+	dist_free(q->delay_dist);
 	q->delay_dist = d;
 	spin_unlock_bh(root_lock);
 	return 0;
@@ -556,7 +570,7 @@ static void netem_destroy(struct Qdisc *
 
 	qdisc_watchdog_cancel(&q->watchdog);
 	qdisc_destroy(q->qdisc);
-	kfree(q->delay_dist);
+	dist_free(q->delay_dist);
 }
 
 static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)



  parent reply	other threads:[~2011-02-23 23:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-23 23:04 [PATCH net-next 0/6] netem patches Stephen Hemminger
2011-02-23 23:04 ` [PATCH net-next 1/6] [PATCH 5/9] netem: cleanup dump code Stephen Hemminger
2011-02-23 23:04 ` Stephen Hemminger [this message]
2011-02-23 23:04 ` [PATCH net-next 3/6] netem: define NETEM_DIST_MAX Stephen Hemminger
2011-02-23 23:04 ` [PATCH net-next 4/6] [PATCH] Revert "sch_netem: Remove classful functionality" Stephen Hemminger
2011-02-23 23:04 ` [PATCH net-next 5/6] netem: revised correlated loss generator Stephen Hemminger
2011-02-23 23:04 ` [PATCH net-next 6/6] netem: update version and cleanup Stephen Hemminger
2011-02-25  6:14 ` [PATCH net-next 0/6] netem patches David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110223230534.173432150@vyatta.com \
    --to=shemminger@vyatta.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.