Recently found a problem with my rasbian running on rpi3. I'm using it quite heavily running couple services that are consuming(some of them caching) almost all memory. Here is some dmesg snipet:

swapper/0: page allocation failure: order:0, mode:0x2080020(GFP_ATOMIC)
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.9.29-8-osmc #1
Hardware name: BCM2835

After a little digging I'v found a solution for that. The following tunables can be used in an attempt to alleviate or prevent:

#change value for this boot
sysctl -w vm.min_free_kbytes=65536

#change value for subsequent boots
echo "vm.min_free_kbytes=65536" >> /etc/sysctl.conf

This tells the kernel to try and keep 64MB of RAM free at all times. It’s useful in two main cases:

  • machines witchout swap, where you don’t want incoming network traffic to overwhelm the kernel and force an OOM before it has time to flush any buffers.
  • x86 machines, for the same reason: the x86 architecture only allows DMA transfers below approximately 900MB of RAM. So you can end up with the bizarre situation of an OOM error with tons of RAM free.