[IPOL discuss] Swap memory

Miguel Colom Miguel.Colom at cmla.ens-cachan.fr
Sun Oct 23 18:09:55 CEST 2011


Hello all,
these days Marc Lebrun and I have been trying to find the cause of a
memory bug in some denoising programs.

These programs work properly in Marc's machine, but they fail on mine and
also on the IPOL server.

Finally we managed to find the cause of the problem. The programs allocate
a lot of memory and when it runs out of a certain amount, "malloc" returns
a NULL or a std::bad_alloc exception is raised by the "new" operator.

In Marc's computer the program isn't crashing because when the available
amount of free memory is low, it starts to use swap memory.

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?

Best,
Miguel

PS: to check if the swap is activated, you can use this command: sudo swap -s

Filename				Type		Size	Used	Priority
/dev/sda1                               partition	5858300	200092	-1

In my case, it is.

PPS: to see the memory used by the process, you can use gnome-system-monitor
. The following code portions can be used to make the process use lots of
memory:

    // MALLOC
    int i = 0;
    double *data;
    do {
      cout << i << endl;
      data = (double*)malloc(1024 * 1024 * sizeof(double));
      i++;
    } while (data != NULL);

---
    // NEW
    int i = 0;
    do {
      cout << i << endl;
      float *data = new float[1024 * 1024];
      i++;
    } while (true);




More information about the discuss mailing list