How to set swap priority in Linux

How to set swap priority in Linux? Can I use 2 swap partition at the same time?

You can set the priority of swap in Linux by swapon.

For example, to set /dev/sdc1‘s priority to 0:

# swapoff /dev/sdc1; swapon -p 0 /dev/sdc1

You can also put one entry into the /etc/fstab to make it take effect each time Linux reboots:

/dev/sdc1 swap swap pri=0 0 0

You can set 2 swap partions to have the same priority, pages are allocated on a round-robin basis between them.

Priority

Each swap area has a priority, either high or low. The default
priority is low. Within the low-priority areas, newer areas are even
lower priority than older areas. All priorities set with swapflags are
high-priority, higher than default. They may have any non-negative
value chosen by the caller. Higher numbers mean higher priority.

Swap pages are allocated from areas in priority order, highest
priority first. For areas with different priorities, a higher-priority
area is exhausted before using a lower-priority area. If two or more
areas have the same priority, and it is the highest priority
available, pages are allocated on a round-robin basis between them.

As of Linux 1.3.6, the kernel usually follows these rules, but there
are exceptions.

From swapon manual.

Leave a Reply

Your email address will not be published. Required fields are marked *