From 630b9741659b9a4b68c64ebbeb675761c6f26842 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Sat, 25 Nov 2017 10:04:32 -0800 Subject: 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 --- src/vnet/fib/fib_entry.c | 2 -- src/vnet/fib/fib_node.c | 7 ++----- src/vnet/fib/fib_node.h | 13 +++++++++---- src/vnet/fib/fib_path.c | 2 -- src/vnet/fib/fib_path_list.c | 2 -- 5 files changed, 11 insertions(+), 15 deletions(-) (limited to 'src/vnet/fib') 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); } -- cgit 1.2.3-korg