Summary of five commands to check swap space in Linux

Summary of five commands to check swap space in Linux

Preface

Two types of swap space can be created under Linux, one is a swap partition and the other is a swap file. The former is suitable for free partitions, while the latter is suitable for hard disks with no free partitions and the hard disk space has been allocated. For example: when installing Red Hat, you can divide the hard disk space by default, and the size of the swap area is the system default configuration. When you need to install an Oracle database after installing the system, it suddenly warns that there is not enough swap space. What to do now?

When the physical memory or RAM on our system is full, we end up utilizing the swap space on the system. During this process, inactive pages of memory are moved to swap space, creating more memory resources. This space is particularly useful when the system is powered off of RAM; however, swap space is located on the hard drive and is therefore slower to access. Therefore, it should not be considered a suitable alternative to RAM.

In this article, we will look at several ways to check available swap space on your Ubuntu system. The commands and procedures described in this article have been run on an Ubuntu 18.04 LTS system.

We are using the Ubuntu command line, the Terminal, to check the swap space on our system. To open Terminal, you can use the Dash or the Ctrl+alt+T shortcut. Then, you can choose the following ways to get swap space information:

Linux free command

Order:

free

This command is used to check the memory and swap utilization on the system in a few lines. Without any switches, the displayed output is printed in kilobytes.

Check swap space using free command

Order:

free -h

With the -h switch, the free command displays the memory and swap utilization in the nearest 3-digit format.

free -h Command

swapon Command

Order:

$ swapon -s

You can check swap for a specific partition, logical volume, or file using the swapon command. Here, we will use the -s (summary) switch to get the exchange details in kilobytes.

swapon Command

top Command

Order:

$ top

The header section of the top command output displays swap space information in kilobytes. Other commands that provide this information include htop, glances, and itop, among others.

Check swap usage using top command

vmstat Command

Order:

$ vmstat

The vmstat command allows you to view swap and swapping information. However, you cannot see the total value of the swap as shown by the previously mentioned command.

Check swap space using vmstat command

/proc/swaps File

Order:

$ cat /proc/swaps

You can also view swap size information via the swap configuration file /proc/swaps. It also displays swap information by device so that you can see the device name (partition, logical volume, or file), its type, and the amount of swap it provides to the system.

Check the contents of /proc/swaps

Although very simple commands are described in this article, you can view the swap space on your Ubuntu system and use it when your system is running low on RAM resources.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Check which processes occupy the swap partition in Linux to implement a script
  • The problem of linux vps server processes kswapd0 and events/0 consuming a lot of CPU
  • Detailed explanation of the role of swap partition under Linux
  • Detailed explanation of adding swap partition in CentOS7 in Linux
  • How to add and increase swap partition in Linux
  • Setting and adding/deleting swap partitions in Linux
  • How to add swap partition in Linux
  • Linux system disk formatting and manually adding swap partition

<<:  Summary of mysqladmin daily management commands under MySQL (must read)

>>:  Example of implementing todo application with Vue

Recommend

CSS style does not work (the most complete solution summary in history)

When we write pages, we sometimes find that the C...

Analysis of the Neglected DOCTYPE Description

doctype is one of them: <!DOCTYPE HTML PUBLIC &...

Tomcat common exceptions and solution code examples

The company project was developed in Java and the...

CSS to achieve the effect of rotating flip card animation

The css animation of the rotating flip effect, th...

Add a copy code button code to the website code block pre tag

Referring to other more professional blog systems...

Navicat multiple ways to modify MySQL database password

Method 1: Use the SET PASSWORD command First log ...

How to extract string elements from non-fixed positions in MySQL

Preface Note: The test database version is MySQL ...

Detailed explanation of the relationship between Linux and GNU systems

Table of contents What is the Linux system that w...

Detailed graphic tutorial on how to enable remote secure access with Docker

1. Edit the docker.service file vi /usr/lib/syste...

How to install theano and keras on ubuntu system

Note: The system is Ubuntu 14.04LTS, a 32-bit ope...

Let you understand how HTML and resources are loaded

All content in this blog is licensed under Creati...