summaryrefslogtreecommitdiff
path: root/net/8021q/vlan.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2008-03-26 16:27:22 -0700
committerDavid S. Miller <davem@davemloft.net>2008-03-26 16:27:22 -0700
commit67727184f28c38d06013c6659560bb046c1d9f9c (patch)
treefce5871c7fe554e05aa61fcc2d2d86afe7befdbc /net/8021q/vlan.c
parent789e41e6f496022ac1639aaae38ea1943606a9d0 (diff)
downloadlinux-exynos-67727184f28c38d06013c6659560bb046c1d9f9c.tar.gz
linux-exynos-67727184f28c38d06013c6659560bb046c1d9f9c.tar.bz2
linux-exynos-67727184f28c38d06013c6659560bb046c1d9f9c.zip
[VLAN]: Reduce memory consumed by vlan_groups
Currently each vlan_groupd contains 8 pointers on arrays with 512 pointers on struct net_device each :) Such a construction "in many cases ... wastes memory". My proposal is to allow for some of these arrays pointers be NULL, meaning that there are no devices in it. When a new device is added to the vlan_group, the appropriate array is allocated. The check in vlan_group_get_device's is safe, since the pointer vg->vlan_devices_arrays[x] can only switch from NULL to not-NULL. The vlan_group_prealloc_vid() is guarded with rtnl lock and is also safe. I've checked (I hope that) all the places, that use these arrays and found, that the register_vlan_dev is the only place, that can put a vlan device on an empty vlan_group. Rough calculations shows, that after the patch a setup with a single vlan dev (or up to 512 vlans with sequential vids) will occupy approximately 8 times less memory. The question I have is - does this patch makes sense, or a totally new structures are required to store the vlan_devs? Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'net/8021q/vlan.c')
-rw-r--r--net/8021q/vlan.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index c35dc230365c..694be86e4490 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -106,29 +106,35 @@ static void vlan_group_free(struct vlan_group *grp)
static struct vlan_group *vlan_group_alloc(int ifindex)
{
struct vlan_group *grp;
- unsigned int size;
- unsigned int i;
grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
if (!grp)
return NULL;
- size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
-
- for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) {
- grp->vlan_devices_arrays[i] = kzalloc(size, GFP_KERNEL);
- if (!grp->vlan_devices_arrays[i])
- goto err;
- }
-
grp->real_dev_ifindex = ifindex;
hlist_add_head_rcu(&grp->hlist,
&vlan_group_hash[vlan_grp_hashfn(ifindex)]);
return grp;
+}
-err:
- vlan_group_free(grp);
- return NULL;
+static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid)
+{
+ struct net_device **array;
+ unsigned int size;
+
+ ASSERT_RTNL();
+
+ array = vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN];
+ if (array != NULL)
+ return 0;
+
+ size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
+ array = kzalloc(size, GFP_KERNEL);
+ if (array == NULL)
+ return -ENOBUFS;
+
+ vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN] = array;
+ return 0;
}
static void vlan_rcu_free(struct rcu_head *rcu)
@@ -247,6 +253,10 @@ int register_vlan_dev(struct net_device *dev)
return -ENOBUFS;
}
+ err = vlan_group_prealloc_vid(grp, vlan_id);
+ if (err < 0)
+ goto out_free_group;
+
err = register_netdevice(dev);
if (err < 0)
goto out_free_group;