• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to prioritize the devices used for swap partition

by admin

If you check the output of the swapon -s command, you would see the Priority column. The priority column defines the order in which the swap devices are used when required. In our example below the priority -1 is higher than the priority -2 (as the values are in negative).

# swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-1               partition	268435452	0	-1
/swapfile               file	      102396	0	-2

By default when the priorities are assigned as the swap devices are created and added as swap. But we can also change the priority of the devices.

Temporarily change the swap priority

1. Before changing the priority make sure the swap device is not in use by the system.

# free
              total        used        free      shared  buff/cache   available
Mem:      263847032     4561048   214238864      324524    45047120   257755920
Swap:     268537848           0   268537848

As seen in the output above, 0 MB of swap is being used currently.

2. Disable the swap devices

# swapoff /swapfile 
# swapoff /dev/dm-1
# swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-1                              	partition	268435452	0	-1

3. set the priority of the swap device /swapfile as 5 which higher than the priority of the other swap device(-1).

# swapon -p 5 /swapfile
# swapon -s
Filename				Type		Size	    Used	Priority
/dev/dm-1               partition	268435452	0	    -1
/swapfile               file	    102396	    0	     5

Persistently change the swap priority

To change the priority of swap device permanently, we have to edit the /etc/fstab file accordingly.

1. First, take the backup of /etc/fstab file.

# cp -p /etc/fstab /etc/fstba_orig

2. Modify the swap device priority of /swapfile to 5 from -2.

# vi /etc/fstab
/dev/mapper/vg_os-lv_swap swap                    swap    defaults        0 0
/swapfile           swap                    swap    pri=9         0 0

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to extend and reduce Swap Space on LVM2 Logical Volume
  2. Failed to Download Metadata for Repo ‘repo_name’
  3. CentOS / RHEL : How to move a Volume Group from one system to another
  4. How to use “yum downloadonly” to download a package without installing it
  5. How to Restrict Active Directory Users and Groups to Login to CentOS/RHEL 7 Client
  6. CentOS / RHEL : How to backup/restore configuration using authconfig
  7. Linux OS Service ‘rusersd’
  8. “error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory” ‘java -version’ error on Startup
  9. resize2fs Command Examples in Linux
  10. How To Create Virtual Data Optimizer(VD0) in CentOS/RHEL 7 and 8

You May Also Like

Primary Sidebar

Recent Posts

  • What are /dev/zero and /dev/null files in Linux
  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright