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
  • 325
  • 1
  • 16
  • Does this answer kind of help? http://superuser.com/questions/561617/oom-killer-despite-lots-of-free-memory-on-pae-kernel – tink Mar 19 '15 at 02:56
  • @tink not sure why I didn't see your comment earlier, but I checked the link, and saw the `vm.overcommit_memory=1` line, and just checked on my system, it was set to `vm.overcommit_memory=0`. I have just changed it, and will update this question once I know if that does that trick or not. Thanks! – insaner Oct 23 '15 at 05:29
  • @tink, well, I just tried `tail /dev/zero` and it didn't work. The swap is still not being used, but `free` tells me the swap is on! Argh. – insaner Oct 23 '15 at 05:30

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.

Adalbert
  • 1
  • 1
  • Your answer needs proper illustration of the Code, you are trying to explain here. Better use bunch of lines comprises the corrections you have suggested the OP (Original Post). You may refer the guide lines also that, how to compose a good answer. – Rajesh Sinha Jan 16 '18 at 10:26
  • 2
    This is an interesting answer to a completely different question. – bot47 May 26 '20 at 11:45
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
  • 1
  • 3
  • but if I have 3GB free of physical ram, and I run `tail /dev/zero` it should still start eating into the swap, at least for that 1GB extra it is allowed before hitting the 4GB limit you mention, right? – insaner Mar 19 '15 at 21:58
  • Probably... It has to be 32-bit system though. Actually maximal allowed address space is less than 3GiB, because of OS kernel.So try it on a machine with 2GiB of RAM. – ilkhd Mar 20 '15 at 07:25
  • would 2GB of _free_ RAM work as well? – insaner Mar 20 '15 at 07:48
  • Not sure. It should, but in Linux you never know how much of free memory you actually have. – ilkhd Mar 20 '15 at 07:52