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.
This commit is contained in:
Remi Tricot-Le Breton 2023-11-16 17:38:27 +01:00 committed by William Lallemand
parent 4fe6c1365d
commit 45a2ff0f4a
4 changed files with 9 additions and 22 deletions

View File

@ -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 */

View File

@ -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)

View File

@ -17,8 +17,6 @@
#include <haproxy/list.h>
#include <haproxy/shctx.h>
int use_shared_mem = 0;
/*
* Reserve a new row if <first> is null, put it in the hotlist, set the refcount to 1
* or append new blocks to the row with <first> 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) {

View File

@ -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");