]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: shctx: Remove 'use_shared_mem' variable
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 16 Nov 2023 16:38:27 +0000 (17:38 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 16 Nov 2023 18:35:10 +0000 (19:35 +0100)
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.

include/haproxy/shctx.h
src/cache.c
src/shctx.c
src/ssl_sock.c

index f318f26db531b4bc6859acfe8891ecd17e317f1e..a57cf156765c235a490b76d16622a2872770bf89 100644 (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 */
index 5ae3ef0851dfc2b73c72b6a8938a82a3bb68434a..3d638303b4070e61a67c0c55d655b9afe5589cf9 100644 (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)
index 1a57e1c5899208ee0b85dfabf486ed954082b86a..79248ef57bf84c3cf2d0a9e21ac6f7cfbc7aac53 100644 (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) {
index ddc7bce186f2a068397264e71d6323b6ec73b57e..307825b7c29bbc95b09b1222643d4a4f581184e5 100644 (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");