14

I recently installed Ubuntu 11.04 onto a RAID0(stripe) device using the alternate installation disc and manually partitioned the HDs ext4 and swap partitions; during this process, I was reading in a forum walkthrough (can't remember where...) that having the swap partition at the beginning of your hard drive could be better for some reason!

Is the idea that the swap is "closer" at the beginning so its accessed quicker with a lower latency/delay? The HD 'needle' moves less to reach the swap...

This confuses me because I like to think of Hard Drives as likened to a samurai sword(not literally)!

I was told that the last inch or two at the tip of the sword is the cutting edge because it travels the fastest.

(Think of a ball on a string and as you swing it around the ball at the end of the string is travelling at a greater speed than it would be if it was closer to the source - your hand)

BUT since the HD is spinning at (x)RPM then the outer edge of that HD should be spinning relatively faster (+x) providing quicker read/write rate.

So does the swap position affect performance in anyway? If so, is it better to have it placed in the beginning for immediate access, or at the end for increased read/write?

I would think the swap is sized and placed according to the individuals needs but how do I decide...

EDIT:

As a note, I do have 8GB of RAM (4x2GB) so I noticed that the swap has not been used in any of my GIS (mapping and analysis) processing. 8GB is the full capacity for my motherboard.

4
  • I thought the slowest part of a hard disk was the arm?
    – Allan
    Aug 13, 2011 at 0:28
  • The comparison with a sword doesn't work in this case. Sure, the outer edge of the disk is spinning the fastest, but that "advantage" is exactly negated by the increased distance it has to travel, so that the outer part of the disk makes a revolution in exactly the same time as the inner part of the disk. If you did succeed in gaining anything, it would be so slight that you'd never be able to perceive it.
    – Kelley
    Aug 13, 2011 at 6:22
  • @kelley thanks! this is a good point because sometimes I do run a process that can take days to complete so the accumulation of these micro/nano seconds may add up...
    – SaultDon
    Aug 13, 2011 at 17:14
  • As more and more people are using SDD, I thought it was interesting to see that some are saying that swap files (or partitions) are bad for those drives. digitalocean.com/community/tutorials/… Jun 24, 2016 at 19:45

7 Answers 7

16

Forget swords and balls on string. Think of a stack of CD platters and then you will have in mind an image closer to what a hard drive is actually like.

Wikipedia on hard disks

Think also of the amount of Memory in the computer and ask, how often does the swap partition get used? Your question could be irrelevant. Disks do not have a beginning or an end. They have outer edges and inner edges. Data is placed across more than one platter. Seek times and access times, as well as spin speeds, would turn any answer into a debate.

Note this point from the Wikipedia article under HDD Formatting

Modern HDDs ... appear at their interfaces as a contiguous set of logical blocks; typically 512 bytes long

It only appears that has a beginning and an end. If performance is a concern then more RAM will have a greater effect than the placement of the swap partition.

2
  • this clears up my messy logic of how a HD operates, thanks. I have maxed out ram and currently the HD spin at 7200rpm so that is OK for me.
    – SaultDon
    Aug 13, 2011 at 17:17
  • I marked this one as correct, though the other answers had their benefits, this one was simple and really cleared it up by discussing that data is spread across "platters".
    – SaultDon
    Aug 13, 2011 at 17:22
7

You should use RAM, not SWAP, because swap is terrible slow, compared to RAM. You can use RAM for the sleep mode.

The speed to access the first or the last sector on disk, when the head comes from the sleep position is so small (6–20 ms), that it doesn't affect your experience.

If you have many read/write cycles from swap, so that microscopic intervals could sum up to a mentionable fraction of a second, you would have continuous reading from swap - not repeated movements from a sleep position, so this could only be an argument, if there are more bits read from the outer sectors, than from the inner ones.

But do you know whether the first block is on the outer or on the inner side, and where the head is in sleep position?

And are you sure, that more information is put on the outer sectors? Maybe the bits there are at the proportion wider, as the disks rotates faster, so that you have a constant number of bytes in each sector. At least the diagram of wikipedia (DE) suggests so.

But - modern drives have a controller, which presents himself to the outer world as a virtual hard drive, and manages it's internals on his own, so every model could handle its geometry differently.

If you really depend on performance, you should go for more RAM, more RAM, more RAM. If you can't get more RAM for your machine, you should consider buying a faster hard drive, instead of guessing with it's geometry.

3
  • Good points, and I do not know if the first block is on the inner or outer side, just started using Ubuntu so I am still getting familiar with the whole linux thing.
    – SaultDon
    Aug 13, 2011 at 17:04
  • to answer your second question, I don't know if more information is on the outer sectors, only that it can be 'put' there from certain defrag utilities (but linux doesn't really need to be defragged from what I understand)
    – SaultDon
    Aug 13, 2011 at 17:06
  • 1
    Note that you do not use RAM for hibernation... you may want to do an edit on your answer in that regard. Jun 24, 2016 at 19:05
4

You can measure the speed of different areas of the hard drive with System > Administration > Disk Utility (palimpsest from command line): pick your hard drive from the list and click on Benchmark. For swap use the read-write test results will be more salient, but please note that the test erases data. The resulting graph should give you an idea of the internal performance differences your drive has.

1

It does not matter, the system will spend just about the same amount of time (maybe delays of microseconds or even smaller than that. All in all you would not realise the difference anyways.) read/writing swap if it's at the beginning or the end.

1

I don't think the end matters overly much but just in case I toss it at the beginning on my regular machines, but for my 2U rack which has 4.5 TB. I have 360g of that in 4 striped 7200 Barracudas that serve as the swap file and temp directories.

0

It does not matter at all and the difference is fractions of a second.. so if you going for fractiona of a sec faster load time then more than likely the beginning would be your best bet.. considering the majority of time it's gonna be reading towards the beginning to the middle or so.. unless your hard drive has tons of data on it.. in which case it will be reading from the farthest point from the beginning when that data is accessed... But at the end of the day who cares 🤣

0

I ran a benchmark to test some speeds for myself. On a 500G ASMT Drive I created 16G partitions at the beginning and at the end. I created ext2 filesystems on them (no journaling). Tested copying some files to them, mounted as 1 and 2.

# rm -r 1/{*,.*} 2/{*,.*} 2> /dev/null; time /bin/cp -a /mnt/4/Syncs/osmand/. 1; time /bin/cp -a /mnt/4/Syncs/osmand/. 2
real    0m3.500s
user    0m0.016s
sys     0m1.490s

real    0m21.152s
user    0m0.001s
sys     0m1.535s
# rm -r 1/{*,.*} 2/{*,.*} 2> /dev/null; time /bin/cp -a /mnt/4/Syncs/osmand/. 1; time /bin/cp -a /mnt/4/Syncs/osmand/. 2                                                              
real    0m4.721s
user    0m0.012s
sys     0m1.509s

real    0m19.691s
user    0m0.000s
sys     0m1.518s
# rm -r 1/{*,.*} 2/{*,.*} 2> /dev/null; time /bin/cp -a /mnt/4/Syncs/osmand/. 1; time /bin/cp -a /mnt/4/Syncs/osmand/. 2                                                                                               
real    0m4.784s
user    0m0.006s
sys     0m1.503s

real    0m19.664s
user    0m0.000s
sys     0m1.526s

The beginning partition was about 5 times faster in these tests. With larger tests, I experienced less dramatic differences, but the beginning partition always seemed to be faster. I suspect that at the end of the disk the writes may have been crossing platters more often.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .