-4

I set an alarm on my cell phone that when ever RAM usage exceeds 90% then got an alert. I also made a script to monitor all the memory, CPU, RAM etc.

How can I reduce the RAM usage where I also have a script of clear cache... but I can't run it all the time or set a cron against it, because it affects the live service.

I have a following script:

memory_alarm=`/usr/bin/free -m|grep Mem|awk '{print $3/$2 * 100.0}'|cut -d\. -f1`

when I ran a top command, it shows 66% and after some seconds the alerts received of RAM usage 95%

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

1

You are not taking the page cache into consideration (under the 'cache' column in free's output). Data written to disk will be held in the cache, and will be flushed when the file is removed/replaced, or free memory becomes low and other processes request more memory.

$ free
             total       used       free     shared    buffers     cached
Mem:       2038308    1890180     148128        504      25072     489884
-/+ buffers/cache:    1375224     663084
Swap:      8386556       7440    8379116
$ /usr/bin/free -m|grep Mem|awk '{print $3/$2 * 100.0}'|cut -d\. -f1
92
$ /usr/bin/free -m|grep Mem|awk '{print ($3-$7)/$2 * 100.0}'|cut -d\. -f1
68
neuro
  • 190
0

This is a VERY old answer but I see it all the time. @Neuro is correct in that RAM usage is NOT (almost never) an issue, as Linux caches disk I/O. (Disk I/O is VERY slow compared to RAM access, and Linux caches almost all sectors that it reads from disk in the hopes that it will be needed again…) So, high RAM usage is mostly irrelevant.

What wasn’t mentioned was that major (or hard) faults (ones that require disk I/O) are an issue, but only if they are sustained and excessive. Minor (or soft) faults are rarely a problem. What is sustained and excessive? That is the question.