aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-11-25 10:04:32 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2017-11-26 19:16:30 +0000
commit630b9741659b9a4b68c64ebbeb675761c6f26842 (patch)
treea47618e43d9b0598b1be3f8804fd5a139034c782 /src
parent020df9a7a55ebf9e06db3f24982efe5fdd68ebb9 (diff)
FIB: store the node type not the function pointer.
Saves memory at no appreciable performance cost. before: DBGvpp# sh fib mem FIB memory Name Size in-use /allocated totals Entry 80 7 / 150 560/12000 after: DBGvpp# sh fib mem FIB memory Name Size in-use /allocated totals Entry 72 7 / 7 504/504 Change-Id: Ic5d3920ceb57b54260dc9af2078c26484335fef1 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/fib/fib_entry.c2
-rw-r--r--src/vnet/fib/fib_node.c7
-rw-r--r--src/vnet/fib/fib_node.h13
-rw-r--r--src/vnet/fib/fib_path.c2
-rw-r--r--src/vnet/fib/fib_path_list.c2
-rw-r--r--src/vnet/geneve/geneve.c2
-rw-r--r--src/vnet/gre/interface.c2
-rw-r--r--src/vnet/map/map.c2
-rw-r--r--src/vnet/mfib/mfib_entry.c2
-rw-r--r--src/vnet/mpls/mpls_tunnel.c2
-rw-r--r--src/vnet/udp/udp_encap.c2
-rw-r--r--src/vnet/vxlan-gpe/vxlan_gpe.c2
-rw-r--r--src/vnet/vxlan/vxlan.c2
13 files changed, 11 insertions, 31 deletions
diff --git a/src/vnet/fib/fib_entry.c b/src/vnet/fib/fib_entry.c
index 74c6a4a587b..35716cacc29 100644
--- a/src/vnet/fib/fib_entry.c
+++ b/src/vnet/fib/fib_entry.c
@@ -191,9 +191,7 @@ format_fib_entry (u8 * s, va_list * args)
static fib_entry_t*
fib_entry_from_fib_node (fib_node_t *node)
{
-#if CLIB_DEBUG > 0
ASSERT(FIB_NODE_TYPE_ENTRY == node->fn_type);
-#endif
return ((fib_entry_t*)node);
}
diff --git a/src/vnet/fib/fib_node.c b/src/vnet/fib/fib_node.c
index db3e22bb3b8..54c300aec1e 100644
--- a/src/vnet/fib/fib_node.c
+++ b/src/vnet/fib/fib_node.c
@@ -183,14 +183,11 @@ void
fib_node_init (fib_node_t *node,
fib_node_type_t type)
{
-#if CLIB_DEBUG > 0
/**
- * The node's type. make sure we are dynamic/down casting correctly
+ * The node's type. used to retrieve the VFT.
*/
node->fn_type = type;
-#endif
node->fn_locks = 0;
- node->fn_vft = &fn_vfts[type];
node->fn_children = FIB_NODE_INDEX_INVALID;
}
@@ -213,7 +210,7 @@ fib_node_unlock (fib_node_t *node)
if (0 == node->fn_locks)
{
- node->fn_vft->fnv_last_lock(node);
+ fn_vfts[node->fn_type].fnv_last_lock(node);
}
}
diff --git a/src/vnet/fib/fib_node.h b/src/vnet/fib/fib_node.h
index d4c96c90b77..532efd54dee 100644
--- a/src/vnet/fib/fib_node.h
+++ b/src/vnet/fib/fib_node.h
@@ -52,7 +52,7 @@ typedef enum fib_node_type_t_ {
*/
FIB_NODE_TYPE_TEST,
FIB_NODE_TYPE_LAST = FIB_NODE_TYPE_TEST,
-} fib_node_type_t;
+} __attribute__ ((packed)) fib_node_type_t;
#define FIB_NODE_TYPE_MAX (FIB_NODE_TYPE_LAST + 1)
@@ -284,18 +284,21 @@ typedef struct fib_node_vft_t_ {
* Objects in the FIB form a graph.
*/
typedef struct fib_node_t_ {
-#if CLIB_DEBUG > 0
/**
* The node's type. make sure we are dynamic/down casting correctly
*/
fib_node_type_t fn_type;
-#endif
+
+ /**
+ * Some pad space the concrete/derived type is free to use
+ */
+ u16 fn_pad;
/**
* The node's VFT.
* we could store the type here instead, and lookup the VFT using that. But
* I like this better,
*/
- const fib_node_vft_t *fn_vft;
+// const fib_node_vft_t *fn_vft;
/**
* Vector of nodes that depend upon/use/share this node
@@ -309,6 +312,8 @@ typedef struct fib_node_t_ {
u32 fn_locks;
} fib_node_t;
+STATIC_ASSERT(sizeof(fib_node_t) == 12, "FIB node type is growing");
+
/**
* @brief
* Register the function table for a given type
diff --git a/src/vnet/fib/fib_path.c b/src/vnet/fib/fib_path.c
index 79291ca8c9a..c6677fb12f2 100644
--- a/src/vnet/fib/fib_path.c
+++ b/src/vnet/fib/fib_path.c
@@ -439,9 +439,7 @@ fib_path_get_node (fib_node_index_t index)
static fib_path_t*
fib_path_from_fib_node (fib_node_t *node)
{
-#if CLIB_DEBUG > 0
ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
-#endif
return ((fib_path_t*)node);
}
diff --git a/src/vnet/fib/fib_path_list.c b/src/vnet/fib/fib_path_list.c
index f9477406ed3..597a700a448 100644
--- a/src/vnet/fib/fib_path_list.c
+++ b/src/vnet/fib/fib_path_list.c
@@ -116,9 +116,7 @@ fib_path_list_get_node (fib_node_index_t index)
static fib_path_list_t*
fib_path_list_from_fib_node (fib_node_t *node)
{
-#if CLIB_DEBUG > 0
ASSERT(FIB_NODE_TYPE_PATH_LIST == node->fn_type);
-#endif
return ((fib_path_list_t*)node);
}
diff --git a/src/vnet/geneve/geneve.c b/src/vnet/geneve/geneve.c
index 25bf4a49741..01f0cd446f3 100644
--- a/src/vnet/geneve/geneve.c
+++ b/src/vnet/geneve/geneve.c
@@ -143,9 +143,7 @@ geneve_tunnel_restack_dpo (geneve_tunnel_t * t)
static geneve_tunnel_t *
geneve_tunnel_from_fib_node (fib_node_t * node)
{
-#if (CLIB_DEBUG > 0)
ASSERT (FIB_NODE_TYPE_GENEVE_TUNNEL == node->fn_type);
-#endif
return ((geneve_tunnel_t *) (((char *) node) -
STRUCT_OFFSET_OF (geneve_tunnel_t, node)));
}
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index d574e596779..ae5da93e0f0 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -153,9 +153,7 @@ gre_tunnel_db_remove (const gre_tunnel_t *t)
static gre_tunnel_t *
gre_tunnel_from_fib_node (fib_node_t *node)
{
-#if (CLIB_DEBUG > 0)
ASSERT(FIB_NODE_TYPE_GRE_TUNNEL == node->fn_type);
-#endif
return ((gre_tunnel_t*) (((char*)node) -
STRUCT_OFFSET_OF(gre_tunnel_t, node)));
}
diff --git a/src/vnet/map/map.c b/src/vnet/map/map.c
index 6d18a069459..e3886d7e7e6 100644
--- a/src/vnet/map/map.c
+++ b/src/vnet/map/map.c
@@ -356,9 +356,7 @@ map_last_lock_gone (fib_node_t * node)
static map_main_pre_resolved_t *
map_from_fib_node (fib_node_t * node)
{
-#if (CLIB_DEBUG > 0)
ASSERT (FIB_NODE_TYPE_MAP_E == node->fn_type);
-#endif
return ((map_main_pre_resolved_t *)
(((char *) node) -
STRUCT_OFFSET_OF (map_main_pre_resolved_t, node)));
diff --git a/src/vnet/mfib/mfib_entry.c b/src/vnet/mfib/mfib_entry.c
index aaecf0f6eb6..6c356c6b267 100644
--- a/src/vnet/mfib/mfib_entry.c
+++ b/src/vnet/mfib/mfib_entry.c
@@ -238,9 +238,7 @@ format_mfib_entry (u8 * s, va_list * args)
static mfib_entry_t*
mfib_entry_from_fib_node (fib_node_t *node)
{
-#if CLIB_DEBUG > 0
ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type);
-#endif
return ((mfib_entry_t*)node);
}
diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c
index a9f32d4e48f..efd9e2dbc84 100644
--- a/src/vnet/mpls/mpls_tunnel.c
+++ b/src/vnet/mpls/mpls_tunnel.c
@@ -961,9 +961,7 @@ VLIB_CLI_COMMAND (show_mpls_tunnel_command, static) = {
static mpls_tunnel_t *
mpls_tunnel_from_fib_node (fib_node_t *node)
{
-#if (CLIB_DEBUG > 0)
ASSERT(FIB_NODE_TYPE_MPLS_TUNNEL == node->fn_type);
-#endif
return ((mpls_tunnel_t*) (((char*)node) -
STRUCT_OFFSET_OF(mpls_tunnel_t, mt_node)));
}
diff --git a/src/vnet/udp/udp_encap.c b/src/vnet/udp/udp_encap.c
index 98b824ba866..2999d4a73ce 100644
--- a/src/vnet/udp/udp_encap.c
+++ b/src/vnet/udp/udp_encap.c
@@ -325,9 +325,7 @@ format_udp_encap (u8 * s, va_list * args)
static udp_encap_t *
udp_encap_from_fib_node (fib_node_t * node)
{
-#if (CLIB_DEBUG > 0)
ASSERT (FIB_NODE_TYPE_UDP_ENCAP == node->fn_type);
-#endif
return ((udp_encap_t *) (((char *) node) -
STRUCT_OFFSET_OF (udp_encap_t, ue_fib_node)));
}
diff --git a/src/vnet/vxlan-gpe/vxlan_gpe.c b/src/vnet/vxlan-gpe/vxlan_gpe.c
index 462c79a0d19..b13a7343ddd 100644
--- a/src/vnet/vxlan-gpe/vxlan_gpe.c
+++ b/src/vnet/vxlan-gpe/vxlan_gpe.c
@@ -183,9 +183,7 @@ vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_t * t)
static vxlan_gpe_tunnel_t *
vxlan_gpe_tunnel_from_fib_node (fib_node_t *node)
{
-#if (CLIB_DEBUG > 0)
ASSERT(FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
-#endif
return ((vxlan_gpe_tunnel_t*) (((char*)node) -
STRUCT_OFFSET_OF(vxlan_gpe_tunnel_t, node)));
}
diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c
index dc973372145..a6e799f7649 100644
--- a/src/vnet/vxlan/vxlan.c
+++ b/src/vnet/vxlan/vxlan.c
@@ -138,9 +138,7 @@ vxlan_tunnel_restack_dpo(vxlan_tunnel_t * t)
static vxlan_tunnel_t *
vxlan_tunnel_from_fib_node (fib_node_t *node)
{
-#if (CLIB_DEBUG > 0)
ASSERT(FIB_NODE_TYPE_VXLAN_TUNNEL == node->fn_type);
-#endif
return ((vxlan_tunnel_t*) (((char*)node) -
STRUCT_OFFSET_OF(vxlan_tunnel_t, node)));
}