From b0be9e32754483a60440ab691a22d5e501f25d22 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sun, 12 Jun 2011 18:45:17 +0000 Subject: [PATCH] - Pthread stack size made adjustable (thread_stack_size) --- ChangeLog | 1 + doc/siproxd.conf.example | 14 ++++++++++++++ src/rtpproxy_relay.c | 24 +++++++++++++++++++++++- src/siproxd.c | 1 + src/siproxd.h | 1 + 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fd2f976..922ec57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ ===== 12-Jun-2011: - one-off in get_ip_by_ifname(), last interface in chain was not considered in matching. + - Pthread stack size made adjustable (thread_stack_size) 11-Jun-2011: - other stun server in example config file and reworked some stun code. 05-Jun-2011: - readconf: allow spaces within string values. diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index 0460918..cb5f29e 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -81,6 +81,20 @@ silence_log = 1 user = nobody #chrootjail = /var/lib/siproxd/ +###################################################################### +# Memory settings +# +# THREAD_STACK_SIZE IS AN EXPERIMENTAL FEATURE! +# It may be used to reduce the stack size allocated +# by pthreads. This may reduce the overall memory footprint +# of siproxd and could be helpful on embedded systems. +# If you don't know what I'm saying above, do not enable this setting! +# USE AT YOUR OWN RISK! +# Too small stack size may lead to unexplainable crashes! +# Improper use may make siproxd eat your dog and vandalize +# your garden. +#thread_stack_size = 512 + ###################################################################### # Registration file: # Where to store the current registrations. diff --git a/src/rtpproxy_relay.c b/src/rtpproxy_relay.c index ada198c..6968abd 100644 --- a/src/rtpproxy_relay.c +++ b/src/rtpproxy_relay.c @@ -92,6 +92,8 @@ int rtp_relay_init( void ) { int sts; int arg=0; struct sigaction sigact; + pthread_attr_t attr; + size_t stacksize; #ifdef USE_DEJITTER dejitter_init(); @@ -113,8 +115,28 @@ int rtp_relay_init( void ) { sigact.sa_flags=0; sigaction(SIGALRM, &sigact, NULL); + pthread_attr_init(&attr); + pthread_attr_init(&attr); + pthread_attr_getstacksize (&attr, &stacksize); + INFO("Current thread stacksize is %i kB",stacksize/1024); + + /* experimental feature: + * reduce the thread stack size to reduce the overall + * memory footprint of siproxd on embedded systems + * + * Use at your own risk! + * Too small stack size may lead to unexplainable crashes! + * Improper use may make siproxd eat your dog and vandalize + * your garden. + */ + if (configuration.thread_stack_size > 0) { + stacksize = configuration.thread_stack_size*1024; + pthread_attr_setstacksize (&attr, stacksize); + INFO("Setting new thread stacksize to %i kB",stacksize/1024); + } + DEBUGC(DBCLASS_RTP,"create thread"); - sts=pthread_create(&rtpproxy_tid, NULL, rtpproxy_main, (void *)&arg); + sts=pthread_create(&rtpproxy_tid, &attr, rtpproxy_main, (void *)&arg); DEBUGC(DBCLASS_RTP,"created, sts=%i", sts); /* set realtime scheduling - if started by root */ diff --git a/src/siproxd.c b/src/siproxd.c index 1cb0c23..c4abc9c 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -89,6 +89,7 @@ static cfgopts_t main_cfg_opts[] = { { "tcp_timeout", TYP_INT4, &configuration.tcp_timeout, {TCP_IDLE_TO, NULL} }, { "tcp_connect_timeout", TYP_INT4, &configuration.tcp_connect_timeout, {TCP_CONNECT_TO, NULL} }, { "tcp_keepalive", TYP_INT4, &configuration.tcp_keepalive, {0, NULL} }, + { "thread_stack_size", TYP_INT4, &configuration.thread_stack_size, {0, NULL} }, {0, 0, 0} }; diff --git a/src/siproxd.h b/src/siproxd.h index fbf87bb..380d535 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -103,6 +103,7 @@ struct siproxd_config { int tcp_timeout; int tcp_connect_timeout; int tcp_keepalive; + int thread_stack_size; }; /*