1

I've been having this problem for a long time now, and I can't seem to figure it out, basically, my linux (32bit 3.2.6-3.fc16.i686.PAE) system is refusing to use the swap. When I run

$ tail /dev/zero
tail: memory exhausted

it does not resort to using the swap at all.. it just dies after using up the physical RAM. Here are the relevant details.

$ free -m
             total       used       free     shared    buffers     cached
Mem:          8076       4652       3423          0        123        543
-/+ buffers/cache:       3985       4090
Swap:         8192        116       8076


$ cat /proc/sys/vm/swappiness 
60

$ ulimit -m
unlimited

$ cat /proc/sys/vm/overcommit_ratio
50

$ cat /proc/sys/vm/overcommit_memory 
0

I tried setting it to 1:

# sysctl vm.overcommit_memory=1
vm.overcommit_memory = 1


$ cat /proc/sys/vm/overcommit_memory 
1

and tried again, same result. Any ideas?

insaner
  • 385

2 Answers2

0

This question is kind of old, but there's a quite simple answer:

tailing from /dev/zero doesn't do any good. If you just want a stream of null-bytes, use cat.

tail (with default parameters) will return the last 10 lines from the argument. Since /dev/zero is a character device, it will start reading chunks of data from it, until the end (regular files are scanned backwards). The read data is kept until 10 lines have been found, then the first lines are evicted from the buffer.

Lines will be seperated by newline characters - \n. Since /dev/zero doesn't return any newlines, all data (all the null-bytes read so far) is still considered to be the first line, and thus kept in the buffer. And tail will continue until it found the end of the file, which will never happen for /dev/zero. So you'll never ever get any useful output from tail /dev/zero.

Luckily, you're on a 32-bit system and have plenty of free memory, so the memory available to a single process (typically 2 GiB, but might be different depending on kernel configuration) is exhausted pretty quickly and without swapping, and the command is aborted. If you try the same on a system with less free memory or a bigger address space (64-bit system), tail will eat up all memory it can get, get the kernel to swap out as much as possible and eventually you'll still get a memory allocation error. Or trigger the OOM-killer. But still no null-bytes on stdout.

0

It is 32-bit Linux, therefore there is no way to allocate more than 4GiB memory for an application, because it'll exhaust its address space. You have 8GiB RAM, and it is mostly free, so 4096 MiB can be allocated w/o use of swap.

ilkhd
  • 224