Know The Concept Behind Memory Utilization In Linux - MobileAppDaily
app development

Know The Concept Behind Memory Utilization In Linux

Here are the top commands to check your Memory usage on Linux

https://dk2dyle8k4h9a.cloudfront.net/Know The Concept Behind Memory Utilization In Linux

Linux is one of the popularly known and widely used Open Source operating system. According to the Wikipedia's definition, Linux is a family of open source and free software operating systems that are built around the Linux Kernel.

Basically, Linux is packaged in a form known as the Linux Distro also known as Linux Distribution for both servers as well as desktop use.

Linux as an operating system is a software that resides under all of the various other software on a computer system for the purpose of receiving requests from several programs and then to relay these received request towards the computer's hardware.

For a majority of Unix compatible operating systems, an important factor in determining the performance is the total amount of physical memory that is available for usage. Linux operates heavily on commands i.e. there are commands for almost every operation in Linux.

This is because the GUI might not always be available at your service and that's when these Linux commands come into action. Even when the user works on servers, then only the shell access is available so every task has to be performed in Linux using these commands.

Commands to Check Memory Usage

Here are the top commands to check the Memory Usage in Linux operating system:

Checking memory plays an important role because then the end-user will be aware of how much memory has been utilized as per the processes executed on the servers in Linux.

Let's take an example of a website - Suppose a user is running a web server, this means that the server must have enough amount of memory to serve the visitors of that particular website. If there is not enough memory then the website will become really slow and there's even a possibility of the website to do down when faced with a user traffic hike.

So, there is a slight possibility of your website to do down if there is a short of memory, this is similar to what happens to the desktop PCs as well.

vmstat

$ vmstat -s
     8167848 K total memory
     7449376 K used memory
     3423872 K active memory
     3140312 K inactive memory
      718472 K free memory
     1154464 K buffer memory
     2422876 K swap cache
     1998844 K total swap
           0 K used swap
     1998844 K free swap
      392650 non-nice user cpu ticks
        8073 nice user cpu ticks
       83959 system cpu ticks
    10448341 idle cpu ticks
       91904 IO-wait cpu ticks
           0 IRQ cpu ticks
        2189 softirq cpu ticks
           0 stolen cpu ticks
     2042603 pages paged in
     2614057 pages paged out
           0 pages swapped in
           0 pages swapped out
    42301605 interrupts
    94581566 CPU context switches
  1382755972 boot time
        8567 forks
$

The vmstat is a very effective tool that lays out the virtual memory usage statistics similar to the proc command. This vmstat command goes with the s option and below are the elements on which the user receives the memory usage reports:

  • CPU
  • Block I/O
  • Memory
  • Processes
  • Disks

By issuing the vmstat -s command, the user will also get virtual memory reports on other processes like Traps and Paging. The report will be shown in a single column statistics as shown in the image above.

/proc/meminfo

$ cat /proc/meminfo
MemTotal:        8167848 kB
MemFree:         1409696 kB
Buffers:          961452 kB
Cached:          2347236 kB
SwapCached:            0 kB
Active:          3124752 kB
Inactive:        2781308 kB
Active(anon):    2603376 kB
Inactive(anon):   309056 kB
Active(file):     521376 kB
Inactive(file):  2472252 kB
Unevictable:        5864 kB
Mlocked:            5880 kB
SwapTotal:       1998844 kB
SwapFree:        1998844 kB
Dirty:              7180 kB
Writeback:             0 kB
AnonPages:       2603272 kB
Mapped:           788380 kB
Shmem:            311596 kB
Slab:             200468 kB
SReclaimable:     151760 kB
SUnreclaim:        48708 kB
KernelStack:        6488 kB
PageTables:        78592 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6082768 kB
Committed_AS:    9397536 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      420204 kB
VmallocChunk:   34359311104 kB
HardwareCorrupted:   0 kB
AnonHugePages:      0 kB                                                                                      
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       62464 kB
DirectMap2M:     8316928 kB

The commands that we are discussing for checking the memory usage in Linux mostly extract data from the proc file. So, instead of running other memory usage commands you can directly open the proc file to see the memory usage statistics by running the proc/meminfo command.

Even though proc/meminfo is a virtual file but it contains the real-time dynamic information about the Linux system and its memory usage. Below are the processes for which proc file provides statistics.

  • Buffers
  • Cached
  • MemFree
  • MemTotal
  • SwapFree
  • SwapTotal

free command

$ free -m
            total used       free shared buffers     cached
Mem:          7976 6459       1517 0 865       2248
-/+ buffers/cache:       3344 4631
Swap:         1951 0       1951

The free command is the most simplest command in memory utilization in Linux that is used to check the memory usage in the system. This command is used when the user needs to see the status of the amount of memory that is free in the system along with the used memory reports.

So the free command, when executed mainly displays these three memory statistics:

  • The total amount of the swap memory in the system
  • All the caches and buffers used by the system's Kernel
  • The total amount of the free as well as the used physical memory of the system.

The user can easily issue this command from the terminal window but he/she needs to know that the output of the free command is not in real-time.

top command

top - 15:20:30 up  6:57, 5 users, load average: 0.64, 0.44, 0.33
Tasks: 265 total,   1 running, 263 sleeping,   0 stopped, 1 zombie
%Cpu(s):  7.8 us, 2.4 sy,  0.0 ni, 88.9 id, 0.9 wa,  0.0 hi, 0.0 si, 0.0 st
KiB Mem:   8167848 total,  6642360 used, 1525488 free,  1026876 buffers
KiB Swap:  1998844 total,        0 used, 1998844 free,  2138148 cached


 PID USER      PR NI VIRT RES  SHR S %CPU %MEM TIME+  COMMAND                                                             
2986 enlighte  20 0 584m 42m  26m S 14.3 0.5 0:44.27 yakuake                                                                                 
1305 root      20 0 448m 68m  39m S 5.0 0.9 3:33.98 Xorg                                                                                    
7701 enlighte  20 0 424m 17m  10m S 4.0 0.2 0:00.12 kio_thumbnail

The top command offers a real-time and dynamic view of your running system. We also use the top command in discovering the PIDs that are the Process ID numbers of the services. The PIDs helps the user in narrowing out the tasks that lead to troubleshooting issues.  

Also, the top command provides the user the real-time update on the statistics of how much swap space is currently being used in the system.

With the top command the user can check:

  • The memory as well as CPU usage per process
  • Reports the total memory usage
  • Real-time monitoring of RAM usage

dmidecode

The command of dmidecode is only used when the user needs to get the detailed information about his/her installed RAM system. For making these details into a human-readable format, the particular tool of the DMI table decoder is used. The DMI table will mainly inform you in detail about the what the system is made of.

So, these are some of the best Linux commands to try out in order to check the memory utilization and the memory usage. And if you agree with the above-mentioned commands and their usage. Then let us know if you think this article was helpful by clicking on the 'Yes' option below.

Read More About:

Akash Singh Chauhan
Written By
Akash Singh Chauhan

Akash Singh Chauhan is a senior writer at MobileAppDaily and he mainly covers all the latest happenings and tweaks in mobile app technology. Being an Engineering graduate he is always compelled to the technology and tries to discover new trends in the tech world. Along with any tech news he also never misses a single episode of ‘Dragon Ball’.

Top Companies

01.
InMobi
Singapore
02.
Dot Com Infoway
New York, USA
03.
M&C Saatchi Mobile
New York City, USA
04.
Techmagnate
New Delhi, India
05.
Fetch
London, UK
View full report

Latest Articles

Join our global community 135K Followers
app development

The Actual Cost Of Mobile App Development You Must Know

Joshua Anderson 4 min read  

Now there is no need to prove that mobile apps are an integral part of the business and play a crucial role in the world. In recent years, mobile apps have gone much higher in terms of generating revenue than a traditional website. It is seen, 65% of the revenue of an organization comes from the mob

app development

Build a Travel App for Better Revenue & Hassle-Free Traveling

Eric Jones 4 min read  

Technology is transforming the landscape of all industries and tourism sector is no exception. This is considered as one of the most thriving industries and according to the recent statistic, it is a huge 6.3 trillion dollar industry and now with the advent of travel apps, travelers are no more rely

app development

Battle Of The Best JavaScript Framework: ReactJS Vs Vue.js

Akash Singh Chauhan 4 min read  

Which is the best JavaScript Framework between React.JS and Vue.js?This is the question that a majority of people if not all have been asking for the past few years. And we can understand the reason behind this repetitive question as it is not an easy task to pick one from two of the best JavaSc

app development

Top Mobile App Development Trends To Drive The Industry In 2018

Vikram Khajuria 4 min read  

After moving away from the universe of web applications and desktop availability, we saw an upsurge in the people who adopted smartphone to access the internet. Mobile applications have gradually become a part of our life, from their essence in area-based applications, to its engagement in innovativ