From 6d733a93b2eb9c16196ee17d5cdc77db21589571 Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Wed, 4 Nov 2020 11:41:05 +0100 Subject: cnat: remove rwlock on ts Type: improvement Remove rwlock contention on timestamps. ~10% pps with 10k sessions. Use fixed-size-pools of increasing sizes starting with 4K, and with a x2 step each time. We don't free/shrink allocated pools. Change-Id: I5fea51faba40430106c823275a6356e81709d118 Signed-off-by: Nathan Skrzypczak --- src/plugins/cnat/cnat_types.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/plugins/cnat/cnat_types.h') diff --git a/src/plugins/cnat/cnat_types.h b/src/plugins/cnat/cnat_types.h index abae83af59a..d229d21adae 100644 --- a/src/plugins/cnat/cnat_types.h +++ b/src/plugins/cnat/cnat_types.h @@ -148,9 +148,6 @@ typedef struct cnat_main_ /* delay in seconds between two scans of session/clients tables */ f64 scanner_timeout; - /* Lock for the timestamp pool */ - clib_rwlock_t ts_lock; - /* Index of the scanner process node */ uword scanner_node_index; @@ -175,6 +172,23 @@ typedef struct cnat_timestamp_t_ u16 refcnt; } cnat_timestamp_t; +/* Create the first pool with 1 << CNAT_TS_BASE_SIZE elts */ +#define CNAT_TS_BASE_SIZE (8) +/* reserve the top CNAT_TS_MPOOL_BITS bits for finding the pool */ +#define CNAT_TS_MPOOL_BITS (6) + +typedef struct cnat_timestamp_mpool_t_ +{ + /* Increasing fixed size pools of timestamps */ + cnat_timestamp_t *ts_pools[1 << CNAT_TS_MPOOL_BITS]; + /* Bitmap of pools with free space */ + uword *ts_free; + /* Index of next pool to init */ + u8 next_empty_pool_idx; + /* ts creation lock */ + clib_spinlock_t ts_lock; +} cnat_timestamp_mpool_t; + typedef struct cnat_node_ctx_ { f64 now; @@ -188,8 +202,7 @@ extern u8 *format_cnat_endpoint (u8 * s, va_list * args); extern uword unformat_cnat_ep_tuple (unformat_input_t * input, va_list * args); extern uword unformat_cnat_ep (unformat_input_t * input, va_list * args); -extern cnat_timestamp_t *cnat_timestamps; -extern fib_source_t cnat_fib_source; +extern cnat_timestamp_mpool_t cnat_timestamps; extern cnat_main_t cnat_main; extern char *cnat_error_strings[]; -- cgit 1.2.3-korg