Re: Big numbers of PPP devices...

David Luyer (luyer@ucs.uwa.edu.au)
Thu, 10 Jun 1999 15:56:06 +0800


> Third alternative (my preference now I think about it): add a
> dev_alloc_name_hint, make dev_alloc_name a #define with a hint of 0.

Oh, here is the patch for that. I didn't leave the old exported function
(binary module compatibility - who needs it?)

This should speed up new ppp (and hence pptp, where thousands of connections
are actually a plausible aim) connections by milliseconds (or more, on
slow embedded systems) when thousands of clients are connected.

diff -ur linux/drivers/net/ppp.c linux-patched/drivers/net/ppp.c
--- linux/drivers/net/ppp.c Wed May 12 00:55:45 1999
+++ linux-patched/drivers/net/ppp.c Thu Jun 10 15:41:40 1999
@@ -2798,6 +2798,7 @@
static struct ppp *
ppp_alloc(void)
{
+ static int hint = 0;
int if_num;
int status;
struct device *dev;
@@ -2841,7 +2842,7 @@
*/
dev = ppp2dev(ppp);
dev->name = ppp->name;
- if_num = dev_alloc_name(dev, "ppp%d");
+ if_num = dev_alloc_name_hint(dev, "ppp%d", hint++);
if (if_num < 0) {
printk(KERN_ERR "ppp: dev_alloc_name failed (%d)\n", if_num);
kfree(ppp);
diff -ur linux/include/linux/netdevice.h linux-patched/include/linux/netdevice.h
--- linux/include/linux/netdevice.h Wed May 12 01:36:38 1999
+++ linux-patched/include/linux/netdevice.h Thu Jun 10 15:43:29 1999
@@ -340,7 +340,7 @@
extern void dev_remove_pack(struct packet_type *pt);
extern struct device *dev_get(const char *name);
extern struct device *dev_alloc(const char *name, int *err);
-extern int dev_alloc_name(struct device *dev, const char *name);
+extern int dev_alloc_name_hint(struct device *dev, const char *name, int hint);
extern int dev_open(struct device *dev);
extern int dev_close(struct device *dev);
extern int dev_queue_xmit(struct sk_buff *skb);
@@ -352,6 +352,8 @@
extern int dev_new_index(void);
extern struct device *dev_get_by_index(int ifindex);
extern int dev_restart(struct device *dev);
+
+#define dev_alloc_name(dev,name) dev_alloc_name_hint(dev,name,0)

typedef int gifconf_func_t(struct device * dev, char * bufptr, int len);
extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
diff -ur linux/net/core/dev.c linux-patched/net/core/dev.c
--- linux/net/core/dev.c Fri Mar 26 01:23:34 1999
+++ linux-patched/net/core/dev.c Thu Jun 10 15:40:34 1999
@@ -293,22 +293,21 @@

/*
* Passed a format string - eg "lt%d" it will try and find a suitable
- * id. Not efficient for many devices, not called a lot..
+ * id. Not efficient for many devices without a good hint, hopefully
+ * not called a lot like that.
*/

-int dev_alloc_name(struct device *dev, const char *name)
+int dev_alloc_name_hint(struct device *dev, const char *name, int hint)
{
int i;
- /*
- * If you need over 100 please also fix the algorithm...
- */
+
for(i=0;i<100;i++)
{
- sprintf(dev->name,name,i);
+ sprintf(dev->name,name,i+hint);
if(dev_get(dev->name)==NULL)
return i;
}
- return -ENFILE; /* Over 100 of the things .. bail out! */
+ return -ENFILE; /* Over 100 guesses .. bail out! */
}

struct device *dev_alloc(const char *name, int *err)
diff -ur linux/net/netsyms.c linux-patched/net/netsyms.c
--- linux/net/netsyms.c Sun Apr 25 08:51:48 1999
+++ linux-patched/net/netsyms.c Thu Jun 10 15:44:05 1999
@@ -457,7 +457,7 @@
EXPORT_SYMBOL(dev_remove_pack);
EXPORT_SYMBOL(dev_get);
EXPORT_SYMBOL(dev_alloc);
-EXPORT_SYMBOL(dev_alloc_name);
+EXPORT_SYMBOL(dev_alloc_name_hint);
EXPORT_SYMBOL(dev_ioctl);
EXPORT_SYMBOL(dev_queue_xmit);
EXPORT_SYMBOL(netdev_dropping);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/