[VLAN]: Avoid a 4-order allocation.
authorDan Aloni <da-x@monatomic.org>
Sat, 3 Mar 2007 04:44:51 +0000 (20:44 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 3 Mar 2007 04:44:51 +0000 (20:44 -0800)
This patch splits the vlan_group struct into a multi-allocated struct. On
x86_64, the size of the original struct is a little more than 32KB, causing
a 4-order allocation, which is prune to problems caused by buddy-system
external fragmentation conditions.

I couldn't just use vmalloc() because vfree() cannot be called in the
softirq context of the RCU callback.

Signed-off-by: Dan Aloni <da-x@monatomic.org>
Acked-by: Jeff Garzik <jeff@garzik.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
22 files changed:
drivers/net/8139cp.c
drivers/net/acenic.c
drivers/net/amd8111e.c
drivers/net/atl1/atl1_main.c
drivers/net/bnx2.c
drivers/net/bonding/bond_main.c
drivers/net/chelsio/cxgb2.c
drivers/net/cxgb3/cxgb3_offload.c
drivers/net/e1000/e1000_main.c
drivers/net/ehea/ehea_main.c
drivers/net/gianfar.c
drivers/net/ixgb/ixgb_main.c
drivers/net/ns83820.c
drivers/net/r8169.c
drivers/net/s2io.c
drivers/net/sky2.c
drivers/net/starfire.c
drivers/net/tg3.c
drivers/net/typhoon.c
drivers/s390/net/qeth_main.c
include/linux/if_vlan.h
net/8021q/vlan.c

index 6f93a765e56479ec9f0b598faf517468d3cd6ca0..12c8453f44bce3e337dc3a3f8d440153ee02061c 100644 (file)
@@ -448,8 +448,7 @@ static void cp_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        spin_lock_irqsave(&cp->lock, flags);
        cp->cpcmd &= ~RxVlanOn;
        cpw16(CpCmd, cp->cpcmd);
-       if (cp->vlgrp)
-               cp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(cp->vlgrp, vid, NULL);
        spin_unlock_irqrestore(&cp->lock, flags);
 }
 #endif /* CP_VLAN_TAG_USED */
index 33c6645455ae73f684a6cdfe33f8b0a1a6a6a5af..7138e0e025bca734e3d7a289e384e620fb50f659 100644 (file)
@@ -2293,10 +2293,7 @@ static void ace_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
 
        local_irq_save(flags);
        ace_mask_irq(dev);
-
-       if (ap->vlgrp)
-               ap->vlgrp->vlan_devices[vid] = NULL;
-
+       vlan_group_set_device(ap->vlgrp, vid, NULL);
        ace_unmask_irq(dev);
        local_irq_restore(flags);
 }
index 9c399aaefbdd1b6b045c97fab94e28dfaef3b990..962c954c2d566e1645c6a4f9e76a96061412c38c 100644 (file)
@@ -1737,8 +1737,7 @@ static void amd8111e_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid
 {
        struct amd8111e_priv *lp = netdev_priv(dev);
        spin_lock_irq(&lp->lock);
-       if (lp->vlgrp)
-               lp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(lp->vlgrp, vid, NULL);
        spin_unlock_irq(&lp->lock);
 }
 #endif
index 65673485bb6b35c1f1e457261a14a7740d5b9389..88d4f70035bb3c106180adf2159137691745bc9d 100644 (file)
@@ -1252,8 +1252,7 @@ static void atl1_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
 
        spin_lock_irqsave(&adapter->lock, flags);
        /* atl1_irq_disable(adapter); */
-       if (adapter->vlgrp)
-               adapter->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(adapter->vlgrp, vid, NULL);
        /* atl1_irq_enable(adapter); */
        spin_unlock_irqrestore(&adapter->lock, flags);
        /* We don't do Vlan filtering */
@@ -1266,7 +1265,7 @@ static void atl1_restore_vlan(struct atl1_adapter *adapter)
        if (adapter->vlgrp) {
                u16 vid;
                for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
-                       if (!adapter->vlgrp->vlan_devices[vid])
+                       if (!vlan_group_get_device(adapter->vlgrp, vid))
                                continue;
                        atl1_vlan_rx_add_vid(adapter->netdev, vid);
                }
index 5a96d7611af1f4dc0f573d6c12b07e5bc79787fc..c12e5ea6181967a4f80a876ed3f6f82dbb988777 100644 (file)
@@ -4467,9 +4467,7 @@ bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
        struct bnx2 *bp = netdev_priv(dev);
 
        bnx2_netif_stop(bp);
-
-       if (bp->vlgrp)
-               bp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(bp->vlgrp, vid, NULL);
        bnx2_set_rx_mode(dev);
 
        bnx2_netif_start(bp);
index a7c8f98a890c12bae0f8e8ac1e47a9037476f01f..ea73ebff438712214251997fdf3138541fe236bf 100644 (file)
@@ -488,9 +488,9 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
                        /* Save and then restore vlan_dev in the grp array,
                         * since the slave's driver might clear it.
                         */
-                       vlan_dev = bond->vlgrp->vlan_devices[vid];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
                        slave_dev->vlan_rx_kill_vid(slave_dev, vid);
-                       bond->vlgrp->vlan_devices[vid] = vlan_dev;
+                       vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
                }
        }
 
@@ -550,9 +550,9 @@ static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *s
                /* Save and then restore vlan_dev in the grp array,
                 * since the slave's driver might clear it.
                 */
-               vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+               vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                slave_dev->vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
-               bond->vlgrp->vlan_devices[vlan->vlan_id] = vlan_dev;
+               vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
        }
 
 unreg:
@@ -2397,7 +2397,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
                vlan_id = 0;
                list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
                                         vlan_list) {
-                       vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == rt->u.dst.dev) {
                                vlan_id = vlan->vlan_id;
                                dprintk("basa: vlan match on %s %d\n",
@@ -2444,7 +2444,7 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
        }
 
        list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
-               vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+               vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                if (vlan->vlan_ip) {
                        bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
                                      vlan->vlan_ip, vlan->vlan_id);
@@ -3371,7 +3371,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
 
                list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
                                         vlan_list) {
-                       vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == event_dev) {
                                switch (event) {
                                case NETDEV_UP:
index 7d0f24f697770c734701bb7c8f7a835a5d559a0b..125c9b10586920bb244970606c85cfe21025277f 100644 (file)
@@ -889,8 +889,7 @@ static void vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        struct adapter *adapter = dev->priv;
 
        spin_lock_irq(&adapter->async_lock);
-       if (adapter->vlan_grp)
-               adapter->vlan_grp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(adapter->vlan_grp, vid, NULL);
        spin_unlock_irq(&adapter->async_lock);
 }
 #endif
index b2cf5f6feb4a4ada3b8ab4bacd48943efdb4d9af..f6ed033efb56519cb924b790a225d642b7b8cb6d 100644 (file)
@@ -160,14 +160,16 @@ static struct net_device *get_iff_from_mac(struct adapter *adapter,
        int i;
 
        for_each_port(adapter, i) {
-               const struct vlan_group *grp;
+               struct vlan_group *grp;
                struct net_device *dev = adapter->port[i];
                const struct port_info *p = netdev_priv(dev);
 
                if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) {
                        if (vlan && vlan != VLAN_VID_MASK) {
                                grp = p->vlan_grp;
-                               dev = grp ? grp->vlan_devices[vlan] : NULL;
+                               dev = NULL;
+                               if (grp)
+                                       dev = vlan_group_get_device(grp, vlan);
                        } else
                                while (dev->master)
                                        dev = dev->master;
index 98215fdd7d10bc23a6b50c59c720d901a65f0636..1d08e937af825421009ba1071190ac1dc5049a9c 100644 (file)
@@ -376,7 +376,7 @@ e1000_update_mng_vlan(struct e1000_adapter *adapter)
        uint16_t vid = adapter->hw.mng_cookie.vlan_id;
        uint16_t old_vid = adapter->mng_vlan_id;
        if (adapter->vlgrp) {
-               if (!adapter->vlgrp->vlan_devices[vid]) {
+               if (!vlan_group_get_device(adapter->vlgrp, vid)) {
                        if (adapter->hw.mng_cookie.status &
                                E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
                                e1000_vlan_rx_add_vid(netdev, vid);
@@ -386,7 +386,7 @@ e1000_update_mng_vlan(struct e1000_adapter *adapter)
 
                        if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
                                        (vid != old_vid) &&
-                                       !adapter->vlgrp->vlan_devices[old_vid])
+                           !vlan_group_get_device(adapter->vlgrp, old_vid))
                                e1000_vlan_rx_kill_vid(netdev, old_vid);
                } else
                        adapter->mng_vlan_id = vid;
@@ -1482,7 +1482,7 @@ e1000_close(struct net_device *netdev)
        if ((adapter->hw.mng_cookie.status &
                          E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
             !(adapter->vlgrp &&
-                         adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
+              vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
                e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
        }
 
@@ -4998,10 +4998,7 @@ e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
        uint32_t vfta, index;
 
        e1000_irq_disable(adapter);
-
-       if (adapter->vlgrp)
-               adapter->vlgrp->vlan_devices[vid] = NULL;
-
+       vlan_group_set_device(adapter->vlgrp, vid, NULL);
        e1000_irq_enable(adapter);
 
        if ((adapter->hw.mng_cookie.status &
@@ -5027,7 +5024,7 @@ e1000_restore_vlan(struct e1000_adapter *adapter)
        if (adapter->vlgrp) {
                uint16_t vid;
                for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
-                       if (!adapter->vlgrp->vlan_devices[vid])
+                       if (!vlan_group_get_device(adapter->vlgrp, vid))
                                continue;
                        e1000_vlan_rx_add_vid(adapter->netdev, vid);
                }
index 88ad1c8bcee49d2a34f1d00aac8a0292a17deaab..0e4042bc0a48e44c570b54b7e205ff3a8a8e58eb 100644 (file)
@@ -1939,8 +1939,7 @@ static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        int index;
        u64 hret;
 
-       if (port->vgrp)
-               port->vgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(port->vgrp, vid, NULL);
 
        cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
        if (!cb1) {
index 1f83988a6a640c3b40f882e48fef8e11669d32e1..02b61b85b62cfe2efe80632c552b05d8147f8d3d 100644 (file)
@@ -1132,8 +1132,7 @@ static void gfar_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
 
        spin_lock_irqsave(&priv->rxlock, flags);
 
-       if (priv->vlgrp)
-               priv->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(priv->vgrp, vid, NULL);
 
        spin_unlock_irqrestore(&priv->rxlock, flags);
 }
index 0c36828893446dec2849c1f192081fc346b15871..afc2ec72529ee4ac22b76546dab7f3630d11aade 100644 (file)
@@ -2213,8 +2213,7 @@ ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
 
        ixgb_irq_disable(adapter);
 
-       if(adapter->vlgrp)
-               adapter->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(adapter->vlgrp, vid, NULL);
 
        ixgb_irq_enable(adapter);
 
@@ -2234,7 +2233,7 @@ ixgb_restore_vlan(struct ixgb_adapter *adapter)
        if(adapter->vlgrp) {
                uint16_t vid;
                for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
-                       if(!adapter->vlgrp->vlan_devices[vid])
+                       if(!vlan_group_get_device(adapter->vlgrp, vid))
                                continue;
                        ixgb_vlan_rx_add_vid(adapter->netdev, vid);
                }
index 568daeb3e9d8f56ac0e4b37249c5d2b9507dc66f..9ec6e9e54f47781b99d8c4402bc6930bd0807f6c 100644 (file)
@@ -514,8 +514,7 @@ static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid
 
        spin_lock_irq(&dev->misc_lock);
        spin_lock(&dev->tx_lock);
-       if (dev->vlgrp)
-               dev->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(dev->vlgrp, vid, NULL);
        spin_unlock(&dev->tx_lock);
        spin_unlock_irq(&dev->misc_lock);
 }
index 13cf06ee97f71389d82f591851be53a9deaac069..15d954e50cae6e816b534bf959c49a2920bef808 100644 (file)
@@ -890,8 +890,7 @@ static void rtl8169_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        unsigned long flags;
 
        spin_lock_irqsave(&tp->lock, flags);
-       if (tp->vlgrp)
-               tp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(tp->vlgrp, vid, NULL);
        spin_unlock_irqrestore(&tp->lock, flags);
 }
 
index 44bb2395af841cea83267c2911cb5dd33631aac6..46ebf141ee5a15b62d0c16eeb77b86dc939a31a9 100644 (file)
@@ -325,8 +325,7 @@ static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
        unsigned long flags;
 
        spin_lock_irqsave(&nic->tx_lock, flags);
-       if (nic->vlgrp)
-               nic->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(nic->vlgrp, vid, NULL);
        spin_unlock_irqrestore(&nic->tx_lock, flags);
 }
 
index 52edbd7ac17e6a134e2af1ca4fe3abd9e42c46ac..53839979cfb8fb1249dc27161b4cab2649fb994c 100644 (file)
@@ -1053,8 +1053,7 @@ static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
 
        sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF);
        sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF);
-       if (sky2->vlgrp)
-               sky2->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(sky2->vlgrp, vid, NULL);
 
        netif_tx_unlock_bh(dev);
 }
index bf873ea2579733f572f25886b9a0ab9d358cbf3d..8bba2e3da7e168d86c4c702d7b1da7ee4581bdee 100644 (file)
@@ -677,8 +677,7 @@ static void netdev_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        spin_lock(&np->lock);
        if (debug > 1)
                printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid);
-       if (np->vlgrp)
-               np->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(np->vlgrp, vid, NULL);
        set_rx_mode(dev);
        spin_unlock(&np->lock);
 }
@@ -1738,7 +1737,7 @@ static void set_rx_mode(struct net_device *dev)
                int vlan_count = 0;
                void __iomem *filter_addr = ioaddr + HashTable + 8;
                for (i = 0; i < VLAN_VID_MASK; i++) {
-                       if (np->vlgrp->vlan_devices[i]) {
+                       if (vlan_group_get_device(np->vlgrp, i)) {
                                if (vlan_count >= 32)
                                        break;
                                writew(cpu_to_be16(i), filter_addr);
index 26c6ac48288c86840e9ce87a6ba0004d2f5f5a95..8c8f9f4d47a599c8b0ef91fcfef65bfffda5df79 100644 (file)
@@ -9114,8 +9114,7 @@ static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
                tg3_netif_stop(tp);
 
        tg3_full_lock(tp, 0);
-       if (tp->vlgrp)
-               tp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(tp->vlgrp, vid, NULL);
        tg3_full_unlock(tp);
 
        if (netif_running(dev))
index 9781b16bb8b66ffe727dee15537f7a855bb16d42..0d91d094edd97bd63407e929682a58d2a2143b40 100644 (file)
@@ -746,8 +746,7 @@ typhoon_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
 {
        struct typhoon *tp = netdev_priv(dev);
        spin_lock_bh(&tp->state_lock);
-       if(tp->vlgrp)
-               tp->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(tp->vlgrp, vid, NULL);
        spin_unlock_bh(&tp->state_lock);
 }
 
index 2257e45594b3dde36ccebc4a4ee0985f91629025..d8a86f5af379fe3d2b0a17ed58b4de05c11fb085 100644 (file)
@@ -3654,7 +3654,7 @@ qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
                return rc;
 
        for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
-               if (vg->vlan_devices[i] == dev){
+               if (vlan_group_get_device(vg, i) == dev){
                        rc = QETH_VLAN_CARD;
                        break;
                }
@@ -5261,7 +5261,7 @@ qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
        QETH_DBF_TEXT(trace, 4, "frvaddr4");
 
        rcu_read_lock();
-       in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
+       in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
        if (!in_dev)
                goto out;
        for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
@@ -5288,7 +5288,7 @@ qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
 
        QETH_DBF_TEXT(trace, 4, "frvaddr6");
 
-       in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
+       in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
        if (!in6_dev)
                return;
        for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
@@ -5360,7 +5360,7 @@ qeth_layer2_process_vlans(struct qeth_card *card, int clear)
        if (!card->vlangrp)
                return;
        for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-               if (card->vlangrp->vlan_devices[i] == NULL)
+               if (vlan_group_get_device(card->vlangrp, i) == NULL)
                        continue;
                if (clear)
                        qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
@@ -5398,8 +5398,7 @@ qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        spin_lock_irqsave(&card->vlanlock, flags);
        /* unregister IP addresses of vlan device */
        qeth_free_vlan_addresses(card, vid);
-       if (card->vlangrp)
-               card->vlangrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(card->vlangrp, vid, NULL);
        spin_unlock_irqrestore(&card->vlanlock, flags);
        if (card->options.layer2)
                qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
@@ -5662,10 +5661,11 @@ qeth_add_vlan_mc(struct qeth_card *card)
 
        vg = card->vlangrp;
        for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-               if (vg->vlan_devices[i] == NULL ||
-                   !(vg->vlan_devices[i]->flags & IFF_UP))
+               struct net_device *netdev = vlan_group_get_device(vg, i);
+               if (netdev == NULL ||
+                   !(netdev->flags & IFF_UP))
                        continue;
-               in_dev = in_dev_get(vg->vlan_devices[i]);
+               in_dev = in_dev_get(netdev);
                if (!in_dev)
                        continue;
                read_lock(&in_dev->mc_list_lock);
@@ -5749,10 +5749,11 @@ qeth_add_vlan_mc6(struct qeth_card *card)
 
        vg = card->vlangrp;
        for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-               if (vg->vlan_devices[i] == NULL ||
-                   !(vg->vlan_devices[i]->flags & IFF_UP))
+               struct net_device *netdev = vlan_group_get_device(vg, i);
+               if (netdev == NULL ||
+                   !(netdev->flags & IFF_UP))
                        continue;
-               in_dev = in6_dev_get(vg->vlan_devices[i]);
+               in_dev = in6_dev_get(netdev);
                if (!in_dev)
                        continue;
                read_lock(&in_dev->lock);
index 35cb385735837a2e5b0eca166770bcc647c41fd9..d103580c72d26f769e6e9e9af6a7e9e2c1eeb0dd 100644 (file)
@@ -70,15 +70,34 @@ extern void vlan_ioctl_set(int (*hook)(void __user *));
  * depends on completely exhausting the VLAN identifier space.  Thus
  * it gives constant time look-up, but in many cases it wastes memory.
  */
-#define VLAN_GROUP_ARRAY_LEN 4096
+#define VLAN_GROUP_ARRAY_LEN          4096
+#define VLAN_GROUP_ARRAY_SPLIT_PARTS  8
+#define VLAN_GROUP_ARRAY_PART_LEN     (VLAN_GROUP_ARRAY_LEN/VLAN_GROUP_ARRAY_SPLIT_PARTS)
 
 struct vlan_group {
        int real_dev_ifindex; /* The ifindex of the ethernet(like) device the vlan is attached to. */
        struct hlist_node       hlist;  /* linked list */
-       struct net_device *vlan_devices[VLAN_GROUP_ARRAY_LEN];
+       struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS];
        struct rcu_head         rcu;
 };
 
+static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, int vlan_id)
+{
+       struct net_device **array;
+       array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
+       return array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN];
+}
+
+static inline void vlan_group_set_device(struct vlan_group *vg, int vlan_id,
+                                        struct net_device *dev)
+{
+       struct net_device **array;
+       if (!vg)
+               return;
+       array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
+       array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
+}
+
 struct vlan_priority_tci_mapping {
        unsigned long priority;
        unsigned short vlan_qos; /* This should be shifted when first set, so we only do it
@@ -160,7 +179,7 @@ static inline int __vlan_hwaccel_rx(struct sk_buff *skb,
                return NET_RX_DROP;
        }
 
-       skb->dev = grp->vlan_devices[vlan_tag & VLAN_VID_MASK];
+       skb->dev = vlan_group_get_device(grp, vlan_tag & VLAN_VID_MASK);
        if (skb->dev == NULL) {
                dev_kfree_skb_any(skb);
 
index c1c205fad4fbc34cde3ba9474a269a42337959af..eb1c71ed7dfe928c80e39701138fd7a0f52160d1 100644 (file)
@@ -184,14 +184,23 @@ struct net_device *__find_vlan_dev(struct net_device *real_dev,
        struct vlan_group *grp = __vlan_find_group(real_dev->ifindex);
 
        if (grp)
-               return grp->vlan_devices[VID];
+               return vlan_group_get_device(grp, VID);
 
        return NULL;
 }
 
+static void vlan_group_free(struct vlan_group *grp)
+{
+       int i;
+
+       for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++)
+               kfree(grp->vlan_devices_arrays[i]);
+       kfree(grp);
+}
+
 static void vlan_rcu_free(struct rcu_head *rcu)
 {
-       kfree(container_of(rcu, struct vlan_group, rcu));
+       vlan_group_free(container_of(rcu, struct vlan_group, rcu));
 }
 
 
@@ -223,7 +232,7 @@ static int unregister_vlan_dev(struct net_device *real_dev,
        ret = 0;
 
        if (grp) {
-               dev = grp->vlan_devices[vlan_id];
+               dev = vlan_group_get_device(grp, vlan_id);
                if (dev) {
                        /* Remove proc entry */
                        vlan_proc_rem_dev(dev);
@@ -237,7 +246,7 @@ static int unregister_vlan_dev(struct net_device *real_dev,
                                real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
                        }
 
-                       grp->vlan_devices[vlan_id] = NULL;
+                       vlan_group_set_device(grp, vlan_id, NULL);
                        synchronize_net();
 
 
@@ -251,7 +260,7 @@ static int unregister_vlan_dev(struct net_device *real_dev,
                         * group.
                         */
                        for (i = 0; i < VLAN_VID_MASK; i++)
-                               if (grp->vlan_devices[i])
+                               if (vlan_group_get_device(grp, i))
                                        break;
 
                        if (i == VLAN_VID_MASK) {
@@ -379,6 +388,7 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
        struct net_device *new_dev;
        struct net_device *real_dev; /* the ethernet device */
        char name[IFNAMSIZ];
+       int i;
 
 #ifdef VLAN_DEBUG
        printk(VLAN_DBG "%s: if_name -:%s:-     vid: %i\n",
@@ -544,6 +554,15 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
                if (!grp)
                        goto out_free_unregister;
 
+               for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) {
+                       grp->vlan_devices_arrays[i] = kzalloc(
+                               sizeof(struct net_device *)*VLAN_GROUP_ARRAY_PART_LEN,
+                               GFP_KERNEL);
+
+                       if (!grp->vlan_devices_arrays[i])
+                               goto out_free_arrays;
+               }
+
                /* printk(KERN_ALERT "VLAN REGISTER:  Allocated new group.\n"); */
                grp->real_dev_ifindex = real_dev->ifindex;
 
@@ -554,7 +573,7 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
                        real_dev->vlan_rx_register(real_dev, grp);
        }
 
-       grp->vlan_devices[VLAN_ID] = new_dev;
+       vlan_group_set_device(grp, VLAN_ID, new_dev);
 
        if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */
                printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n",
@@ -571,6 +590,9 @@ static struct net_device *register_vlan_device(const char *eth_IF_name,
 #endif
        return new_dev;
 
+out_free_arrays:
+       vlan_group_free(grp);
+
 out_free_unregister:
        unregister_netdev(new_dev);
        goto out_unlock;
@@ -606,7 +628,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
        case NETDEV_CHANGE:
                /* Propagate real device state to vlan devices */
                for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-                       vlandev = grp->vlan_devices[i];
+                       vlandev = vlan_group_get_device(grp, i);
                        if (!vlandev)
                                continue;
 
@@ -617,7 +639,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
        case NETDEV_DOWN:
                /* Put all VLANs for this dev in the down state too.  */
                for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-                       vlandev = grp->vlan_devices[i];
+                       vlandev = vlan_group_get_device(grp, i);
                        if (!vlandev)
                                continue;
 
@@ -632,7 +654,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
        case NETDEV_UP:
                /* Put all VLANs for this dev in the up state too.  */
                for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
-                       vlandev = grp->vlan_devices[i];
+                       vlandev = vlan_group_get_device(grp, i);
                        if (!vlandev)
                                continue;
 
@@ -649,7 +671,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
                for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
                        int ret;
 
-                       vlandev = grp->vlan_devices[i];
+                       vlandev = vlan_group_get_device(grp, i);
                        if (!vlandev)
                                continue;