Is having the 'swap' partition at the 'beginning' better than at the 'end'?

37,594

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

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.

Share:
37,594

Related videos on Youtube

SaultDon
Author by

SaultDon

I've had a career in GIS since 2006, but it's also a hobby where this site helps answer lots of those off-the-beaten-path questions I always come up with.

Updated on September 18, 2022

Comments

  • SaultDon
    SaultDon almost 2 years

    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.

    • Allan
      Allan almost 13 years
      I thought the slowest part of a hard disk was the arm?
    • guptarahul275
      guptarahul275 almost 13 years
      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.
    • SaultDon
      SaultDon almost 13 years
      @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...
    • Alexis Wilke
      Alexis Wilke about 8 years
      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/…
  • SaultDon
    SaultDon almost 13 years
    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
    SaultDon almost 13 years
    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
    SaultDon almost 13 years
    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".
  • Alexis Wilke
    Alexis Wilke about 8 years
    Note that you do not use RAM for hibernation... you may want to do an edit on your answer in that regard.