Skip to content

Coping with out of memory situations

Tom M edited this page Oct 25, 2020 · 3 revisions

By default, ANMP will decode the whole audio file at once and put its raw PCM to main memory, provided that enough memory is available. Since ANMP version 9: To avoid memory pressure situations from arising while ANMP is blocking a huge amount of memory, the memory pages containing the decoded PCM are being advised by madvise(MADV_FREE), letting the kernel know that this memory is not "important" and may be freed if memory pressure occurs. The madvise is issued after the file has been fully decoded. If memory pressure later occurs, the kernel will free pages, which is like punching holes of zeros into the PCM, causing random silences. IMO, this is better than a system that freezes or the OOM killer being invoked. Ofc, this madvise behaviour can be disabled if you don't wish to.

However, a critical moment is when memory pressure occurs while the audio file is still being decoded. You may experience heavy stalls or swappings to disk. In this case, the only real option you have is to invoke the OOM killer via SysRq+F. So make sure SysRq is enabled:

$ cat /proc/sys/kernel/sysrq
1