From: Remi Tricot-Le Breton Date: Thu, 16 Nov 2023 16:38:27 +0000 (+0100) Subject: MINOR: shctx: Remove 'use_shared_mem' variable X-Git-Tag: v2.9-dev10~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45a2ff0f4ae9e43f98e5602971748e17f8a3a3aa;p=thirdparty%2Fhaproxy.git MINOR: shctx: Remove 'use_shared_mem' variable This global variable was used to avoid using locks on shared_contexts in the unlikely case of nbthread==1. Since the locks do not do anything when USE_THREAD is not defined, it will be more beneficial to simply remove this variable and the systematic test on its value in the shared context locking functions. --- diff --git a/include/haproxy/shctx.h b/include/haproxy/shctx.h index f318f26db5..a57cf15676 100644 --- a/include/haproxy/shctx.h +++ b/include/haproxy/shctx.h @@ -21,7 +21,7 @@ int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize, unsigned int maxobjsz, - int extra, int shared); + int extra); struct shared_block *shctx_row_reserve_hot(struct shared_context *shctx, struct shared_block *last, int data_len); void shctx_row_detach(struct shared_context *shctx, struct shared_block *first); @@ -35,27 +35,21 @@ int shctx_row_data_get(struct shared_context *shctx, struct shared_block *first, /* Lock functions */ -extern int use_shared_mem; - static inline void shctx_rdlock(struct shared_context *shctx) { - if (use_shared_mem) - HA_RWLOCK_RDLOCK(SHCTX_LOCK, &shctx->lock); + HA_RWLOCK_RDLOCK(SHCTX_LOCK, &shctx->lock); } static inline void shctx_rdunlock(struct shared_context *shctx) { - if (use_shared_mem) - HA_RWLOCK_RDUNLOCK(SHCTX_LOCK, &shctx->lock); + HA_RWLOCK_RDUNLOCK(SHCTX_LOCK, &shctx->lock); } static inline void shctx_wrlock(struct shared_context *shctx) { - if (use_shared_mem) - HA_RWLOCK_WRLOCK(SHCTX_LOCK, &shctx->lock); + HA_RWLOCK_WRLOCK(SHCTX_LOCK, &shctx->lock); } static inline void shctx_wrunlock(struct shared_context *shctx) { - if (use_shared_mem) - HA_RWLOCK_WRUNLOCK(SHCTX_LOCK, &shctx->lock); + HA_RWLOCK_WRUNLOCK(SHCTX_LOCK, &shctx->lock); } /* List Macros */ diff --git a/src/cache.c b/src/cache.c index 5ae3ef0851..3d638303b4 100644 --- a/src/cache.c +++ b/src/cache.c @@ -2299,7 +2299,7 @@ int post_check_cache() list_for_each_entry_safe(cache_config, back, &caches_config, list) { ret_shctx = shctx_init(&shctx, cache_config->maxblocks, CACHE_BLOCKSIZE, - cache_config->maxobjsz, sizeof(struct cache), 1); + cache_config->maxobjsz, sizeof(struct cache)); if (ret_shctx <= 0) { if (ret_shctx == SHCTX_E_INIT_LOCK) diff --git a/src/shctx.c b/src/shctx.c index 1a57e1c589..79248ef57b 100644 --- a/src/shctx.c +++ b/src/shctx.c @@ -17,8 +17,6 @@ #include #include -int use_shared_mem = 0; - /* * Reserve a new row if is null, put it in the hotlist, set the refcount to 1 * or append new blocks to the row with as first block if non null. @@ -271,13 +269,13 @@ int shctx_row_data_get(struct shared_context *shctx, struct shared_block *first, * and 0 if cache is already allocated. */ int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize, - unsigned int maxobjsz, int extra, int shared) + unsigned int maxobjsz, int extra) { int i; struct shared_context *shctx; int ret; void *cur; - int maptype = MAP_PRIVATE; + int maptype = MAP_SHARED; if (maxblocks <= 0) return 0; @@ -286,11 +284,6 @@ int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize, blocksize = (blocksize + sizeof(void *) - 1) & -sizeof(void *); extra = (extra + sizeof(void *) - 1) & -sizeof(void *); - if (shared) { - maptype = MAP_SHARED; - use_shared_mem = 1; - } - shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context) + extra + (maxblocks * (sizeof(struct shared_block) + blocksize)), PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0); if (!shctx || shctx == MAP_FAILED) { diff --git a/src/ssl_sock.c b/src/ssl_sock.c index ddc7bce186..307825b7c2 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -5425,7 +5425,7 @@ int ssl_sock_prepare_bind_conf(struct bind_conf *bind_conf) if (!ssl_shctx && global.tune.sslcachesize) { alloc_ctx = shctx_init(&ssl_shctx, global.tune.sslcachesize, sizeof(struct sh_ssl_sess_hdr) + SHSESS_BLOCK_MIN_SIZE, -1, - sizeof(*sh_ssl_sess_tree), (global.nbthread > 1)); + sizeof(*sh_ssl_sess_tree)); if (alloc_ctx <= 0) { if (alloc_ctx == SHCTX_E_INIT_LOCK) ha_alert("Unable to initialize the lock for the shared SSL session cache. You can retry using the global statement 'tune.ssl.force-private-cache' but it could increase CPU usage due to renegotiations if nbproc > 1.\n");