RSS grows ~240 MB on every dialplan reload and is never released (Asterisk [22.8.2], large dialplan)

Hi all,

We run a multi-tenant PBX and see Asterisk’s memory (RSS) grow by about 240 MB on every dialplan reload. It is never released, so we have to restart Asterisk once or twice a day.

Setup

  • Asterisk [22.8.2], Ubuntu, 15 GB RAM, no swap.
  • About 90 tenants and about 7,300 PJSIP endpoints, with endpoints, AORs, auths and contacts loaded from MariaDB through ODBC realtime (no sorcery memory cache yet).
  • The dialplan comes from generated .conf files loaded with #tryinclude: one file per tenant plus a few shared files. Size:-= 74641 extensions (546727 priorities) in 23116 contexts. =- .
  • About 1,150 hints. We cut them from about 74,000, and that brought reload time from about 60 s down to about 1.5 s.
  • A web panel runs dialplan reload after edits (extensions, IVRs, DIDs, and so on). Reloads are coalesced, one at a time, and skipped when no file changed. We still get about 30–40 reloads on a busy weekday.

What we measured (RSS of the Asterisk process, 5 seconds after each reload, with about 5 calls active):

before        8456 MB
reload 1      8706 MB   (+250)
reload 2      8934 MB   (+228)
10 min, no reload: 8934 -> 8934 MB (flat)

Earlier the same day it was 8134 → 8380 MB (+246) for a single reload. Memory doesn’t level off after a few reloads. It only grows when a reload happens. Calls, registrations and CDR/CEL don’t make it grow.

Things we checked

  • core show taskprocessors: no queue backlog (all “In Queue” are 0).
  • ODBC connections are normal (1 of 1 per DSN). CDR/CEL go to ODBC.
  • Hints are stable at 1,154.

Questions

  1. Is it expected that a dialplan reload with calls active keeps the old dialplan’s memory, so RSS grows by roughly the size of the dialplan each time?
  2. Has anyone had MALLOC_ARENA_MAX=2 (or calling malloc_trim) fix this, or does it point to a real leak in pbx_config or the hint/context handling?
  3. Is there a better way to apply dialplan changes for one tenant without reloading the whole dialplan? For example, something we could do through pbx_lua/pbx_realtime, AstDB-driven contexts, or reloading only part of the configuration.
  4. If a MALLOC_DEBUG build would help, which memory show output would you like to see?

We can test patches or debug builds on a staging copy. Thanks!

  1. You stated 23.x in your title, yet 22.8.2 in the forum post
  2. 22.8.2 is from February, so I’d suggest setting up a test environment on the latest release to see if it is different
  3. MALLOC_DEBUG as you’ve mentioned would tell you what the memory is for, do a before reload/after reload and compare the output to see what increased
  4. “dialplan reload” doesn’t keep old dialplan active really

Sorry for the confusion: the server runs 22.8.2, the title is wrong. Thanks for the pointers.

I built a test on Asterisk 23.5.0 with the same dialplan size (36,320 extensions, 218,276 priorities, 16,828 contexts, generated by our production code). On 23.5.0, RSS rises for the first 2 reloads and then stays flat (197 → 361 → 456 MB, then 456 for every further reload; with 40 Local channels up: 459 MB flat over 8 reloads). With MALLOC_ARENA_MAX=2 it stays at 365 MB. On 22.8.2 in production we see +230–250 MB on every reload with no ceiling. So it looks like either a 22.8.2 issue or allocator arenas. Next step: MALLOC_ARENA_MAX=2 on production, then an upgrade to the latest release; I’ll post the numbers.