From: Emeric Brun Date: Tue, 25 Sep 2012 09:11:16 +0000 (+0200) Subject: MINOR: ssl: add build param USE_PRIVATE_CACHE to build cache without shared memory X-Git-Tag: v1.5-dev13~239 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9faf071acb1fa8ba514bc7a55ab4e7ff51c29362;p=thirdparty%2Fhaproxy.git MINOR: ssl: add build param USE_PRIVATE_CACHE to build cache without shared memory 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. --- diff --git a/Makefile b/Makefile index 745319817b..f0533a70af 100644 --- 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 diff --git a/include/proto/shctx.h b/include/proto/shctx.h index 862f6a057a..6705664d55 100644 --- a/include/proto/shctx.h +++ b/include/proto/shctx.h @@ -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); diff --git a/src/shctx.c b/src/shctx.c index 23992a6f26..2db8f790fe 100644 --- a/src/shctx.c +++ b/src/shctx.c @@ -12,6 +12,7 @@ */ #include +#ifndef USE_PRIVATE_CACHE #ifdef USE_SYSCALL_FUTEX #include #ifndef u32 @@ -22,6 +23,7 @@ #else /* USE_SYSCALL_FUTEX */ #include #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));