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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. Understanding OpenSSH Configuration Files
  2. How to set “max_report_luns” and “max_luns” on CentOS/RHEL 6 to scan more than 512 LUNs
  3. CentOS / RHEL 7 : Beginners guide to systemd
  4. Kernel Logs Warning Messages “kernel: Possible SYN flooding on port X. Sending cookies” is logged”
  5. CentOS / RHEL 7 : How to Change the machine-id
  6. How to use “btrfs scrub” command to manage scrubbing on Btrfs file systems
  7. fdisk: Unable to write /dev/sdg: Bad file descriptor – error while formatting USB disk
  8. How to use FTP under Linux to transfer files
  9. Linux OS Service ‘nfslock’
  10. CentOS / RHEL : How to Recover from deleted /etc/passwd file

You May Also Like

Primary Sidebar

Recent Posts

  • How to Configure Automatic Package Updates on the Server in CentOS/RHEL 8
  • FATAL: Error inserting rds_rdma
  • Failed to start LSB: Bring up/down networking – On restarting network service CentOS/RHEL (DHCP client)
  • How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary