How to Check RAM Usage on Ubuntu

How to Check RAM Usage on Ubuntu

In Ubuntu, you can check the RAM (Random Access Memory) usage of your system with multiple methods available via both the GUI (Graphical User Interface) and the command line. Checking the memory usage on Ubuntu server is quite a straightforward process.

Understanding the amount of memory used and available is essential for troubleshooting and optimizing your web server performance since RAM is a vital system component that provides fast read and write access to a storage medium. Regularly monitoring this metric can aid in diagnosing potential system issues, optimizing server performance, and determining the necessity for a RAM upgrade.

In this quick guide, we will elucidate various prevalent methods to inspect RAM usage on Ubuntu, employing an array of commands and tools, ensuring you have a comprehensive understanding of how to monitor it on your Linux system.

Let’s get started!

Option 1: Check RAM Using the “free” Command

The “free” command displays the amount of free and used memory in the system. To use this command, open a terminal and type the following command:

free

The output will display the total amount of RAM, used RAM, free RAM, and shared memory. The output will also show the buffers and cached memory.

root@geeks:~# free
              total        used        free      shared  buff/cache   available
Mem:       16424164      966948    14938512       81844      518704    15102152
Swap:             0           0           0

Option 2: Check RAM Using the “top” Command

The “top” command displays the system processes and their resource usage, including RAM usage. To use this command, open a terminal and type the following command:

top

The output will display the list of processes running on the system, including their PID, user, CPU usage, and RAM usage. You’ll see memory usage displayed as KiB Mem and KiB Swap.

top - 13:23:44 up 20 days, 21:24,  1 user,  load average: 0.00, 0.00, 0.00
Tasks: 176 total,   1 running, 109 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16424164 total, 11720752 free,  1438952 used,  3264460 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 14579664 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 2416 root      20   0   42812   3960   3304 R   0.3  0.0   0:00.02 top
    1 root      20   0  225268   8920   6560 S   0.0  0.1   0:46.62 systemd
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.60 kthreadd
    4 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/0:0H
    6 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 mm_percpu_wq
    7 root      20   0       0      0      0 S   0.0  0.0   0:01.82 ksoftirqd/0
    8 root      20   0       0      0      0 I   0.0  0.0   3:09.90 rcu_sched
    9 root      20   0       0      0      0 I   0.0  0.0   0:00.00 rcu_bh
   10 root      rt   0       0      0      0 S   0.0  0.0   0:00.73 migration/0
   11 root      rt   0       0      0      0 S   0.0  0.0   0:04.07 watchdog/0
   12 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/0
   13 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/1
   14 root      rt   0       0      0      0 S   0.0  0.0   0:03.22 watchdog/1
   15 root      rt   0       0      0      0 S   0.0  0.0   0:00.76 migration/1
   16 root      20   0       0      0      0 S   0.0  0.0   0:00.92 ksoftirqd/1
   18 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/1:0H
   19 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/2
   20 root      rt   0       0      0      0 S   0.0  0.0   0:03.19 watchdog/2
   21 root      rt   0       0      0      0 S   0.0  0.0   0:00.77 migration/2
   22 root      20   0       0      0      0 S   0.0  0.0   0:00.90 ksoftirqd/2
   24 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/2:0H
   25 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/3
   26 root      rt   0       0      0      0 S   0.0  0.0   0:03.11 watchdog/3
   27 root      rt   0       0      0      0 S   0.0  0.0   0:00.78 migration/3
   28 root      20   0       0      0      0 S   0.0  0.0   0:00.96 ksoftirqd/3
   30 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/3:0H
   31 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/4
   32 root      rt   0       0      0      0 S   0.0  0.0   0:03.04 watchdog/4
   33 root      rt   0       0      0      0 S   0.0  0.0   0:00.80 migration/4
   34 root      20   0       0      0      0 S   0.0  0.0   0:00.90 ksoftirqd/4                                              

Option 3: Check RAM Using the “htop” Command

The “htop” command is an enhanced version of the “top” command, which displays the system processes and their resource usage in a more user-friendly way. To use this command, open a terminal and type the following command:

apt-get install htop
htop

The output will display the list of processes running on the system, including their PID, user, CPU usage, and RAM usage.

  1  [                                                0.0%]   5  [                                                0.0%]
  2  [|                                               0.7%]   6  [|                                               0.7%]
  3  [                                                0.0%]   7  [                                                0.0%]
  4  [                                                0.0%]   8  [                                                0.0%]
  Mem[||||||||||||||||                         1.48G/15.7G]   Tasks: 63, 127 thr; 1 running
  Swp[                                               0K/0K]   Load average: 0.00 0.00 0.00
                                                              Uptime: 20 days, 21:21:36

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 1145 root       20   0 32248  4808  3876 R  0.7  0.0  0:00.37 htop
 1112 root       20   0  870M 26976 10148 S  0.7  0.2  1h11:32 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
  472 root       19  -1  395M  251M  239M S  0.7  1.6  3:42.68 /lib/systemd/systemd-journald
 1213 root       20   0  870M 26976 10148 S  0.7  0.2 10:29.64 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1721 root       20   0  103M  6812  5840 S  0.7  0.0  0:00.01 sshd: [accepted]
 1201 mysql      20   0 9094M 1047M 17700 S  0.0  6.5 47:05.51 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
 1234 root       20   0  870M 26976 10148 S  0.0  0.2 10:27.77 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1214 root       20   0  870M 26976 10148 S  0.0  0.2 10:17.40 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1235 root       20   0  870M 26976 10148 S  0.0  0.2 12:40.85 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1056 messagebu  20   0 50412  4736  3768 S  0.0  0.0  1:24.34 /usr/bin/dbus-daemon --system --address=systemd: --nofork --no
 1087 root       20   0  282M  6568  5776 S  0.0  0.0  0:40.59 /usr/lib/policykit-1/polkitd --no-debug
 1541 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  0:53.64 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
 7150 www-data   20   0  434M  106M 91368 S  0.0  0.7  0:03.17 /usr/sbin/apache2 -k start
 3028 www-data   20   0 88640 15588  6100 S  0.0  0.1 15:07.81 nginx: worker process
17259 www-data   20   0  432M  105M 92360 S  0.0  0.7  0:02.17 /usr/sbin/apache2 -k start
 1240 root       20   0  870M 26976 10148 S  0.0  0.2  5:13.80 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
27244 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  0:20.36 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
 1239 root       20   0  870M 26976 10148 S  0.0  0.2  4:09.77 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1238 root       20   0  870M 26976 10148 S  0.0  0.2  4:07.15 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1244 root       20   0  870M 26976 10148 S  0.0  0.2  4:07.28 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
 1538 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  1:39.13 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
  984 root       20   0  103M  7120  6128 S  0.0  0.0  0:00.04 sshd: root@pts/0
 1539 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  1:09.05 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
10277 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  0:45.94 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
 1540 mysql      20   0 9094M 1047M 17700 S  0.0  6.5  1:14.24 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Option 4. Check RAM Using the `vmstat` Command

vmstat is a tool that reports virtual memory statistics. It provides information about processes, memory, paging, block IO, traps, and CPU activity.

See also  How to Uninstall InfluxDB on Ubuntu

To use vmstat, simply type:

vmstat

Look at the “swpd” (swap used) and “free” (free memory) columns for details on memory usage.

root@geeks:~# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 11715776 193944 3070816    0    0     0     9    0    3  0  0 100  0  0

Option 5. Check RAM Using the `cat` Command with `/proc/meminfo`

The /proc/meminfo file contains detailed information about the system’s memory usage.

To view its contents, use:

cat /proc/meminfo

This will display a detailed breakdown of your system’s memory, including total, free, used, and other memory-related statistics.

root@geeks:~# cat /proc/meminfo
MemTotal:       16424164 kB
MemFree:        11727596 kB
MemAvailable:   14587452 kB
Buffers:          193944 kB
Cached:          2770224 kB
SwapCached:            0 kB
Active:          2908184 kB
Inactive:        1335364 kB
Active(anon):    1369208 kB
Inactive(anon):     6508 kB
Active(file):    1538976 kB
Inactive(file):  1328856 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:       1279404 kB
Mapped:           293980 kB
Shmem:             96340 kB
Slab:             375684 kB
SReclaimable:     301232 kB
SUnreclaim:        74452 kB
KernelStack:        5008 kB
PageTables:        19040 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     8212080 kB
Committed_AS:    6095528 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      235376 kB
DirectMap2M:     7104512 kB
DirectMap1G:    11534336 kB

Option 6: Check RAM Using the System Monitor

The System Monitor is a graphical tool that displays the system processes and resource usage. To use this tool, go to the Applications menu, click on the System Tools, and select the System Monitor. In the System Monitor, go to the Resources tab, and you will see the RAM usage and other resource usage information.

See also  How to Check if Ubuntu Server is Connected to the Internet

Option 7. Check RAM Using the `gnome-system-monitor`

If you’re using the GNOME desktop environment, you can use the gnome-system-monitor:

Press Alt + F2, type gnome-system-monitor, and press Enter. Navigate to the “Resources” tab to view memory usage.

Option 8. Check RAM Using `glances`

glances is an advanced system monitoring tool that provides a comprehensive overview of various system resources, including memory.

To install glances, use:

apt install glances

Once installed, run it by typing:

glances

Option 9. Check RAM Using `nmon`

nmon is another system monitoring tool that provides information about various system resources, including memory.

To install nmon, use:

apt install nmon

After installation, run it by typing:

nmon

Press ‘m’ to view memory statistics.

Option 10. Check RAM Using `smem`

smem provides memory usage reports with a focus on “proportional set size” (PSS), which is a more accurate representation of the memory being used by applications and processes.

To install smem, use:

apt install smem

Run it by simply typing:

smem

Commands Mentioned:

  • free – a command that displays the amount of free and used memory in the system.
  • top – a command that displays the system processes and their resource usage, including RAM usage.
  • htop – an enhanced version of the “top” command that displays the system processes and their resource usage in a more user-friendly way.
  • cat /proc/meminfo – Shows detailed information about the system’s memory usage.
  • gnome-system-monitor – Opens the GNOME system monitor for graphical representation of system resources, including memory.
  • glances – Runs the `glances` tool to view comprehensive system resource usage.
  • nmon – Runs the `nmon` tool for system monitoring, press ‘m’ to view memory statistics.
  • smem – Runs the `smem` tool to view memory usage based on proportional set size.
See also  How to Uninstall Let's Encrypt Certbot on Ubuntu

Conclusion:

Monitoring RAM usage on Ubuntu is straightforward, whether you prefer using the graphical interface or the command line. Regularly checking your RAM can help ensure your system runs smoothly and allows you to make informed decisions about potential upgrades or optimizations. Remember, understanding your system’s resources is key to maintaining its health and performance.

In this guide, we have gone through various ways to check the RAM on Ubuntu using different commands and tools. By using these commands and tools, you can easily obtain the necessary information about the RAM usage of your system.

If you’re on the hunt for the best web hosting solutions tailored for Ubuntu, look no further. We’ve done the heavy lifting for you. After extensive testing and research, we’ve compiled a definitive list of the top Ubuntu hosting providers for 2023. Make sure to check out our “Best Ubuntu Hosting 2023” guide to ensure your projects are powered by the best in the business.

If you have any questions or suggestions, feel free to comment below.

FAQs

  1. Why is it important to monitor memory usage on Ubuntu?

    Monitoring memory usage on Ubuntu helps in understanding the system’s performance, identifying potential bottlenecks, and ensuring that applications run smoothly. Regular checks can also help in troubleshooting issues, optimizing system performance, and determining if there’s a need for a RAM upgrade.

  2. What’s the difference between `top` and `htop`?

    Both `top` and `htop` are system monitoring tools, but `htop` provides a more user-friendly interface with color-coded outputs and allows for interactive process management. While `top` provides a static view, `htop` offers a real-time, dynamic display and supports mouse operations.

  3. How can I check memory usage using the graphical interface on Ubuntu?

    You can use the “System Monitor” tool, which is Ubuntu’s default system resource and process monitoring tool. Navigate to the Ubuntu Dash or Show Applications, search for “System Monitor”, open it, and click on the “Resources” tab to view memory usage.

  4. What is “proportional set size” (PSS) in `smem`?

    Proportional Set Size (PSS) is a metric used by `smem` to provide a more accurate representation of the memory being used by applications and processes. PSS calculates the memory usage of each process, considering shared libraries, and divides it proportionally among the processes using those libraries. This gives a clearer picture of the actual memory footprint of processes.

  5. Why might I see different memory values in different tools?

    Different tools might display varying memory values due to the way they calculate and represent memory usage. Some tools might show raw values, while others account for buffers, caches, and shared memory. It’s essential to understand the metrics each tool provides to interpret the data accurately.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *