GIF allocates 128MB of memory to dither
Posted: 2017-08-09T23:27:00-07:00
I am using ImageMagick in a Linux application as part of an image translation pipeline. I've been having problems with the server OOM killing processes. The command I am running can be replicated from the command line:
$ convert -resize x64 s1.svg s1.gif
s1.svg looks like this:
The command when run consumes 128Mb (134221824 bytes) of memory (as seen through strace):
I traced the memory utilisation to the following lines in "GetCubeInfo()" in MagickCore/quantize.c:
In the above code, which appears to be independent of the size of the file being processed, length evaluated to 2^24 and size is 8, so the call ends up requesting 2^27 bytes (128Mb) of memory.
The purpose of the application is to convert two differing SVGs into GIFs and then stitch them together as an animated GIF for web display. The problem is that the memory being used by this process is causing the OS to OOM kill processes due to the memory requirement when multiple converts run simultaneously.
Is there any reason why GIF needs such a huge amount of memory for what works out to be a 5k GIF file?
Surely the dither resources (the memory allocation in GetCubeInfo) should be related to the size of the source file?
Setting resource limitations either in the call or via shell environment doesn't help. They are ignored.
Environment: debian Jessie (3.16.39-1+deb8u2)
ImageMagick: v7.0.6 (compiled and run on host)
I've also tried this on RedHat using packages and got the same result.
$ convert -resize x64 s1.svg s1.gif
s1.svg looks like this:
Code: Select all
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 124 30">
<defs>
<style type="text/css"><![CDATA[
#background {
fill: black;
}
]]></style>
</defs>
<path id="background" d="M0,0h124v30h-124z"/>
</svg>
Code: Select all
...
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap(NULL, 134221824, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff4f3c58000
futex(0x738d24, FUTEX_WAKE_PRIVATE, 2147483647) = 0
...
Code: Select all
length=(size_t) (1UL << (4*(8-CacheShift)));
cube_info->memory_info=AcquireVirtualMemory(length,sizeof(*cube_info->cache));
The purpose of the application is to convert two differing SVGs into GIFs and then stitch them together as an animated GIF for web display. The problem is that the memory being used by this process is causing the OS to OOM kill processes due to the memory requirement when multiple converts run simultaneously.
Is there any reason why GIF needs such a huge amount of memory for what works out to be a 5k GIF file?
Surely the dither resources (the memory allocation in GetCubeInfo) should be related to the size of the source file?
Setting resource limitations either in the call or via shell environment doesn't help. They are ignored.
Environment: debian Jessie (3.16.39-1+deb8u2)
ImageMagick: v7.0.6 (compiled and run on host)
I've also tried this on RedHat using packages and got the same result.