15

Where do I put my swap? Debian installation gives 2 choices: (1) at the end or (2) at the beginning of the disk space. What is optimal?

What is the optimal amount of swap given my computer has 512Mb RAM? Should I have more than one swap?

Should I define swap space as a logical or primary partition?

I'm installing Debian 6 testing 32bit on a 40Gb disk.

ptrcao
  • 5,635
  • 3
    Note that the optimal swap size depends on the use of your machine. You won't define the same size for a desktop, a server or an embedded system. – rahmu Sep 08 '11 at 08:32
  • Mine is a desktop if that helps. – ptrcao Sep 08 '11 at 08:41

4 Answers4

5

A hard disk is usually faster at the start than at the end. But I'm not sure if it makes a significant difference.

Optimal amount of swap depends on how many programs you run and how excessively swap is used. 1G won't hurt, though. More than one swap is not necessary.

You can put your swap

  • in a primary partition,
  • in a logical partition,
  • on a LVM volume (that's what I do)
  • and even in a file - that is said to make no noticeable difference nowadays.

You even can do a combined way: use a 512M..1G swap partition permanenty and add a swap file if you need.

glglgl
  • 1,210
  • 3
    Do not forget that you need around 1Mb of real memory permanently allocated by kernel for each 1Gb of virtual memory available. – andcoz Sep 08 '11 at 09:00
  • 1
    @glglgl: Why is it faster at the start? – ptrcao Sep 08 '11 at 11:02
  • 4
    The revolution rate is constant, but there are more data at the border of the HDD (start) than in the center (end) as the area is bigger there. See also http://partition.radified.com/partitioning_2.htm. – glglgl Sep 08 '11 at 11:07
4

Most disks use zoned recording, where a more or less constant physical density of data is maintained over the disk. This means that tracks closer to the edge of the disk will have more sectors. Data reads from these regions will be a bit faster than data reads from tracks close to the hub.

On modern disks, the tracks closest to the edge start at 0, with higher numbers being closer to the centre of the disk. Therefore partitions on lower numbered tracks towards will perform slightly faster. As an aside, the actual heads x sectors x tracks layout on the drive is virtualised - the values you see are translated to the physical geometry behind the scenes by the drive's firmware and have nothing to do with the actual layout of the drive.

A rule of thumb for swap space is to have about twice as much as your physical RAM. A 1GB swap partition sounds reasonable.

For swap, making it a primary or logical partition is irrelevant, although there are a couple of caveats that may bite you on really old machines.

On older systems, some BIOSs couldn't boot from a partition that started outside track 1024. The /boot area could be either left under / or mounted as a separate /boot partition. In either case the entire partition where /boot resides would need to be within track 1024 and may have needed to be a primary partition. This issue normally does not affect swap partitions.

Note that most PCs built from the mid-late 1990s onwards will not have this issue, so it probably does not affect you.

1

Where do I put my swap?

I don't expect that it matters much (performance). Just go with the default.

What is the optimal amount of swap given my computer has 512Mb RAM?

I've seen some place mentioned that you should have roughly twice the amount of swap as the amount of RAM.

Should I have more than one swap?

Why would you do that? I don't even know if Linux can use more than one swap area (haven't checked).

Should I define swap space as a logical or primary partition?

Rather leave it as logical, just so you don't run out of partitions if you create more.

tshepang
  • 65,642
  • I've done some reading and there's a lot of talk about the travel time of the head. You mean none of these considerations make a difference? – ptrcao Sep 08 '11 at 08:07
  • Not enough to bother caring about. – tshepang Sep 08 '11 at 08:25
  • 2
    From man mkswap: Presently, Linux allows 32 swap areas (this was 8 before Linux 2.4.10). – andcoz Sep 08 '11 at 08:49
  • Linux can use multiple swap partitions, configured with different priorities (use up one first before starting to fill-up another), you can also configure Linux to emulate RAID-0 across two identical swap partitions by setting the priority for each the same. – Coder Guy Oct 14 '21 at 18:45
0

The best place to put your swap may depend on the other partitions you have on your disk. If you're putting your swap partition on the same physical disk as your operating system root, you should try to place it
close to the beginning of your OS and/or home partitions.

I found this question while investigating a speed issue with my current system.

Due to the order in which I've installed the operating systems on my machine, my swap partition is right at the beginning of the disk, and my old OS partition is right next to it, but the root of my newest OS filesystem is right at the end of the disk.
When memory gets tight and things start getting swapped out, the system slows to a crawl in a way that it doesn't with the old OS.
The two operating systems aren't identical, so it's not comparing apples with apples, but my working theory is that things slow down because the the disk heads are switching back and forth across the whole width of the disk. You can can even hear the difference - the disk sounds much louder and clunkier when using swap space with the new OS.
The time taken for the heads to move back and forth could easily outweigh any advantages from a faster moving disk at the outside edge.

This is a very old question, and this answer is only relevant to mechanical, magnetic HDDs. It may not apply to SSDs as they don't have moving disk heads.

M_M
  • 101