Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
Thank you for the feedback. Ok, this would be a bit more complex change. I will need to get some time to look into it. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-548449192___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
Yes, this happens. The function updating the config block and replacing some strings of that with newly allocated values cannot free the old ones because it does not know if a child might still use the old values. We have to wait for all the children to release the values. One approach could be to wake up the children from time to time with a signal, even if there is no traffic. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-542147380___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
Thanks for the additional insight! So did I understood you correctly: If I use Kamailio in a configuration with several children listening on different network interfaces - if there is at least one child that does not handle traffic the "replaced" strings are not freed? -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-540051283___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
Daniel is right, the memory should be eventually freed when ALL the child processes update their local configuration, i.e. do at least one iteration of their loop and call cfg_update(). Each child process updates its local cfg pointer to the global one and travels through the pending callback list. Every item of this list can have a set of memory address to free. The last child that processes the change frees the memory. Check cfg_update_local with the loop: while (cfg_child_cb != last_cb) {...} cfg_child_cb_free_item() frees the "replaced" strings. The restriction is that none of the processes should be idle for a very long time. They should at least update the local config from time to time. This may not be always the case. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-540044623___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
Yes, changing a cfg value e.g. every minute with this framework makes no sense. But good comment about the update mechanism, I will play with it e.g. by sending some SIP messages. I also looked into the code - but I am also not deeply familiar with the code, only looked to it as well. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-539996662___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
That could actually be part of this case -- the values are cloned by each process to avoid sync'ing with mutexes at runtime. Each process gets the new value when it executes cfg_update(), which is typically done when a process has something new to do (e.g., process a new sip message). In your test case, as the old value is still referenced by other processes, might not be destroyed. This part of code is inherited from SER project, I am not very familiar with, that's why I am saying it might be designed for a different purpose than is expected here (i.e., not for use with very often changes of values). My comments here are based on a brief look at the code. And, as I said, for needs related to values that need to be changed very often via rpc, better use shared variable or shared hash table variables. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-539994980___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
I tested it with another cfg variable not related to any module (like we have pstn.gw_ip in default cfg). The test system did not have any traffic, so i would assume that the variable would be commited really fast. But I will have another look to it. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-539970553___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
I haven't really went that deep in the related code, but there are reference counters behind those values, so they might be released when all processes get to use the new value, which can be later in time (or never, depending on the type of sip traffic). Overall, I am not sure if the framework was designed to deal with very often changes, could be more for adjusting some global/custom/module parameters from time to time to avoid restarting kamailio. With the first example in this report, changing very often the ac_extra_hdrs for tm is not likely, imo. If you need to use in config a string variable that has to be changed very often via rpc, use better $shv(x) or $sht(t=>x) . -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-539929291___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Re: [sr-dev] [kamailio/kamailio] core/cfg has memory leak if string value is set (#2094)
I looked today into it as well. I could reproduce it with current git master. ``` root@proxy-1:/usr/local/src/kamailio-devel# grep "^Oct 7 18:38.* qm_status:.*alloc'd" /var/log/syslog | cut -d: -f6- | sort | uniq -c | sort -n | grep core/cfg/cfg 1alloc'd from core: core/cfg/cfg_struct.c: cfg_shmize(217) 1alloc'd from core: core/cfg/cfg_struct.c: sr_cfg_init(324) 1alloc'd from core: core/cfg/cfg_struct.c: sr_cfg_init(336) 1alloc'd from core: core/cfg/cfg_struct.c: sr_cfg_init(348) 1alloc'd from core: core/cfg/cfg_struct.c: sr_cfg_init(355) 1alloc'd from core: core/cfg/cfg_struct.c: sr_cfg_init(362) 2alloc'd from core: core/cfg/cfg_ctx.c: cfg_register_ctx(47) 2alloc'd from core: core/cfg/cfg_struct.c: cfg_clone_global(627) 80alloc'd from core: core/cfg/cfg_ctx.c: cfg_set_now(559) 81alloc'd from core: core/cfg/cfg_struct.c: cfg_child_cb_new(830) 84alloc'd from core: core/cfg/cfg_struct.c: cfg_clone_str(130) root@proxy-1:/usr/local/src/kamailio-devel# kamcmd core.version kamailio 5.4.0-dev0 (x86_64/linux) 7cd263-dirty ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/2094#issuecomment-539102437___ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev