Sunday, June 22, 2014

Linux Check Memory Usage

$ free -m
                  total          used          free       shared    buffers     cached
Mem:         64458        63032        1426          0        365          23842
-/+ buffers/cache:        38823        25634
Swap:        16386        8681          7705

                                  total          used            free         shared    buffers     cached
Line 1       Mem:          64458       63032         1426          0          365         23842

64458   Indicates memory/physical RAM available for your machine
63032   Indicates memory/RAM used by system. This include even buffers and cached data size as well.
1426     Indicates Total RAM free and available for new process to run.

0           Indicates shared memory. This column is obsolete and may be removed in future releases of free.
365       Indicates total RAM buffered by different applications in Linux
23842    Indicates total RAM used for Caching of data for future purpose.      

                                  total         used         free     
Line 2    -/+ buffers/cache:        38823       25634

38823  This is actual size of used RAM which we get from RAM used -(buffers + cache)
A bit of mathematical calculation

Used RAM = +63032       
Used Buffers = -365      
Used Cache = -23842

Actual Total used RAM is 63032-(365+23842)= 38823

Then why my Linux machine is showing 63032 as used RAM. This is because Linux counts cached RAM, Buffered RAM to this used RAM      
  
25634 Indicates actual total free RAM available, we get to this number by subtracting actual RAM used from total RAM available in the system. 

Total RAM = +64458      
actual used RAM = -38823      
Total actual available RAM = 25634

If any one asks what is the free RAM available, we have to give this number(25634) instead of first line number(1426) for free RAM available in your machine.
  
                              total           used       free     
Line 3:  Swap:        16386         8681      7705

This line indicates swap details like total SWAP size, used as well as free SWAP.   

Swap is a virtual memory created on HDD to increase RAM size virtually. On Linux, swap space is managed by the "kswapd" daemon (kernel thread). Swapping is needed to access a page that is not in physical memory or to move inactive pages to swap space.  

Why does oracle need so much swap? 

Oracle does not access nor use swap space directly. If it is used indirectly, it would be provided to Oracle as "virtual memory" by the Linux / UNIX OS, as a consequence of the Linux / UNIX system running out of RAM memory. What the Oracle RDBMS software needs is for your system to remain stable (although slow, certainly) if your Linux/Unix system runs out of RAM memory.

The purpose of swap on a Linux / UNIX system is to control how the Linux / UNIX system should respond, should it run out of RAM memory.

Difference b/w buffer & cache

Buffer

1.  A buffer is a temporary location to store data for a particular application and this data is not used by any other
     application.    
2.  Buffers is the amount of memory that’s being used to keep filesystem metadata in RAM. This data is frequently
     accessed, and so keeping it in memory results in huge performance benefits. 

Cache

1.  Linux doesn’t just use RAM for running programs; it also uses RAM to speed up hard disk access. This is known as  
     “caching,” and it greatly improves the performance of your computer. 

2.  Cache is a memory location to store frequently used data for faster access. Other difference between a buffer and
     a cache is that cache can be used multiple times where as buffer is used single time. And both are temporary
     store  for your data processing.

3.  Cached is the amount of memory that’s being used to keep copies of actual files in RAM. When there are files that
are constantly being written or read, having these in memory reduces the amount of times you need to operate    on the physical hard disk; as a result, you can greatly improve performance by using memory for cache.

Linux always tries to use RAM to speed up disk operations by using available memory for buffers (file system metadata) and cache (pages with actual contents of files or block devices). This helps the system to run faster because disk information is already in memory which saves I/O operations. If space is needed by programs or applications like Oracle, then Linux will free up the buffers and cache to yield memory for the applications.


No comments:

Post a Comment