mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-12-11 04:31:01 +01:00
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.
This commit is contained in:
parent
4b3091e54e
commit
9faf071acb
5
Makefile
5
Makefile
@ -15,6 +15,7 @@
|
|||||||
# USE_NETFILTER : enable netfilter on Linux. Automatic.
|
# USE_NETFILTER : enable netfilter on Linux. Automatic.
|
||||||
# USE_PCRE : enable use of libpcre for regex. Recommended.
|
# USE_PCRE : enable use of libpcre for regex. Recommended.
|
||||||
# USE_POLL : enable poll(). Automatic.
|
# USE_POLL : enable poll(). Automatic.
|
||||||
|
# USE_PRIVATE_CACHE : disable shared memory cache of ssl sessions.
|
||||||
# USE_REGPARM : enable regparm optimization. Recommended on x86.
|
# USE_REGPARM : enable regparm optimization. Recommended on x86.
|
||||||
# USE_SEPOLL : enable speculative epoll(). Automatic.
|
# USE_SEPOLL : enable speculative epoll(). Automatic.
|
||||||
# USE_STATIC_PCRE : enable static libpcre. Recommended.
|
# USE_STATIC_PCRE : enable static libpcre. Recommended.
|
||||||
@ -476,12 +477,16 @@ BUILD_OPTIONS += $(call ignore_implicit,USE_OPENSSL)
|
|||||||
OPTIONS_CFLAGS += -DUSE_OPENSSL
|
OPTIONS_CFLAGS += -DUSE_OPENSSL
|
||||||
OPTIONS_LDFLAGS += -lssl -lcrypto
|
OPTIONS_LDFLAGS += -lssl -lcrypto
|
||||||
OPTIONS_OBJS += src/ssl_sock.o src/shctx.o
|
OPTIONS_OBJS += src/ssl_sock.o src/shctx.o
|
||||||
|
ifneq ($(USE_PRIVATE_CACHE),)
|
||||||
|
OPTIONS_CFLAGS += -DUSE_PRIVATE_CACHE
|
||||||
|
else
|
||||||
ifneq ($(USE_FUTEX),)
|
ifneq ($(USE_FUTEX),)
|
||||||
OPTIONS_CFLAGS += -DUSE_SYSCALL_FUTEX
|
OPTIONS_CFLAGS += -DUSE_SYSCALL_FUTEX
|
||||||
else
|
else
|
||||||
OPTIONS_LDFLAGS += -lpthread
|
OPTIONS_LDFLAGS += -lpthread
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(USE_PCRE),)
|
ifneq ($(USE_PCRE),)
|
||||||
# PCREDIR is the directory hosting include/pcre.h and lib/libpcre.*. It is
|
# PCREDIR is the directory hosting include/pcre.h and lib/libpcre.*. It is
|
||||||
|
|||||||
@ -56,7 +56,8 @@ void shctx_sess_add(const unsigned char *session, unsigned int session_len, long
|
|||||||
/* Allocate shared memory context.
|
/* Allocate shared memory context.
|
||||||
* size is maximum cached sessions.
|
* size is maximum cached sessions.
|
||||||
* if set less or equal to 0, SHCTX_DEFAULT_SIZE is used.
|
* 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,
|
* Returns: -1 on alloc failure, size if it performs context alloc,
|
||||||
* and 0 if cache is already allocated */
|
* and 0 if cache is already allocated */
|
||||||
int shared_context_init(int size, int use_shared_memory);
|
int shared_context_init(int size, int use_shared_memory);
|
||||||
|
|||||||
18
src/shctx.c
18
src/shctx.c
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
#ifdef USE_SYSCALL_FUTEX
|
#ifdef USE_SYSCALL_FUTEX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifndef u32
|
#ifndef u32
|
||||||
@ -22,6 +23,7 @@
|
|||||||
#else /* USE_SYSCALL_FUTEX */
|
#else /* USE_SYSCALL_FUTEX */
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif /* USE_SYSCALL_FUTEX */
|
#endif /* USE_SYSCALL_FUTEX */
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "ebmbtree.h"
|
#include "ebmbtree.h"
|
||||||
#include "proto/shctx.h"
|
#include "proto/shctx.h"
|
||||||
@ -38,10 +40,12 @@ struct shared_session {
|
|||||||
|
|
||||||
|
|
||||||
struct shared_context {
|
struct shared_context {
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
#ifdef USE_SYSCALL_FUTEX
|
#ifdef USE_SYSCALL_FUTEX
|
||||||
unsigned int waiters;
|
unsigned int waiters;
|
||||||
#else /* USE_SYSCALL_FUTEX */
|
#else /* USE_SYSCALL_FUTEX */
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
struct shared_session active;
|
struct shared_session active;
|
||||||
struct shared_session free;
|
struct shared_session free;
|
||||||
@ -49,12 +53,19 @@ struct shared_context {
|
|||||||
|
|
||||||
/* Static shared context */
|
/* Static shared context */
|
||||||
static struct shared_context *shctx = NULL;
|
static struct shared_context *shctx = NULL;
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
static int use_shared_mem = 0;
|
static int use_shared_mem = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
static void (*shared_session_new_cbk)(unsigned char *session, unsigned int session_len, long cdate);
|
static void (*shared_session_new_cbk)(unsigned char *session, unsigned int session_len, long cdate);
|
||||||
|
|
||||||
/* Lock functions */
|
/* Lock functions */
|
||||||
|
#ifdef USE_PRIVATE_CACHE
|
||||||
|
#define shared_context_lock(v)
|
||||||
|
#define shared_context_unlock(v)
|
||||||
|
|
||||||
|
#else
|
||||||
#ifdef USE_SYSCALL_FUTEX
|
#ifdef USE_SYSCALL_FUTEX
|
||||||
#if defined (__i586__) || defined (__x86_64__)
|
#if defined (__i586__) || defined (__x86_64__)
|
||||||
static inline unsigned int xchg(unsigned int *ptr, unsigned int x)
|
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)
|
#define shared_context_unlock(v) if (use_shared_mem) pthread_mutex_unlock(&shctx->mutex)
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* List Macros */
|
/* 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 shared_context_init(int size, int shared)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
#ifndef USE_SYSCALL_FUTEX
|
#ifndef USE_SYSCALL_FUTEX
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
#endif /* USE_SYSCALL_FUTEX */
|
#endif /* USE_SYSCALL_FUTEX */
|
||||||
|
#endif
|
||||||
struct shared_session *prev,*cur;
|
struct shared_session *prev,*cur;
|
||||||
int maptype = MAP_PRIVATE;
|
int maptype = MAP_PRIVATE;
|
||||||
|
|
||||||
@ -377,8 +391,10 @@ int shared_context_init(int size, int shared)
|
|||||||
if (size<=0)
|
if (size<=0)
|
||||||
size = SHCTX_DEFAULT_SIZE;
|
size = SHCTX_DEFAULT_SIZE;
|
||||||
|
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
if (shared)
|
if (shared)
|
||||||
maptype = MAP_SHARED;
|
maptype = MAP_SHARED;
|
||||||
|
#endif
|
||||||
|
|
||||||
shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context)+(size*sizeof(struct shared_session)),
|
shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context)+(size*sizeof(struct shared_session)),
|
||||||
PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0);
|
PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0);
|
||||||
@ -387,6 +403,7 @@ int shared_context_init(int size, int shared)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_PRIVATE_CACHE
|
||||||
#ifdef USE_SYSCALL_FUTEX
|
#ifdef USE_SYSCALL_FUTEX
|
||||||
shctx->waiters = 0;
|
shctx->waiters = 0;
|
||||||
#else
|
#else
|
||||||
@ -396,6 +413,7 @@ int shared_context_init(int size, int shared)
|
|||||||
#endif
|
#endif
|
||||||
if (maptype == MAP_SHARED)
|
if (maptype == MAP_SHARED)
|
||||||
use_shared_mem = 1;
|
use_shared_mem = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
memset(&shctx->active.key, 0, sizeof(struct ebmb_node));
|
memset(&shctx->active.key, 0, sizeof(struct ebmb_node));
|
||||||
memset(&shctx->free.key, 0, sizeof(struct ebmb_node));
|
memset(&shctx->free.key, 0, sizeof(struct ebmb_node));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user