Query on RAM Memory

Hi Experts,

I have a linux system , which triggers a alarm if RAM memory goes above 70%... When i see top command i cant find any process utilizing much of memory .. Can anyone tell me what could be the reason for high memory utilization.. Bellow is the free command o/p:

 free                                                             
             total       used       free     shared    buffers     cached                    
Mem:       3626072    2981104     644968          0     581724    1846152                    
-/+ buffers/cache:     553228    3072844                                                     
Swap:      4194296          0    4194296    
 

Bellow is output of cat /proc/meminfo

 
MemTotal:      3626072 kB                                                                    
MemFree:        647368 kB                                                                    
Buffers:        581708 kB                                                                    
Cached:        1846080 kB                                                                    
SwapCached:          0 kB                                                                    
Active:        2683580 kB                                                                    
Inactive:       204592 kB                                                                    
HighTotal:     2746676 kB                                                                    
HighFree:       430268 kB                                                                    
LowTotal:       879396 kB                                                                    
LowFree:        217100 kB                                                                    
SwapTotal:     4194296 kB                                                                    
SwapFree:      4194296 kB                                                                    
Dirty:             272 kB                                                                    
Writeback:           0 kB                                                                    
AnonPages:      460300 kB                                                                    
Mapped:          20140 kB                                                                    
Slab:            76044 kB                                                                    
PageTables:       2156 kB                                                                    
NFS_Unstable:        0 kB                                                                    
Bounce:              0 kB                                                                    
CommitLimit:   6007332 kB                                                                    
Committed_AS:   649188 kB                                                                    
VmallocTotal:   114680 kB                                                                    
VmallocUsed:      5736 kB                                                                    
VmallocChunk:   108352 kB                                                                    
HugePages_Total:     0                                                                       
HugePages_Free:      0                                                                       
HugePages_Rsvd:      0                                                                       
Hugepagesize:     4096 kB  
 

Can anyone please explain
Thanks in advance

The used number in free is the sum of memory used by applications, buffers, and caches, and not only that of the applications. Linux will always try to use as much memory as possible to cache files to reduce disk access (which is a good thing).

Thanks for your response...My query is who is eating up the memory... I need to get memory down in regard to not see critical alarms...Which is triggered now as memory is 80% used...

You can see in this, you have over 1GB cached memory.

You dont need to get your memory usage down, you should alter your checking script so its when memory is used up and its not being used by cache.

Yes, 80% of your memory are used (but not reserved). But really only about 13% are reserved by applications, with the other 67% being used as cache and buffer to avoid time-consuming disk reads. That is, those 67% are used to keep libraries and files in a fast access location (RAM is much much faster than any disk, even SSDs), and that space is automatically re-assigned should any application require it.

So in order to get the amount of memory reserved by applications ("used"), you'll have to substract the buffers and cache numbers from the used number.

Thanks @pludi @Tommyk

I do understand about the cache and buffers as you said... But thats how its designed here... :(.. Will cleaning up of files solve my problem temporarily, say my root has 52% disk usage... So removing unwanted files is it a solution?

No, as Pludi described it so eloquently where i failed, your Linux system will always cache, however you cannot class this as unavailable memory.

You should class anything that is cache as free so your total amount of free memory is Free mem + Cached Mem.

It is not a design flaw, it is a monitoring flaw. You dont want to clear this down as cache gets overwritten by applications as pludi said when necessary just as it would write to free memory just the same, but keeping things in cache is obviously faster than having to go to disk each time.

Hope that makes sense.

1 Like

No. How much of the disk is used has nothing to do with how much RAM is used. Files are only cached once they are read (and not automatically the whole disk), so it only contains files that have been used. And I doubt you'd be willing to remove files that are required.

Adapt the script/program that's sending out the alert, that's the best advice I can give you.

1 Like

If you really need to get the cached value low you can
a) make the application on that box use direct I/O (recommended if its a database or another application that caches itself) or
b) tune your system to use less fs-cache which will most likely degrade that systems performace. Have a look at the sysctl utility for this and be sure you know what you're doing before using this approach.

Edit: I second pludis and Tommyks advice to adapt your monitoring script as the best solution to your problem...

Thanks a lot...

Below is the snapshot of part of SAR output...

00:00:01    kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
00:10:01       487844   3138228     86.55    582252   1906476   4194296         0      0.00         0
00:20:01       487688   3138384     86.55    582252   1906520   4194296         0      0.00         0
00:30:01       487656   3138416     86.55    582256   1906560   4194296         0      0.00         0
00:40:01       486632   3139440     86.58    582256   1906620   4194296         0      0.00         0
00:50:01       486908   3139164     86.57    582256   1906660   4194296         0      0.00         0
01:00:01       485636   3140436     86.61    582256   1906712   4194296         0      0.00         0
01:10:01       485420   3140652     86.61    582256   1906756   4194296         0      0.00         0
01:20:01       483960   3142112     86.65    582256   1906820   4194296         0      0.00         0
01:30:01       483124   3142948     86.68    582256   1906888   4194296         0      0.00         0
01:40:01       482472   3143600     86.69    582256   1906928   4194296         0      0.00         0
01:50:01       483120   3142952     86.68    582256   1906960   4194296         0      0.00         0
02:00:01       480484   3145588     86.75    582256   1907100   4194296         0      0.00         0
02:10:01       479088   3146984     86.79    582256   1907228   4194296         0      0.00         0
02:20:01       479364   3146708     86.78    582256   1907280   4194296         0      0.00         0
02:30:01       475056   3151016     86.90    582256   1907416   4194296         0      0.00         0
02:40:01       473100   3152972     86.95    582256   1907560   4194296         0      0.00         0
02:50:01       472880   3153192     86.96    582256   1907652   4194296         0      0.00         0
03:00:01       471796   3154276     86.99    582256   1907812   4194296         0      0.00         0

 

Everywhere it does consider as used up memory, system understands it as 86% used up memory... and i assume my alarm is also triggered because of this.... I have to find out some way to fix it... Thanks a lot for your explanation

%memused is worked out based on %memfree of total RAM, although you may see it as used from the outputs, cached is by no means anywhere near to used. You cannot use this value for monitoring until your no longer using cache.

If you reboot your machine it will clear the cached memory down, however you can't reboot your machine every 5 minutes to keep that low as cache builds up again.

I have a server with 32GB RAM, its only using 2GB and 29GB is cached, showing 1GB free, however if an application requires more memory it will used cached memory before it goes into swap.

I think you need to think again about this, it is not a problem that needs fixing, this is your box running at its optimal performance. Your alarm is triggered due to a result that is not entirely representative of what your looking for.

Here i meant by fixing is only in terms of the alarm ( Not memory) now i understood the concept of memory cache , thanks to you and pludi...

Just was wondering what is the impact on clearing the cache, If nothing , by any means can we clear cache without reboot....

Thanks again

There is no problem with clearing cache, it just reduces performance on the Linux server.

Try this command:

root@server [~]# echo 1 > /proc/sys/vm/drop_caches

and then check memory usage to see if it has cleared it:

root@server [~]# free

Thanks ... I will try this and see if it helps.....

 
use top | more 

and look in %MEM