What is Swap partition how do I use Swap partition on NVMe

What is Swap partition how do I use Swap partition on NVMe

tenco 2019-03-28

NVMe is the next phase of the solid-state storage era, improving performance on SSDS and other storage devices on the network.Now that more and more servers are supporting NVMe, IT's time for IT professionals to consider the use of Swap partitions to maximize the use of these systems.

Before looking at the use of Swap partitions on NVMe disks, we need to understand what Swap partitions are and why you should avoid them on SSDS in the first place.Then, this article explores the issue of using Swap partitions on NVMe.


The need for a Swap partition

Swap partitioning is like fire insurance. It's something you never want to use, but you have to be ready to use it.On a system that works the way you want it to, there should be enough memory to load programs and cache data.If your system has enough RAM, there will be no problem.

Swap partitions come into play when your system doesn't have enough RAM.A specific area of a hard disk that ACTS as extra RAM and serves as a swap area.

Linux systems may need swap areas for a number of reasons.This may be due to insufficient RAM, or it may be because some server-level applications (such as Oracle databases or SAP) require some swap space.There are exceptions, such as memory leaks in your application server.In this case, you run the risk of running out of memory, stopping the application, and customer dissatisfaction.

Swap partition and SSD

On traditional mechanical hard drives, the use of Swap partitions has never been an issue.However, this is not the case if you are using a SSD flash RAM unit with a finite lifetime.Every write on flash wears away the memory unit, and at some point, it stops working.

The life expectancy of an SSD device is expressed in TB write (TBW) values, which indicate how many bytes can be written before the SSD is corrupted.The TBW value of SSD devices is usually listed as a persistent parameter in the product specification.The TBW value of a disk depends on its quality. Low-end consumer SSDS can start to fail as low as 20 TBW, while enterprise/server SSDS can typically reach more than 1000 TBW.Limiting the use of Swap partitions reduces the number of writes on SSDS.

Use of Swap partitions on NVMe

The main difference between a normal SSD device and an NVMe device is the way they connect to the system bus.At the physical level, both device types use flash units to write data, which means there is no fundamental difference between SSD and NVMe TBW.But what does this mean for using Swap partitions on NVMe devices?This means that the rules that apply to non-nvme SSDS also apply to NVMe SSDS.

Let's be clear: if you run out of memory and Swap is always in use, it's best to put it on your hard drive.This does not apply to a typical Linux system, however, and most servers and workstations that use Linux handle the physical RAM installed well.

However, if the Linux kernel on these systems starts swapping memory pages to disk, it is important to see whether active or inactive memory pages are being swapped.Inactive memory pages are memory pages that have been allocated once and will not be used again.If your system is swapping only inactive pages, there is no reason to worry and no reason to avoid using Swap partitions on SSD or NVMe drives.This is because the inactive pages usually remain in their original position after being paged out, which means that only the inactive pages are paged out and the amount of data written to the swap is much lower.

The best way to find out if your system is actively using Swap partitions is to run the vmstat command, which provides a system-wide view of performance, including processes, Swap usage, memory, paging, and CPU activity.

For example, if you run the vmstat 2 100 command, it will display information about Swap 100 times in 2 seconds.You need to take a closer look at the SI and SO columns of the results of Swap In and Swap Out.The first line of vmstat output is a long summary that can be ignored.As the command generates output, you monitor what happens in the rest of these columns.If you don't see anything important, there's nothing to worry about.If you do see significant activity, then your SSD device is slowly wearing out and you'd better consider adding more RAM to the system.

天高科技