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

Beginners understand MySQL deadlock problem from source code

After many difficult single-step debugging late a...

Share 13 excellent web wireframe design and production tools

When you start working on a project, it’s importa...

Introduction to the B-Tree Insertion Process

In the previous article https://www.jb51.net/arti...

Native JS to implement breathing carousel

Today I will share with you a breathing carousel ...

Detailed explanation of incompatible changes in rendering functions in Vue3

Table of contents Rendering API changes Render fu...

How to read the regional information of IP using Nginx and GeoIP module

Install GeoIP on Linux yum install nginx-module-g...

Some functions of using tcpdump to capture packets in the Linux command line

tcpdump is a flexible and powerful packet capture...

Solution for Nginx installation without generating sbin directory

Error description: 1. After installing Nginx (1.1...

SQL interview question: Find the sum of time differences (ignore duplicates)

When I was interviewing for a BI position at a ce...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

Three ways to jump to a page by clicking a button tag in HTML

Method 1: Using the onclick event <input type=...

Native js drag and drop function to create a slider example code

Drag and drop is a common function in the front e...

Oracle deployment tutorial in Linux environment

1. Environment and related software Virtual Machi...