FIB: store the node type not the function pointer. 68/9568/2
authorNeale Ranns <nranns@cisco.com>
Sat, 25 Nov 2017 18:04:32 +0000 (10:04 -0800)
committerDamjan Marion <dmarion.lists@gmail.com>
Sun, 26 Nov 2017 19:16:30 +0000 (19:16 +0000)
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>
13 files changed:
src/vnet/fib/fib_entry.c
src/vnet/fib/fib_node.c
src/vnet/fib/fib_node.h
src/vnet/fib/fib_path.c
src/vnet/fib/fib_path_list.c
src/vnet/geneve/geneve.c
src/vnet/gre/interface.c
src/vnet/map/map.c
src/vnet/mfib/mfib_entry.c
src/vnet/mpls/mpls_tunnel.c
src/vnet/udp/udp_encap.c
src/vnet/vxlan-gpe/vxlan_gpe.c
src/vnet/vxlan/vxlan.c

index 74c6a4a..35716ca 100644 (file)
@@ -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);
 }
 
index db3e22b..54c300a 100644 (file)
@@ -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);
     }
 }
 
index d4c96c9..532efd5 100644 (file)
@@ -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
index 79291ca..c6677fb 100644 (file)
@@ -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);
 }
 
index f947740..597a700 100644 (file)
@@ -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);
 }
 
index 25bf4a4..01f0cd4 100644 (file)
@@ -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)));
 }
index d574e59..ae5da93 100644 (file)
@@ -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)));
 }
index 6d18a06..e3886d7 100644 (file)
@@ -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)));
index aaecf0f..6c356c6 100644 (file)
@@ -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);
 }
 
index a9f32d4..efd9e2d 100644 (file)
@@ -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)));
 }
index 98b824b..2999d4a 100644 (file)
@@ -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)));
 }
index 462c79a..b13a734 100644 (file)
@@ -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)));
 }
index dc97337..a6e799f 100644 (file)
@@ -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)));
 }