]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: add build param USE_PRIVATE_CACHE to build cache without shared memory
authorEmeric Brun <ebrun@exceliance.fr>
Tue, 25 Sep 2012 09:11:16 +0000 (11:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Oct 2012 06:34:38 +0000 (08:34 +0200)
It removes dependencies with futex or mutex but ssl performances decrease
using nbproc > 1 because switching process force session renegotiation.

This can be useful on small systems which never intend to run in multi-process
mode.

Makefile
include/proto/shctx.h
src/shctx.c

index 745319817b581e650e1e356c45837792b7da7586..f0533a70af8aaaa042d42748f5c8d8dc17a54219 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@
 #   USE_NETFILTER        : enable netfilter on Linux. Automatic.
 #   USE_PCRE             : enable use of libpcre for regex. Recommended.
 #   USE_POLL             : enable poll(). Automatic.
+#   USE_PRIVATE_CACHE    : disable shared memory cache of ssl sessions.
 #   USE_REGPARM          : enable regparm optimization. Recommended on x86.
 #   USE_SEPOLL           : enable speculative epoll(). Automatic.
 #   USE_STATIC_PCRE      : enable static libpcre. Recommended.
@@ -476,12 +477,16 @@ BUILD_OPTIONS   += $(call ignore_implicit,USE_OPENSSL)
 OPTIONS_CFLAGS  += -DUSE_OPENSSL
 OPTIONS_LDFLAGS += -lssl -lcrypto
 OPTIONS_OBJS  += src/ssl_sock.o src/shctx.o
+ifneq ($(USE_PRIVATE_CACHE),)
+OPTIONS_CFLAGS  += -DUSE_PRIVATE_CACHE
+else
 ifneq ($(USE_FUTEX),)
 OPTIONS_CFLAGS  += -DUSE_SYSCALL_FUTEX
 else
 OPTIONS_LDFLAGS += -lpthread
 endif
 endif
+endif
 
 ifneq ($(USE_PCRE),)
 # PCREDIR is the directory hosting include/pcre.h and lib/libpcre.*. It is
index 862f6a057a817e8164f5557245bc2e6097b307f7..6705664d55d2cd3d7f4b7d16df6a9c8e8cafbf38 100644 (file)
@@ -56,7 +56,8 @@ void shctx_sess_add(const unsigned char *session, unsigned int session_len, long
 /* Allocate shared memory context.
  * size is maximum cached sessions.
  *      if set less or equal to 0, SHCTX_DEFAULT_SIZE is used.
- * use_shared_memory is set to 1 to use a mapped share memory
+ * set use_shared_memory to 1 to use a mapped shared memory insteed
+ * of private. (ignored if compiled whith USE_PRIVATE_CACHE=1)
  * Returns: -1 on alloc failure, size if it performs context alloc,
  * and 0 if cache is already allocated */
 int shared_context_init(int size, int use_shared_memory);
index 23992a6f26192101cf0a428bbc12e46574da52ec..2db8f790feaba0646892c0dd34ff598c1161a22e 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <sys/mman.h>
+#ifndef USE_PRIVATE_CACHE
 #ifdef USE_SYSCALL_FUTEX
 #include <unistd.h>
 #ifndef u32
@@ -22,6 +23,7 @@
 #else /* USE_SYSCALL_FUTEX */
 #include <pthread.h>
 #endif /* USE_SYSCALL_FUTEX */
+#endif
 
 #include "ebmbtree.h"
 #include "proto/shctx.h"
@@ -38,10 +40,12 @@ struct shared_session {
 
 
 struct shared_context {
+#ifndef USE_PRIVATE_CACHE
 #ifdef USE_SYSCALL_FUTEX
        unsigned int waiters;
 #else /* USE_SYSCALL_FUTEX */
        pthread_mutex_t mutex;
+#endif
 #endif
        struct shared_session active;
        struct shared_session free;
@@ -49,12 +53,19 @@ struct shared_context {
 
 /* Static shared context */
 static struct shared_context *shctx = NULL;
+#ifndef USE_PRIVATE_CACHE
 static int use_shared_mem = 0;
+#endif
 
 /* Callbacks */
 static void (*shared_session_new_cbk)(unsigned char *session, unsigned int session_len, long cdate);
 
 /* Lock functions */
+#ifdef USE_PRIVATE_CACHE
+#define shared_context_lock(v)
+#define shared_context_unlock(v)
+
+#else
 #ifdef USE_SYSCALL_FUTEX
 #if defined (__i586__) || defined (__x86_64__)
 static inline unsigned int xchg(unsigned int *ptr, unsigned int x)
@@ -140,6 +151,7 @@ static inline void _shared_context_unlock(void)
 
 #define shared_context_unlock(v) if (use_shared_mem) pthread_mutex_unlock(&shctx->mutex)
 
+#endif
 #endif
 
 /* List Macros */
@@ -365,9 +377,11 @@ void shsess_set_new_cbk(void (*func)(unsigned char *, unsigned int, long))
 int shared_context_init(int size, int shared)
 {
        int i;
+#ifndef USE_PRIVATE_CACHE
 #ifndef USE_SYSCALL_FUTEX
        pthread_mutexattr_t attr;
 #endif /* USE_SYSCALL_FUTEX */
+#endif
        struct shared_session *prev,*cur;
        int maptype = MAP_PRIVATE;
 
@@ -377,8 +391,10 @@ int shared_context_init(int size, int shared)
        if (size<=0)
                size = SHCTX_DEFAULT_SIZE;
 
+#ifndef USE_PRIVATE_CACHE
        if (shared)
                maptype = MAP_SHARED;
+#endif
 
        shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context)+(size*sizeof(struct shared_session)),
                                              PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0);
@@ -387,6 +403,7 @@ int shared_context_init(int size, int shared)
                return -1;
        }
 
+#ifndef USE_PRIVATE_CACHE
 #ifdef USE_SYSCALL_FUTEX
        shctx->waiters = 0;
 #else
@@ -396,6 +413,7 @@ int shared_context_init(int size, int shared)
 #endif
        if (maptype == MAP_SHARED)
                use_shared_mem = 1;
+#endif
 
        memset(&shctx->active.key, 0, sizeof(struct ebmb_node));
        memset(&shctx->free.key, 0, sizeof(struct ebmb_node));