memtester asks for memory, linux oom crashes computer

Asked by G.M.

Hi,

I wanted to test my RAM, so I installed memtester.

On my machine with 2*4GB RAM, I typed in:
$ memtester 8GB 10

Immediately, the computer got frozen...

According to the docs (man page):
"memtester will malloc(3) the amount of memory specified, if possible. If this fails, it will decrease the amount of memory requested until it succeeds"

So, apparently, memtester succeeded reserving 8GB. I would be glad to understand how, since:
1. My machine just has that amount physically, but with the OS+other running software, only 5794044 bytes are free
2. I have set up some paranoïd configurations so that no user process can request more than 2GB:
$ ulimit -m
2097152

How is it possible that memtester did not got rejected by the OS when asking for more memory than available?
How is it possible that memtester did not got rejected by the user process's limits?
How to prevent memtester (and any other software) to crash my system by simply greedily asking for memory?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu linux Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Colin Ian King (colin-king) said :
#1

Linux will allow one to overcommit on memory allocations. With large allocations like this, the system will run low on free memory and start to swap out old dirty (used) pages to the swap partition to free up pages for the allocation. In doing so your system will become less responsive as all the swap activity will use all the available disk bandwidth in servicing the swap activity.

So:

1. "How is it possible that memtester did not got rejected by the OS when asking for more memory than available?"

- that's because the kernel allows one to allocate more memory than is available because of the overcommit behaviour, plus it will service this with swapping. This is normal behaviour.

2. "How is it possible that memtester did not got rejected by the user process's limits?"

Reading the manual to memtester I see that it recommends running it as root; this will therefore ignore the ulimit set to your normal user id. e.g.

$ ulimit -m
2097152
$ sudo memtester 8GB 10

[ the sudo will ignore your user ulimit ]

3. I see that memtester will attempt to mlock pages into memory. Running it as root will effectively allow it to lock pages into memory so they can't be swapped out. Hence when the system runs low on memory the kernel will attempt to swap out pages of other running processes first (since memtester's pages are locked in and can't be swapped out). Eventually the kernel will run out of pages to evict and the OOM killer will kill memtester.

4. "How to prevent memtester (and any other software) to crash my system by simply greedily asking for memory?"

To stop memtester being OOM'd, run it with the just the size of available memory rather than the physical memory size. The 'free' command will show you how much memory is available, e.g. on my machine:

$ free -m
              total used free shared buff/cache available
Mem: 15769 2108 9362 274 4299 13059
Swap: 7812 0 7812

..showing there are 9362 MB of free memory, so run memtester with the 'free' memory size.

Revision history for this message
Bernard Stafford (bernard010) said :
#2

I would uninstall the program. During the boot -> Advanced options- Memory Test

Can you help with this problem?

Provide an answer of your own, or ask G.M. for more information if necessary.

To post a message you must log in.