How to check operative memory linux

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

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.

Читайте также:  Ndi scan converter windows

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, 5 Simple Commands

Home » SysAdmin » How to Check Memory Usage in Linux, 5 Simple Commands

It is essential that your Linux system runs at an optimal level. A few simple terminal commands provide access to all relevant information and help you monitor memory statistics.

In this tutorial, learn five powerful commands to check memory usage in Linux.

We also provide detailed explanations of what they do and more importantly, how to interpret the results. The commands will work with nearly all Linux distributions. In this instance, the commands and the results are presented using Ubuntu 18.04

  • Access to a command line / terminal
  • User with sudo privileges
  • The apt package manager

Commands to Check Memory Use in Linux

cat Command to Show Linux Memory Information

Entering cat /proc/meminfo in your terminal opens the /proc/meminfo file.

This is a virtual file that reports the amount of available and used memory. It contains real-time information about the system’s memory usage as well as the buffers and shared memory used by the kernel. The output might differ slightly based on the architecture and operating system in question.

This is an example of what the /proc/meminfo file looks like in Ubuntu 18.04:

The terminal displays the information in kilobytes.

free Command to Display the Amount of Physical and Swap Memory

Typing free in your command terminal provides the following result:

The data represents the used/available memory and the swap memory figures in kilobytes.

total Total installed memory
used Memory currently in use by running processes (used= total – free – buff/cache)
free Unused memory (free= total – used – buff/cache)
shared Memory shared by multiple processes
buffers Memory reserved by the OS to allocate as buffers when process need them
cached Recently used files stored in RAM
buff/cache Buffers + Cache
available Estimation of how much memory is available for starting new applications, without swapping.

Compared to the /proc/meminfo file, the free command provides less information. However, it is easier to understand. The key figure being the available value as it displays how much memory is still available for running new applications.

The free command has multiple options to format the output so that it better matches your requirements. The table below lists the most useful variations of the free command.

Options Result
-b output in bytes
– k output in kilobytes
– m output in megabytes
– g output in gigabytes
– l detailed low and high memory statistics
– o old format (no -/+buffers/cache line)
– t total for RAM + swap
– s update every [delay] seconds
– c update [count] times

Note: As with most commands, entering man free displays an overview of all variations and descriptions of the results.

vmstat Command to Report Virtual Memory Statistics

The vmstat command is a useful tool that reports virtual memory statistics.

vmstat provides general information about processes, memory, paging, block IO, traps, and CPU activity.

The detailed description listed below provides an explanation for each value in case you need assistance in analyzing the results.

  • Procs
    • r: number of processes waiting for run time.
    • b: number of processes in uninterruptible sleep.
  • Memory
    • swpd: amount of virtual memory used.
    • free: amount of idle memory.
    • buff: the amount of memory used as buffers.
    • cache: amount of memory used as cache.
  • Swap
    • si: memory swapped in from disk (/s).
    • so: memory swapped to disk (/s).
  • IO
    • bi: Blocks received from a block device (blocks/s).
    • bo: Blocks sent to a block device (blocks/s).
  • System
    • in: number of interrupts per second, including the clock.
    • cs: number of context switches per second.
  • CPU – These are percentages of total CPU time.
    • us: Time spent running non-kernel code. (user time, including nice time)
    • sy: Time spent running kernel code. (system time)
    • id: Time spent idle. Before Linux 2.5.41, this includes IO-wait time.
    • wa: Time spent waiting for IO. Before Linux 2.5.41, included in idle.
    • st: Time stolen from a virtual machine. Before Linux 2.6.11, unknown.
Читайте также:  Жесткий диск стал медленно работать windows 10

top Command to Check Memory Use

The top command is useful to check memory and CPU usage per process. It displays information about:

  • uptime
  • average load
  • tasks running
  • number of users logged in
  • number of CPUs/CPU utilization
  • memory/swap system processes

The data is continuously updated, which allows you to follow the processes in real-time.

Aside from providing you with essential memory information, the top command provides a limited interactive interface. It is possible to manipulate and configure operations by using command-line options.

The man command in Linux man top provides a comprehensive list of all available variations.

htop Command to Find Memory Load of Each Process

The information the htop command provides is similar to the top command. However, the real advantage to the htop command is its user-friendly environment and improved controls.

The command uses color for its output, provides full command lines for processes, as well as the option to scroll both vertically and horizontally.

The following output appears:

  1. The top segment provides summary information and contains graphic meters and text counters.
  2. The lower section structures the detailed data, per process. This allows you to perform actions on individual processes with ease.
  3. The shortcuts listed at the bottom of the screen will enable you to manipulate and customize the processes quickly and without the need to type specific commands.

Note: If you run into “Command ‘htop’ not found” message when trying to run the htop command, you will need to install the htop function first:

As an alternative, use the command below:

Checking Memory Usage in Linux using the GUI

Using a graphical interface for server administration is not common practice. However, certain data sets are much clearer, with a visual representation of memory usage.

To access the System Monitor:

  1. Navigate to Show Applications.
  2. Enter System Monitor in the search bar and access the application.
  3. Select the Resources tab.
  4. A graphical overview of your memory consumption in real time, including historical information is displayed.

This guide provided several options to check memory usage on your Linux system. We learned that a single command provides an abundance of valuable data for future analysis. Learning to interpret the information correctly is critical.

Now you can administer your server more efficiently.

Источник

8 Commands to Check Memory Usage on Linux

Linux is not like Windows and you will not get a GUI always, especially in a server environment.

As a Linux administrator, it is important to know how to check your available and used resources, such as memory, CPU, disk space, etc.

If there are any applications that use too much resources on the system to run your system at the optimum level you need to find and fix.

If you want to find out the top 10 memory (RAM) consumption processes in Linux, go to the following article.

In Linux, there are commands for everything, so use the corresponding commands.

In this tutorial, we will show you eight powerful commands to check memory usage on a Linux system, including RAM and swap.

The following commands can help you check memory usage in Linux in different ways.

  • free Command
  • /proc/meminfo File
  • vmstat Command
  • ps_mem Command
  • smem Command
  • top Command
  • htop Command
  • glances Command

1) How to Check Memory Usage on Linux Using the free Command

Free command is the most powerful command widely used by the Linux administrator. But it provides very little information compared to the “/proc/meminfo” file.

Free command displays the total amount of free and used physical and swap memory on the system, as well as buffers and caches used by the kernel.

These information is gathered from the “/proc/meminfo” file.

  • total: Total installed memory
  • used: Memory is currently in use by running processes (used= total – free – buff/cache)
  • free: Unused memory (free= total – used – buff/cache)
  • shared: Memory shared between two or more processes (multiple processes)
  • buffers: Memory reserved by the kernel to hold a process queue request.
  • cache: Size of the page cache that holds recently used files in RAM
  • buff/cache: Buffers + Cache
  • available: Estimation of how much memory is available for starting new applications, without swapping.
Читайте также:  Куда устанавливается windows папка

2) How to Check Memory Usage on Linux Using the /proc/meminfo File

The “/proc/meminfo” file is a virtual file that contains various real-time information about memory usage.

It shows memory stats in kilobytes, most of which are somewhat difficult to understand.

However it contains useful information about memory usage.

3) How to Check Memory Usage on Linux Using the vmstat Command

The vmstat command is another useful tool for reporting virtual memory statistics.

vmstat reports information about processes, memory, paging, block IO, traps, disks, and cpu functionality.

vmstat does not require special permissions, and it can help identify system bottlenecks.

If you want to understand this in detail, read the field description below.

Procs

  • r: The number of runnable processes (running or waiting for run time).
  • b: The number of processes in uninterruptible sleep.

Memory

  • swpd: the amount of virtual memory used.
  • free: the amount of idle memory.
  • buff: the amount of memory used as buffers.
  • cache: the amount of memory used as cache.
  • inact: the amount of inactive memory. (-a option)
  • active: the amount of active memory. (-a option)

Swap

  • si: Amount of memory swapped in from disk (/s).
  • so: Amount of memory swapped to disk (/s).

IO

  • bi: Blocks received from a block device (blocks/s).
  • bo: Blocks sent to a block device (blocks/s).

System

  • in: The number of interrupts per second, including the clock.
  • cs: The number of context switches per second.

CPU : These are percentages of total CPU time.

  • us: Time spent running non-kernel code. (user time, including nice time)
  • sy: Time spent running kernel code. (system time)
  • id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
  • wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
  • st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

Run the following command for detailed information.

4) How to Check Memory Usage on Linux Using the ps_mem Command

ps_mem is a simple Python script that allows you to get core memory usage accurately for a program in Linux.

This can determine how much RAM is used per program (not per process).

It calculates the total amount of memory used per program, total = sum (private RAM for program processes) + sum (shared RAM for program processes).

The shared RAM is problematic to calculate, and the tool automatically selects the most accurate method available for the running kernel.

5) How to Check Memory Usage on Linux Using the smem Command

smem is a tool that can provide numerous reports of memory usage on Linux systems. Unlike existing tools, smem can report Proportional Set Size (PSS), Unique Set Size (USS) and Resident Set Size (RSS).

Proportional Set Size (PSS): refers to the amount of memory used by libraries and applications in the virtual memory system.

Unique Set Size (USS) : Unshared memory is reported as USS (Unique Set Size).

Resident Set Size (RSS) : The standard measure of physical memory (it typically shared among multiple applications) usage known as resident set size (RSS) will significantly overestimate memory usage.

6) How to Check Memory Usage on Linux Using the top Command

top command is one of the most frequently used commands by Linux administrators to understand and view the resource usage for a process on a Linux system.

It displays the total memory of the system, current memory usage, free memory and total memory used by the buffers.

In addition, it displays total swap memory, current swap usage, free swap memory, and total cached memory by the system.

7) How to Check Memory Usage on Linux Using the htop Command

The htop command is an interactive process viewer for Linux/Unix systems. It is a text-mode application and requires the ncurses library, it was developed by Hisham.

It is designed as an alternative to the top command.

This is similar to the top command, but allows you to scroll vertically and horizontally to see all the processes running the system.

htop comes with Visual Colors, which have added benefits and are very evident when it comes to tracking system performance.

You are free to carry out any tasks related to processes, such as process killing and renicing without entering their PIDs.

8) How to Check Memory Usage on Linux Using the glances Command

Glances is a cross-platform system monitoring tool written in Python.

You can see all information in one place such as CPU usage, Memory usage, running process, Network interface, Disk I/O, Raid, Sensors, Filesystem info, Docker, System info, Uptime, etc,.

Источник

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