[IPOL discuss] Swap memory

Nicolas Limare nicolas.limare at cmla.ens-cachan.fr
Mon Oct 24 02:44:05 CEST 2011


Hi,

>> In my computer, when the memory is low, the swap isn't used and the
>> program fails to get more memory because the system isn't using swap.
>>
>> Does anyone know the cause why the system isn't using swap or how to
>> configure it to change this behavior?

It may depend on the amount or RAM and swap you have on your
system, and the kernel version, and the system arch (a structure with
lots of pointers and long int will require 2x more memory in 64bits
than in 32bits), and maybe the libc vesion too. As Pascal pointed out,
memory problems can happen are allocation time by returning NULL when
too much memory is requested, or at write time by killing the process
when trying tu use the overallocated memory.

You should look at your kernel configuration to see if and how it is
using optimistic memory allocation, in /proc/sys/vm/overcommit_memory
and /proc/sys/vm/overcommit_ratio
-> http://www.tin.org/bin/man.cgi?section=5&topic=proc or "man proc"

You can also look at the swappiness configuration, but I doubt it will
answer your problem:
-> http://en.wikipedia.org/wiki/Swappiness

> But on a server, the swap should not be used. And
> the reason for that is because Random Accessing swapped Memory can
> easily render the system unresponsive or even lock it, and that's bad
> karma on a multi-user system.

That is why, on the IPOL demo server, there is no swap at all. I also
think swap should only be a 

If a process requires "really too much memory", malloc() returns NULL.
If it tries to use "too much memory", the process is killed by the
system. To know what happens, maybe you can combine Pascal's
suggestion with Enric's xmalloc() with writing out the amount of
memory requested, and abort() on malloc() error.

    static void* dbg_malloc(size_t size)
    {
        void * memptr;
        fprintf(stderr, "requesting %ul bytes of memory.\n", size);
        memptr = malloc(size);
	if (NULL == memptr) {
            fprintf(stderr, "allocation failed, aborting.\n");
            abort();
        }
        fprintf(stderr, "allocated %ul bytes of memory.\n", size);
	memset(memptr, 0, size);
        fprintf(stderr, "wrote %ul bytes of memory.\n", size);
        return memptr;
    }

> By the way, fuchsia has 6 Gb of RAM, and 3 Gb of swap. Let's say the
> algorithm uses the full 3Gb of swap, just writing and reading 3Gb from
> the disk will take more than 30 seconds (that's no longer On Line).
> In conclusion I'll consider resizing the input, or rethinking the
> algorithm to reduce its memory footprint.

And the official IPOL guidelines say that a demo shouldn't require
more than 1GiB of RAM. But nothing is done (yet) to enforce it.

-> http://www.ipol.im/meta/submission/manual/#index3h1

--
Nicolas LIMARE - CMLA - ENS Cachan    http://www.cmla.ens-cachan.fr/~limare/
IPOL - image processing on line                          http://www.ipol.im/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20111024/35135465/attachment.pgp>


More information about the discuss mailing list