]> git.neil.brown.name Git - history.git/commitdiff
[BRIDGE]: FDB cache alloc.
authorStephen Hemminger <shemminger@osdl.org>
Fri, 16 Apr 2004 07:22:49 +0000 (00:22 -0700)
committerStephen Hemminger <shemminger@osdl.org>
Fri, 16 Apr 2004 07:22:49 +0000 (00:22 -0700)
Since forwarding database gets a lot of memory alloc/free on a busy
bridge, use kmem_cache_alloc to provide cache and better stats.

net/bridge/br.c
net/bridge/br_fdb.c
net/bridge/br_private.h

index 2f02b889c496035099f27caae2070046b0db3a01..675d0709a06911a7241a579976b97aefc3500a26 100644 (file)
@@ -31,6 +31,8 @@ int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
 
 static int __init br_init(void)
 {
+       br_fdb_init();
+
 #ifdef CONFIG_BRIDGE_NETFILTER
        if (br_netfilter_init())
                return 1;
@@ -65,6 +67,7 @@ static void __exit br_deinit(void)
 #endif
 
        br_handle_frame_hook = NULL;
+       br_fdb_fini();
 }
 
 EXPORT_SYMBOL(br_should_route_hook);
index e4c548690be9360baea075f6302324012f6af4de..69664a4da8ef2d7a2e34925498d8ceca9ffaafd8 100644 (file)
 #include <asm/uaccess.h>
 #include "br_private.h"
 
+static kmem_cache_t *br_fdb_cache;
+
+void __init br_fdb_init(void)
+{
+       br_fdb_cache = kmem_cache_create("bridge_fdb_cache",
+                                        sizeof(struct net_bridge_fdb_entry),
+                                        0,
+                                        SLAB_HWCACHE_ALIGN, NULL, NULL);
+}
+
+void __exit br_fdb_fini(void)
+{
+       kmem_cache_destroy(br_fdb_cache);
+}
+
+
 /* if topology_changing then use forward_delay (default 15 sec)
  * otherwise keep longer (default 5 minutes)
  */
@@ -37,7 +53,7 @@ static __inline__ int has_expired(const struct net_bridge *br,
                && time_before_eq(fdb->ageing_timer + hold_time(br), jiffies);
 }
 
-static __inline__ void copy_fdb(struct __fdb_entry *ent, 
+static inline void copy_fdb(struct __fdb_entry *ent, 
                                const struct net_bridge_fdb_entry *f)
 {
        memset(ent, 0, sizeof(struct __fdb_entry));
@@ -175,7 +191,7 @@ struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br, unsigned char *ad
 void br_fdb_put(struct net_bridge_fdb_entry *ent)
 {
        if (atomic_dec_and_test(&ent->use_count))
-               kfree(ent);
+               kmem_cache_free(br_fdb_cache, ent);
 }
 
 int br_fdb_get_entries(struct net_bridge *br,
@@ -222,7 +238,7 @@ int br_fdb_get_entries(struct net_bridge *br,
                        
                        /* entry was deleted during copy_to_user */
                        if (atomic_dec_and_test(&f->use_count)) {
-                               kfree(f);
+                               kmem_cache_free(br_fdb_cache, f);
                                num = -EAGAIN;
                                goto out;
                        }
@@ -282,7 +298,7 @@ int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
                }
        }
 
-       fdb = kmalloc(sizeof(*fdb), GFP_ATOMIC);
+       fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC);
        if (unlikely(fdb == NULL)) {
                ret = -ENOMEM;
                goto out;
index 1e3ad5078d727dec588b988b7eb5786da4102410..20462c1e4e5e48d464144b4804f06ea725e2375f 100644 (file)
@@ -127,6 +127,8 @@ extern void br_dev_setup(struct net_device *dev);
 extern int br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
 
 /* br_fdb.c */
+extern void br_fdb_init(void);
+extern void br_fdb_fini(void);
 extern void br_fdb_changeaddr(struct net_bridge_port *p,
                              const unsigned char *newaddr);
 extern void br_fdb_cleanup(unsigned long arg);