From: "Tobin C. Harding" <me@tobin.cc>
To: "David S . Miller" <davem@davemloft.net>
Cc: mawilcox@microsoft.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, "Tobin C. Harding" <me@tobin.cc>
Subject: [PATCH 2/2] net: Replace custom page based bitmap with IDA
Date: Sun, 12 Feb 2017 13:57:34 +1100 [thread overview]
Message-ID: <1486868254-5386-3-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1486868254-5386-1-git-send-email-me@tobin.cc>
Current implementation of __dev_alloc_name uses a custom bitmap of
a single page to iterate network device id's and allocate an unused id.
This leads to a upper limit of 8 * PAGE_SIZE network device id's (for
each name format i.e eth0).
This patch uses the kernel's IDA as a replacement to the page based
bitmap. This has the effect of simplifying the code and removing
the upper limit.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
net/core/dev.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index 29101c9..b16ea84 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1025,39 +1025,31 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
{
int i = 0;
const char *p;
- const int max_netdevices = 8*PAGE_SIZE;
- unsigned long *inuse;
struct net_device *d;
+ DEFINE_IDA(ida);
+ const int end = 0;
p = strnchr(name, IFNAMSIZ-1, '%');
if (p) {
- /*
- * Verify the string as this thing may have come from
+ /* Verify the string as this thing may have come from
* the user. There must be either one "%d" and no other "%"
* characters.
*/
if (p[1] != 'd' || strchr(p + 2, '%'))
return -EINVAL;
- /* Use one page as a bit array of possible slots */
- inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
- if (!inuse)
- return -ENOMEM;
-
for_each_netdev(net, d) {
if (!sscanf(d->name, name, &i))
continue;
- if (i < 0 || i >= max_netdevices)
+ if (i < 0)
continue;
/* avoid cases where sscanf is not exact inverse of printf */
snprintf(buf, IFNAMSIZ, name, i);
if (!strncmp(buf, d->name, IFNAMSIZ))
- set_bit(i, inuse);
+ ida_simple_get(&ida, i, end, GFP_KERNEL);
}
-
- i = find_first_zero_bit(inuse, max_netdevices);
- free_page((unsigned long) inuse);
+ i = ida_simple_get(&ida, 0, end, GFP_KERNEL);
}
if (buf != name)
--
2.7.4
prev parent reply other threads:[~2017-02-12 2:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-12 2:57 [PATCH 0/2] net: Replace custom page based bitmap with IDA Tobin C. Harding
2017-02-12 2:57 ` [PATCH 1/2] include: Fix checkpatch whitespace error and warning Tobin C. Harding
2017-02-12 10:39 ` Sergei Shtylyov
2017-02-12 12:17 ` Matthew Wilcox
2017-02-12 2:57 ` Tobin C. Harding [this message]
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=1486868254-5386-3-git-send-email-me@tobin.cc \
--to=me@tobin.cc \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mawilcox@microsoft.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox