Skip to content

Commit 6261d98

Browse files
shemmingerdavem330
authored andcommitted
ip_tunnel: embed hash list head
The IP tunnel hash heads can be embedded in the per-net structure since it is a fixed size. Reduce the size so that the total structure fits in a page size. The original size was overly large, even NETDEV_HASHBITS is only 8 bits! Also, add some white space for readability. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Pravin B Shelar <pshelar@nicira.com>. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8a56d24 commit 6261d98

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎include/net/ip_tunnels.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ struct tnl_ptk_info {
8686
#define PACKET_RCVD 0
8787
#define PACKET_REJECT 1
8888

89-
#define IP_TNL_HASH_BITS 10
89+
#define IP_TNL_HASH_BITS 7
9090
#define IP_TNL_HASH_SIZE (1 << IP_TNL_HASH_BITS)
9191

9292
struct ip_tunnel_net {
93-
struct hlist_head *tunnels;
9493
struct net_device *fb_tunnel_dev;
94+
struct hlist_head tunnels[IP_TNL_HASH_SIZE];
9595
};
9696

9797
#ifdef CONFIG_INET

‎net/ipv4/ip_tunnel.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,26 +838,26 @@ int ip_tunnel_init_net(struct net *net, int ip_tnl_net_id,
838838
{
839839
struct ip_tunnel_net *itn = net_generic(net, ip_tnl_net_id);
840840
struct ip_tunnel_parm parms;
841+
unsigned int i;
841842

842-
itn->tunnels = kzalloc(IP_TNL_HASH_SIZE * sizeof(struct hlist_head), GFP_KERNEL);
843-
if (!itn->tunnels)
844-
return -ENOMEM;
843+
for (i = 0; i < IP_TNL_HASH_SIZE; i++)
844+
INIT_HLIST_HEAD(&itn->tunnels[i]);
845845

846846
if (!ops) {
847847
itn->fb_tunnel_dev = NULL;
848848
return 0;
849849
}
850+
850851
memset(&parms, 0, sizeof(parms));
851852
if (devname)
852853
strlcpy(parms.name, devname, IFNAMSIZ);
853854

854855
rtnl_lock();
855856
itn->fb_tunnel_dev = __ip_tunnel_create(net, ops, &parms);
856857
rtnl_unlock();
857-
if (IS_ERR(itn->fb_tunnel_dev)) {
858-
kfree(itn->tunnels);
858+
859+
if (IS_ERR(itn->fb_tunnel_dev))
859860
return PTR_ERR(itn->fb_tunnel_dev);
860-
}
861861

862862
return 0;
863863
}
@@ -887,7 +887,6 @@ void ip_tunnel_delete_net(struct ip_tunnel_net *itn)
887887
ip_tunnel_destroy(itn, &list);
888888
unregister_netdevice_many(&list);
889889
rtnl_unlock();
890-
kfree(itn->tunnels);
891890
}
892891
EXPORT_SYMBOL_GPL(ip_tunnel_delete_net);
893892

0 commit comments

Comments
 (0)