3

I am running Ubuntu 10.04 with the below kernel version

Linux ip-10-0-1-119 2.6.32-343-ec2 #45-Ubuntu SMP Tue Feb 14 18:18:17 UTC 2012 x86_64 GNU/Linux

The memory status shows that the cache is using the maximum share of the RAM.

ubuntu@ip-10-0-1-12:~$ free -m
             total       used       free     shared    buffers     cached
Mem:          7702       7657         44          0         24       6137
-/+ buffers/cache:       1494       6207
Swap:            0          0          0

I understand that the OS manages it automatically and keeps the maximum share of RAM in the cache to minimize the cost of I/O.

The problem is during heavy load when our application requires memory and if the same amount is not available in the physical RAM the OOM killer terminates the application.

How can I tune my kernel so that if there is any memory request from my application the kernel should free some of the cache memory to make room for my application instead the OOM killer terminating it ?

Supratik
  • 2,154
  • 10
  • 51
  • 66
  • It's already freeing cache memory as quickly as it can. With no swap, it likely can't free cached memory fast enough because much of that memory is dirty and has to be written back to disk. – David Schwartz Oct 09 '16 at 10:43

1 Answers1

8

Normally, linux will clear cache for you application. What you can do is exclude your application from OOM killer. OOM killer will not terminate your application then.

echo -17 > /proc/PID/oom_adj

PID should be the PID of your program.

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
  • Cool trick! After all these years I did not know this. The obscure syntax might have something to do with it, but sure as hell I copied the information you provided. – Janne Pikkarainen Mar 15 '12 at 13:33
  • @Lucas Kauffman Thanks for your reply. Can you please tell me why was Kernel not releasing memory from the cache at the first? – Supratik Mar 16 '12 at 06:19
  • Normally it should, I suggest you install something (if you can) like munin, it logs everything and makes graphs. You should be able to find out what is happening. It might be a bug in your system or it might be your application actually blowing up your memory. – Lucas Kauffman Mar 16 '12 at 06:27
  • 1
    @LucasKauffman does it have to do something with not having any swap? – Sabya Mar 19 '12 at 09:23
  • 1
    Normally it shouldn't, but I always strongly advice against not having swap. – Lucas Kauffman Mar 19 '12 at 09:34