Hello,
following the Kamailio Developers Meeting discussions and provided that GNU/Linux malloc() aligns allocated memory to 16 bytes on x86_64 (64b CPUs), I just updated the native Kamailio qm (quick malloc - the default one) and fm (fast malloc) memory managers to also align to 16 bytes:
- https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.htm...
By default they do it to 16 also for 32b CPUs, the overhead at startup with default config was rather insignificant (like 5000 bytes for private memory set to 8MB), so I didn't want to bother that much (that's also because some 32b CPUs could require larger alignment that the size of the pointer address), but for flexibility I added the an option to set the alignment size at compile time with KSR_MEMORY_ALIGN define (e.g., -DKSR_MEMORY_ALIGN=8UL).
The main benefit at this moment is that Kamailio should be able to use the OS distribution (e.g., Debian) packaged libwolfssl instead of bundling and building the library inside it to compile with custom flags, like it is done now. Also, it is safe for the future to use other libraries that leverage internally the OS memory alignment size for specific optimizations.
I also increased the optimize factor to 15, which should speed up a bit dealing with larger chunks of memory (now up to 32KB, previously was up to 16KB). Considering that it is more and more common to deal with larger SIP messages (e.g., a webrtc invite can easily be like 20KB) as well as tls/encryption needs addition space that the unencrypted udp/tcp.
Hopefully these updates don't have side effects, it was nothing consistent changed, a few defines and fields to match the new alignment constraints. But testing is important, try to play with the master and your configs whenever you have any chance.
Unfortunately the tlsf memory manager seems to be specifically designed for aligning to 8 bytes, a rather old related issue in that project is not concluded:
- https://github.com/mattconte/tlsf/issues/16
That means the tls_wolfssl module linked with the officially packaged libwolfssl has to be used with qm or fm malloc from now on. Or it has to be built like so far to use tlsf memory manager. The tls/tlsa module can still be used with tlsf memory manager.
Cheers, Daniel