LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   memory calculation (https://www.linuxquestions.org/questions/linux-server-73/memory-calculation-819949/)

mario.almeida 07-15-2010 06:56 AM

memory calculation
 
Hi All,

I want to calculate the total amount of memory used by the system,
Someone please confirm if the below formula is correct.
Quote:

((memUsed-mebBuffers-memCached)*100)/memUsed => totalMemoryUsed%
Code:

free -o
            total      used      free    shared    buffers    cached
Mem:      8167004    8115292      51712          0      87680    1444676
Swap:      8388584    3252996    5135588

((8115292-87680-1444676)*100/8115292) => 81%

As per the above calculation 81% of memory is used.
Is this correct? and if so
Am I running out of memory?
what is the limit in % that I should maintain for a better performance?

johnsfine 07-15-2010 07:01 AM

A used% value for memory is not very meaningful. It may not give you a good measure of whether you are "running out of memory".

In any case, your formula should be dividing by total, rather than by memUsed. That doesn't change the result much in your case, but under other conditions it might be a big difference.

Code:

((8115292-87680-1444676)*100/8167004) => 81%
By "running out of memory" I expect you mean something like "the system would run a lot faster if it had more memory". That is probably true for your system, but the info you posted doesn't prove it.

Since you have enough of swap space, your system isn't "running out of memory" in a literal sense. Almost all of your 5135588 KiB of free swap space plus a significant part of your 1444676 KiB of cache would need to be used by "anonymous" memory before you would literally run out of memory. That is likely more than double your current use level of anonymous memory.

Quote:

Originally Posted by mario.almeida (Post 4033820)
what is the limit in % that I should maintain for a better performance?

There is no meaningful answer to that question. The fraction of ram use in various categories does not translate directly into performance. What matters for performance is how much time the system is spending moving pages around, between the address spaces of processes and the cache and more importantly between the cache and the disk.

Your high use of swap space might indicate a lot of active anonymous pages have been pushed out to swap, meaning lack of memory is making your system much slower. But it equally well might mean you have a bunch of idle services running that own a lot of anonymous memory that they aren't trying to use, so that has properly been swapped out.

Your high level of memory use by processes as compared to cache might mean that code pages (and other file mappings) aged out of each process address space are quickly dropped from the cache for lack of space, so they must be frequently read back from the original files (.so files etc.) as they are faulted back into process address spaces (again meaning lack of memory is making the system slow). But it equally well might mean the use of file mappings by your processes is either small (most memory use anonymous) or stable, such that few pages age out of the process address space and the cache size is plenty for the use of cache.

markseger 07-15-2010 07:18 AM

hard to tell... I never use the free command as it doesn't tell the whole picture. For example how much slab is used? How much memory is mapped? maybe those numbers are included in others, but I'll let others help. The ONE thing that should be ignored is 'cache' as that is memory for caching files. The more files you open and read the more cache is used. However if the system needs the memory for something else, it just gets rid of older pages.

on my system:

[root@o185i193 plot]# free -o
total used free shared buffers cached
Mem: 4059252 2368812 1690440 0 194424 1909904
Swap: 1052216 0 1052216


[root@o185i193 plot]# collectl -sm --verbose -c1
# MEMORY STATISTICS
#<---------------------------Physical Memory---------------------------><-----------Swap------------><-------Paging------>
# Total Used Free Buff Cached Slab Mapped Commit Inact Total Used Free In Out Fault MajFt In Out
3964M 2329M 1634M 194424K 1865M 114852K 162112K 421420K 1225M 1027M 0 1027M 0 0 19604 0 0 120

so you can see there is a lot more going on that free is telling you. In fact, if you look at /proc/meminfo you'll see even more.

-mark

vamsi_k 07-22-2010 10:05 AM

The “total” memory is the amount available after loading the kernel. Any memory being used for processes or disk buffering is listed as “used.” Memory that is currently unused is listed in the “free” column. Note that the total memory is equal to the sum of the “used” and “free” columns.

The memory indicated as “shared” is an indication of how much memory is common to more than one process. A program such as the shell typically has more than one instance running. The executable code is read-only and can be shared by all processes running the shell.

The “buffers” entry indicates how much of the memory in use is currently being used for disk buffering.

The “free” command also shows very clearly whether the swap space is enabled, and how much swapping is going on.

Source : http://www.linuxjournal.com/article/2770


All times are GMT -5. The time now is 12:00 AM.