LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-13-2016, 09:34 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
Use cases for multiple swap partitions on single and multiple disks?


What use cases would require a system to have
multiple swap partitions and/or swap files (on a single disk?) ?

On multiple disk systems, what use cases would justify trying
to spread swap over disk and how do we go about doing that?

How does Linux knows all the spread out SWAP files or partitions are one single SWAP file.

Thank you.

Last edited by fanoflq; 04-13-2016 at 09:52 PM.
 
Old 04-14-2016, 12:26 AM   #2
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 270

Rep: Reputation: Disabled
Quote:
Originally Posted by fanoflq View Post
What use cases would require a system to have
multiple swap partitions and/or swap files (on a single disk?) ?
In order of performance:

0. multiple disks, raw partitions

1. md raid0 pair, raw partition. high risk if either partition fails
2. md raid10,f2 pair, raw partition. best balance of performance and safety
3. md raid1, raw partition. better safety than single disk

4. single disk, least used, raw partition
5a. raw partition
5b. swap file

The last three are about the same.

Cheers,
 
Old 04-14-2016, 01:11 AM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Thank you for your response.
It is a little cryptic for me....
So here are my questions... so I can understand your previous response better.

Quote:
In order of performance:

0. multiple disks, raw partitions
You kept mentioning raw partitions multiple times.
Not sure what do you mean by raw partitions.
We cannot use raw partitions until we format it with a filesystem.
So why are the (unusable) raw partitions relevant to performance?
How does raw partition relate to swap partition and disk performance?

Here is scenario for your case:
On a single Linux system, you have swap partitions on multiple disk.
So you have these hard drives: sda, sdb, sdc, sdd.
And you create these corresponding swap partitions:
sda4,sdb4, sdc4, sdd4.

Does Linux know all these are to be used as swap partitions?
How to inform Linux these partitions are to behave as a single swap file?


Quote:
1. md raid0 pair, raw partition. high risk if either partition fails

2. md raid10,f2 pair, raw partition. best balance of performance and safety
3. md raid1, raw partition. better safety than single disk
I do not know much about raids to ask questions for now.


Quote:
4. single disk, least used, raw partition
What do you mean by least used?

Quote:
5a. raw partition
5b. swap file
When you say swap file, does it also mean swap partition?
 
Old 04-15-2016, 03:25 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
'swap' is a filesystem type ; look into your /etc/fstab file.
After you create a 'swap' type partition it must be added as an entry in /etc/fstab for persistence.
You'd use http://linux.die.net/man/8/swapon to activate a swap partition after you create it.

HTH
 
1 members found this post helpful.
Old 04-15-2016, 03:57 AM   #5
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
chrism01:

Thank you.
How about use cases?
What scenarios would we want to use multiple swap partitions?
 
Old 04-15-2016, 04:50 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, multiple swap partitions are pretty rare, but one use case is this:

If you've built a system (inc a swap partition) and subsequently need more swap space AND there is no unused disk space at the end of the swap partition.... Rather than rebuild the entire system, just add some swap elsewhere on the next available disk space.

Hypothetically, I can see if you have a LOT of disks on a system and you know you'll need swap, you could spread the load over multiple drives. This prevents I/O bottlenecking... in fact you'd want to spread the I/O load over multiple disk controller cards / buses, not necessarily just the drives.
This example is a real niche case, but it could happen.

HTH
 
1 members found this post helpful.
Old 04-15-2016, 09:01 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
My primary swap area is an SSD partition. I don't want to devote a lot of SSD space to swap, so my "just in case" swap area is a partition on a rotating disk. And no, I'm not worried about wearing out my SSD. If you have enough swap activity to significantly impact the life of a modern SSD, your system would be unusably slow if the swap were on anything except an SSD.
 
Old 04-15-2016, 04:02 PM   #8
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 270

Rep: Reputation: Disabled
Quote:
Originally Posted by fanoflq View Post
You kept mentioning raw partitions multiple times.
Not sure what do you mean by raw partitions.
We cannot use raw partitions until we format it with a filesystem.
So why are the (unusable) raw partitions relevant to performance?
How does raw partition relate to swap partition and disk performance?
Swap uses disk blocks without any filesystem. It can use a whole unformatted disk or an unformatted partition.

Quote:
Here is scenario for your case:
On a single Linux system, you have swap partitions on multiple disk.
So you have these hard drives: sda, sdb, sdc, sdd.
And you create these corresponding swap partitions:
sda4,sdb4, sdc4, sdd4.

Does Linux know all these are to be used as swap partitions?
How to inform Linux these partitions are to behave as a single swap file?
See the man pages swapon(8), and mkswap(8), and mount(8)
Quote:
I do not know much about raids to ask questions for now.
You ask about multiple swap partitions. Multiple swap partitions are typically used for high performance situations, md raid is used to give higher than single disk performance, but not required.

Quote:
What do you mean by least used?
If a disk is heavily used it is not a good pick for swap.

Quote:
When you say swap file, does it also mean swap partition?
No. A swap file is a file created on a filesystem. It is usually used when there are no raw (unformatted) partitions available. It will be slower than a raw partition.

You asked a question that requires some knowledge of disk I/O and memory use, usually in the server setup domain.

Cheers,
 
1 members found this post helpful.
Old 04-15-2016, 06:28 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
I would say for most home users a swap file is just as fast as a swap partition.

From Wikipedia
https://en.wikipedia.org/wiki/Paging...x-like_systems
Quote:
From the end-user perspective, swap files in versions 2.6.x and later of the Linux kernel are virtually as fast as swap partitions; the limitation is that swap files should be contiguously allocated on their underlying file systems. To increase performance of swap files, the kernel keeps a map of where they are placed on underlying devices and accesses them directly, thus bypassing the caching and avoiding the filesystem overhead.[15][16] However, Red Hat recommends swap partitions to be used.[17]
 
1 members found this post helpful.
Old 04-15-2016, 08:43 PM   #10
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
Not sure there is much or any difference in speeds of a swap partition and a swap file for most users in modern kernels. I guess if you get a swap file in a place that has heads moving way past data then yes. Same could be said for a swap partition that is the other side of a data partition that gets swapped a lot.
 
Old 04-15-2016, 09:48 PM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by michaelk View Post
I would say for most home users a swap file is just as fast as a swap partition.

From Wikipedia
https://en.wikipedia.org/wiki/Paging...x-like_systems
From the end-user perspective, swap files in versions 2.6.x and later of the Linux kernel are virtually as fast as swap partitions; the limitation is that swap files should be contiguously allocated on their underlying file systems. To increase performance of swap files, the kernel keeps a map of where they are placed on underlying devices and accesses them directly, thus bypassing the caching and avoiding the filesystem overhead.[15][16] However, Red Hat recommends swap partitions to be used.[17]
Contiguous??? I don't think so. The maximum contiguous space possible in an ext2/3/4 filesysem is one block group, and that can be no larger than 128MiB. A swap file does need to be fully allocated (i.e., non-sparse), but there is not requirement that it be contiguous. I presume that a badly fragmented swap file would hurt performance, though.
 
Old 04-16-2016, 04:31 AM   #12
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
On my old laptop (not a high performance best, by any means) I use just the scenario suggested by Chris in Post #6. I have two swap partition because it was set up with one, and that turned out not to be big enough. So, there are two, and basically you just don't notice the difference between two and one.

If the two were widely separated on the (spinning rustware) disk, there would be a performance impact (that's a further performance impact over and above the perf impact from just using swap), due to head movement, so they're not.
 
Old 04-16-2016, 08:00 AM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by lazardo View Post
Swap uses disk blocks without any filesystem. It can use a whole unformatted disk or an unformatted partition.
Well,,, no. Swap uses a partition that has been identified for use with swap AND has a "superblock" that identifies itself as swap. I believe it also includes a "free list" for allocation/hibernation/crash dump support.
Quote:

See the man pages swapon(8), and mkswap(8), and mount(8)
You ask about multiple swap partitions. Multiple swap partitions are typically used for high performance situations, md raid is used to give higher than single disk performance, but not required.
Yes and no. md raid is only used to provide error recovery (useful for non-stop operations). It still slows the paging activity.
 
Old 04-16-2016, 08:20 AM   #14
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by rknichols View Post
Contiguous??? I don't think so. The maximum contiguous space possible in an ext2/3/4 filesysem is one block group, and that can be no larger than 128MiB. A swap file does need to be fully allocated (i.e., non-sparse), but there is not requirement that it be contiguous. I presume that a badly fragmented swap file would hurt performance, though.
Nope, it must be a contiguous extent, which is why a separate partition is so convenient.

As for the original q, if you have the need allocate multiples, else not. Why all the hand-wringing ?.
 
Old 04-16-2016, 08:45 AM   #15
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I don't think the swap file has to be contiguous.

There are NO guarantees in any native Linux filesystem that a file be contiguous, in fact, doing so makes it slower (not to mention that when the size crosses block cluster units it has to skip the cluster allocation sectors, and thus is not contiguous anyway).

It does need to be fully allocated - but that is only due to the filesystem supporting the swap file causing paging activity to allocate blocks in a sparse file (and hence a possible deadlock).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem resuming from suspend to disk with multiple swap partitions guanx Slackware 2 10-02-2013 08:57 AM
Partioning a single partition into multiple partitions. Grtyop Linux - Newbie 4 07-05-2013 03:28 PM
Is it possible to use two swap partitions for multiple uses? texasone Linux - General 9 09-07-2011 06:32 AM
Multiple SWAP partitions: what is priority number?? coolblue Linux - Newbie 1 05-01-2007 02:26 PM
Multiple swap partitions? [GOD]Anck Slackware 10 01-01-2004 11:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration