Excessive memory allocation makes ubuntu unresponsive

Asked by Christian Plesner Hansen

Whenever a program on my machine uses lots of memory the machine will occasionally become unresponsive for 10-20 seconds at a time. I can move the mouse around but nothing else responds. This happens with chrome all the time. Am I the only one seeing this or is this a common issue? If it's just me it's probably a configuration issue.

Worse, I've accidentally during development run programs that allocate an unbounded amount of memory and this makes the machine terminally unresponsive. Not even the mouse responds. The only way to bring it back is to turn it on and off physically. The program below reproduces the issue consistently. Even though it's clearly a bad program I'd expect the OS to provide at least a minimum of protection here, for some reason mine doesn't.

#include <stdlib.h>

int main(int argc, char *argv[]) {
  unsigned long long size = 0;
  for (size = 4; 1; size *= 2) {
    malloc(size);
  }
}

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Krüger (thkrueger) said :
#1

Might be a stupid but: did you check your RAM?

Revision history for this message
Christian Plesner Hansen (c7n) said :
#2

It actually has been a while since I tested that; I just did and two passes of memtest-86 and it didn't find any errors.

Revision history for this message
Dan Kitcher (a2339) said :
#3

A related query: I frequenty have 10x as much memory shown by top as in use, as the sum of the nonzero %cpu entries in top, and an ubuntu12.04 pc which is going slow because it is churning into swap. (yes. some of us still have that). There are no listed processes with high memory usage to kill, yet Mem: at the top shows pretty much full and Swap: shows hundreds of Mb used when there should be no need for that. What commandline way is there to clear memory not being used by root nor user?

By the way, the badprogram above will trash 2^any amount of memory.

Can you help with this problem?

Provide an answer of your own, or ask Christian Plesner Hansen for more information if necessary.

To post a message you must log in.