Linux see memory usage

How to check memory usage per process in Linux

Table of Contents

Linux check memory usage per process. how to check which process is using more memory in Linux. Linux how much memory is a process using. Linux track process memory usage over time. linux check memory usage per process in mb. Linux check memory. linux show memory usage. linux see memory usage. linux memory usage info. linux process memory usage. how to check memory usage in linux.


There are several metrics available to check memory usage per process in Linux. I will begin with the two that are easiest to obtain

  • the virtual set size (vss)
  • the resident memory size (rss)

both of which are available in most implementations of the ps and top commands.

    Vss: called VSZ in the ps command and VIRT in top , is the total amount of memory mapped by a process. It is the sum of all the regions shown in /proc/

/map . This number is of limited interest, since only part of the virtual memory is committed to physical memory at any one time.

  • Rss: called RSS in ps and RES in top , is the sum of memory that is mapped to physical pages of memory. This gets closer to the actual memory budget of the process, but there is a problem, if you add up the Rss of all the processes, you will get an overestimate the memory in use because some pages will be shared.
  • Using top and ps to check memory usage per process (VSS and RSS)

    The ps command shows Vss (VSZ) and Rss (RSS) with the options, -Aly , and a custom format which includes vsz and rss , as shown here

    Likewise free and top also shows a summary of the free memory and memory usage per process:

    Using smem to check memory usage per process

    In 2009, Matt Mackall began looking at the problem of accounting for shared pages in process memory measurement and added two new metrics called the unique set size or Uss , and the proportional set size or Pss

    • Uss: This is the amount of memory that is committed to physical memory and is unique to a process; it is not shared with any other. It is the amount of memory that would be freed if the process were to terminate.
    • Pss: This splits the accounting of shared pages that are committed to physical memory between all the processes that have them mapped. For example, if an area of library code is 12 pages long and is shared by six processes, each will accumulate two pages in Pss . Thus, if you add the Pss numbers for all processes, you will get the actual amount of memory being used by those processes. In other words, Pss is the number we have been looking for.

    The information is available in /proc/

    /smaps , which contains additional information for each of the mappings shown in /proc/

    /maps . Here is one section from such a file which provides information about the mapping for the libc code segment:

    Читайте также:  Сервер облачного хранилища для windows

    There is a tool named smem that collates the information from the smaps files and presents it in various ways, including as pie or bar charts. The project page for smem is https://www.selenic.com/smem.

    There are various filters which you can apply with smem as shown below with the latest available release (1.4) at the time of writing this article

    To check memory usage per process in total we can execute below command

    This will give you memory usage detail of every process active on your system.

    To get the memory usage of a single process we can grep the process from the list

    Here as you see we get similar results as above with /proc/31768/smaps and with smem tool. So the actual memory usage of amsHelper is 56.4 MB

    Lastly I hope the steps from the article to check memory usage per process on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

    Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

    If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

    For any other feedbacks or questions you can either use the comments section or contact me form.

    Thank You for your support!!

    5 thoughts on “How to check memory usage per process in Linux”

    There’s definately a lot to know about this
    issue. I really like all of the points you’ve made.

    I am happy that I noticed this site, precisely the right information that I was looking for! .

    Thank you – excellent writeup!
    But I would add this, from the smem man page: The USS and PSS only include physical memory usage. They do not include memory that has been swapped out to disk”
    I’d also note that it would be faster and easier to choose the process via the -P option:
    smem -k -P amsHelper

    Thank you for sharing this additional information.

    Cool! Thanks for the full ps flags to list the many kinds of memory options, as well as the tip about looking at the /proc/PID/smaps file for more information. I was trying to figure out how much memory one of my processes was consuming, but, alas, my Linux distro (running on an embedded system) has no way to install either smem or the other popular pmap tool. I’ve been just using good, old top for that, but your article gave me a vast array of many more suggestions! Thanks so much for that 🙂

    Источник

    5 commands to check memory usage on Linux

    Memory Usage

    On linux, there are commands for almost everything, because the gui might not be always available. When working on servers only shell access is available and everything has to be done from these commands. So today we shall be checking the commands that can be used to check memory usage on a linux system. Memory include RAM and swap.

    It is often important to check memory usage and memory used per process on servers so that resources do not fall short and users are able to access the server. For example a website. If you are running a webserver, then the server must have enough memory to serve the visitors to the site. If not, the site would become very slow or even go down when there is a traffic spike, simply because memory would fall short. Its just like what happens on your desktop PC.

    1. free command

    The free command is the most simple and easy to use command to check memory usage on linux. Here is a quick example

    Читайте также:  Телевизор как монитор для компьютера hdmi windows 10

    The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by linux, in this case around 6.4 GB. The output is pretty self explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in first line added with the buffers and cached amount of memory.

    Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed.
    The last line is the swap memory, which in this case is lying entirely free.

    2. /proc/meminfo

    The next way to check memory usage is to read the /proc/meminfo file. Know that the /proc file system does not contain real files. They are rather virtual files that contain dynamic information about the kernel and the system.

    Check the values of MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree.
    They indicate same values of memory usage as the free command.

    3. vmstat

    The vmstat command with the s option, lays out the memory usage statistics much like the proc command. Here is an example

    The top few lines indicate total memory, free memory etc and so on.

    4. top command

    The top command is generally used to check memory and cpu usage per process. However it also reports total memory usage and can be used to monitor the total RAM usage. The header on output has the required information. Here is a sample output

    Check the KiB Mem and KiB Swap lines on the header. They indicate total, used and free amounts of the memory. The buffer and cache information is present here too, like the free command.

    5. htop

    Similar to the top command, the htop command also shows memory usage along with various other details.

    The header on top shows cpu usage along with RAM and swap usage with the corresponding figures.

    RAM Information

    To find out hardware information about the installed RAM, use the demidecode command. It reports lots of information about the installed RAM memory.

    Provided information includes the size (2048MB), type (DDR2) , speed(667 Mhz) etc.

    Summary

    All the above mentioned commands work from the terminal and do not have a gui. When working on a desktop with a gui, it is much easier to use a GUI tool with graphical output. The most common tools are gnome-system-monitor on gnome and
    ksysguard on KDE. Both provide resource usage information about cpu, ram, swap and network bandwidth in a graphical and easy to understand visual output.

    A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

    66 thoughts on “ 5 commands to check memory usage on Linux ”

    You have explained the topic very well. Thanks for sharing a nice article.

    Thanks for these commands. It saved a lots of time.

    How about explaining what we are looking for? Most people would know these commands. Waste of time.

    Please correct the typo in “RAM Information” section. The command for viewing hardware info about RAM is “dmidecode” and not “demidecode”.
    And it also requires root privileges.

    Источник

    How to Check Memory Usage in Linux? Use These 5 Commands

    When using any Linux distribution, it is important as a SysAdmin to know how to visualize your available and used resources, such as memory, CPU, disk space, etc.

    We have already showed you how to check CPU info in Linux, today, I am going to show how to check memory in Linux.

    Читайте также:  Extended журнальный для windows

    Note: Memory, physical memory terms are used for RAM (which is a more popular term). In other words, if you want to check RAM usage in Linux, you use the memory related commands. If you want to check disk space in Linux, you use disk related commands.

    5 Commands to check memory usage in Linux

    In this article, we will cover how to check memory in different ways and explain a little bit how each of the command lines for this purpose works.

    1. free

    The free command in Linux has the simplest output. It shows the amount of free and used memory on your Linux system.

    You can see the free and used physical memory i.e. RAM, the swap usage and the buffer used by the Linux kernel.

    All you have to do is to type free in the terminal and hit enter:

    You can see that the free command provides only the necessary info at a glance.

    2. top

    This is probably one of the most common and the one that I use at first. It gives the information about memory and CPU. Here is a screenshot of how it looks:

    top command running

    In the header you will notice how it reports the total amount of memory, the amount used and the amount free, and this for both regular (RAM) memory and SWAP memory as well. It also gives you a real time visualization of the current running processes and the amount each one is consuming.

    3. htop

    htop is very similar in functionality to the top command, yet it’s slightly different. It is a bit more graphical and shows information a little more friendlier than top, however, it is also a real time visualization:

    htop running

    You can see the used memory out of the available memory beside the Mem line on the top left section.

    4. /proc/meminfo

    Even though it might seem like we are consulting a file, in reality whatever in contained inside “proc” folder is just virtual files that display information directly from kernel.

    This one method gives you very detailed information about the memory, not only a general view but even the amount of pages of memory being used.

    You can use any file viewing Linux command to display the content of the file. I have used cat command in my example below.

    /proc/meminfo

    Explaining in deep all this information would require an entire article so I am not going to to do that here.

    5. vmstat -m

    Like the /proc/meminfo, this one gives you information directly from kernel, in fact, only a superuser can execute it (so if you are running a Debian or Ubuntu based, you will need to sudo it).

    It gives you a very in deep detail about the memory available and the pages of memory being used:

    sudo vmstat -m

    Bonus: RAM information with dmidecode

    Dmidecode is more about the memory chip physically, it gives information about the actual chips allocated in your computer, so it allows you to know more things about the current installed memory such as: where is it physically located (which memory bank), what type of memory is it (DIMM, SIMM), speed, manufacturer, voltage and even if any error is currently being detected.

    Running it as: sudo dmidecode -t 17 will give you information similar to this screenshot:

    sudo dmidecode -t 17

    Wrapping up

    As usual, Linux offers you several ways to consult information about something, in this case checking memory usage in your system. This information depending for what is needed and how it’s used can be very useful and provide valuable information as SysAdmin.

    Источник

    Оцените статью