### Description
Config file has parameter "shm_mem_size" (or "shm" or "shm_mem") which allows to set shared memory size (in Mb) via configuration file. This parameter worked well in 3.1.5. Now it does not work (4.4.2). Shared memory size is always 64Mb (default value). The only way to set another size is to use "-m" command line option.
#### Reproduction
- Set shm_mem_size=512 in configuration file - Start kamailio and check size of shared memory using "kamcmd core.shmmem" - Expected result: total size of shared memory should be 512 Mb (in bytes) - Actual result: 64Mb
### Possible Solutions
A workaround is to use "-m" command line option to send shared memeory size.
### Additional Information
version: kamailio 4.4.3 (x86_64/linux) 5a2195 flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: 5a2195 compiled on 13:41:22 Sep 27 2016 with gcc 4.4.7
OS: CentOS 6.8 (kernel 2.6.32-642.4.2.el6.x86_64)
Can you check the syslog file and see if you get there some error message? The shared memory is initialized whenever is first time needed during the parsing of the configuration file, so it may be that the parameter was set too late.
The safest would be indeed setting it via -m command line parameter.
There are no error messages. The problem is in main.c. It sets shm_mem_size to default value before parsing config file. But cfg.y sets shm_mem_size only when it's zero.
Can you try with the patch referenced by the commit above? If all ok, then I will backport to 4.4 branch.
Your patch will override memory size set by "-m" option in case it is 64mb (-m 64). I created another patch for my environment by moving setting sm_mem_size to default size after yyparse().
--- kamailio-4.4.3.orig/main.c 2016-09-14 16:50:30.000000000 +0300 +++ kamailio-4.4.3/main.c 2017-01-26 18:30:55.000000000 +0300 @@ -2069,9 +2069,6 @@ abort(); } } - if (shm_mem_size == 0) { - shm_mem_size = SHM_MEM_POOL_SIZE; - }
if (endianness_sanity_check() != 0){ fprintf(stderr, "BUG: endianness sanity tests failed\n"); @@ -2136,6 +2133,11 @@
goto error; } + + if (shm_mem_size == 0) { + shm_mem_size = SHM_MEM_POOL_SIZE; + } + if (cfg_warnings){ fprintf(stderr, "%d config warnings\n", cfg_warnings); }
It also would be good to add documentation for shm_mem_size parameter in config file (I did not find it).
I expected that, but the issue is that there will be problems if the size is not provided by -m and the shm_mem_size is set after a config directive that needs shared memory, because the size is 0 at that moment. Probably the init of the size should be done inside the function initializing the shared memory, if it is 0.
Closed #950.
Still broken in the version the bug was reported against: 4.4
The patch by @mmalygin is probably also needed to get the previous (and standard) _"command-line overrides config file"_ behaviour
there will be problems if the size is not provided by -m and the shm_mem_size is set after a config directive that needs shared memory
Can that really happen? What option would need that? And isn't that caught by: ```c if (shm_initialized()) yyerror("shm/shm_mem_size must be before any modparam or the" " route blocks"); ```