Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How does the 'swap' drive actually work????

  1. #1
    Join Date
    Apr 2008
    Beans
    109

    How does the 'swap' drive actually work????

    I was wondering about the Linux swap partition drive.

    So, it uses hard drive space as memory. Does this mean that if I had a 100GB hard drive and used 90GB for swap, that this computer will run decently fast???

  2. #2
    Join Date
    Mar 2005
    Location
    Texas
    Beans
    1,675
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How does the 'swap' drive actually work????

    It only uses it as a last resort, because hard drives are _much_ slower than actual memory. I notice a pretty big slowdown if/when my computer starts using the swap. Most of the time it doesn't need it though.
    100 buckets of bits on the bus,
    100 buckets of bits,
    Take one down, short it to ground,
    FF buckets of bits on the bus.

  3. #3
    Join Date
    Feb 2008
    Beans
    794
    Distro
    Ubuntu

    Re: How does the 'swap' drive actually work????

    your Swap drive only needs to be twice as (or 2.5x) the physical RAM in your box.


    i.e. if your box had 2Gb of RAM then the swap partition should be 4Gb or 5Gb in size. Anything bigger would not improve performance.
    Last edited by solitaire; May 5th, 2008 at 10:58 PM. Reason: updated the sizes should be 2x not 1x
    Laters...
    Sol
    "Have you found the secrets of the universe? Asked Zebade "I'm sure I left them here somewhere" User numbers: Ubuntu 23772 Linux 477911

  4. #4
    Join Date
    Dec 2006
    Beans
    485
    Distro
    Hardy Heron (Ubuntu Development)

    Re: How does the 'swap' drive actually work????

    I've got 2 GB of RAM in my MPB, and I'm not even using a swap, and I never seem to have any problems.

    When the swap partition/file was invented, 2MB of ram was unthinkable. I think it made alot more sense then. But RAM is cheap.

    Really, you DON'T want your computer using the swap file if you can help it. I've always heard it's good to use a swap file/partition as BIG as your ram, not 2.5 times. I can't understand why you'd need that much space dedicated for 2.5 times Ram, Although I could be wrong.

    Russo
    Macbook Pro C2D
    Ubuntu 8.04

  5. #5
    Join Date
    Nov 2006
    Location
    London
    Beans
    77
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: How does the 'swap' drive actually work????


  6. #6
    Join Date
    Apr 2008
    Beans
    297
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: How does the 'swap' drive actually work????

    I got a question related to that as well.

    I never fully understood the need of a SWAP partition. It's needed when there is not enough RAM available. OK, I understand that. But what else is it really doing?
    I checked a server in the office the other day that used (at the end of the day) around 250-300MB RAM, no SWAP was used so far. The next morning RAM usage didn't change but a few MB SWAP was used. The system has 4GB RAM. Why was the SWAP used with still tons of RAM available?

    Another question that I have is what happens when I suspend to disk. Is the SWAP partition used to save the data from the RAM? If so, what if there is not enough space available for RAM + potential SWAP usage?
    If not, where is the data saved to?

    Which then also leads me to the question, how can SWAP increase the performance of systems that has plenty of RAM (2GB+). Assuming that it's not a computer that is used for RAM intensive work like video editing, etc. I would guess that someone doing that has "enough" RAM according to his needs, anyways.
    So, with enough RAM, why wouldn't it be enough to have rather little SWAP, e.g. 300MB?

    The last question that bugs me since a while is, since HDD's are rather slow, would it be possible to use a USB FlashDrive as SWAP partition? Would that increase the performance?

  7. #7
    Join Date
    Nov 2006
    Location
    London
    Beans
    77
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: How does the 'swap' drive actually work????

    Quite simple. When the processor is requesting some data, it looks for it first in its lvl1 cache (very small, very fast access, usually contains only simple instruction), if not here it will look for it in the lvl 2 cache, if not, RAM, if not, swap, if not HDD... as you can see each operation is accessing a lower media at each stage.. that also why the swap should not be too big or then the system will spend too much time looking for the info.
    Now to answer your question, the flash drive might be much slower than the HDD, hence using it for swap will decrease performance.

  8. #8
    Join Date
    Sep 2007
    Beans
    9

    Re: How does the 'swap' drive actually work????

    If you're using a laptop keep this in mind:

    1) To hibernate your system you MUST have a swap partition slightly bigger than your ram. I have 4 gigs of ram, so I must have a partition between 5-8 gigs in size.

    2) Swapfiles cannot be used for hibernate, so if you have a laptop don't use a swapfile.

    3) If you know you aren't going to be hibernating then you can use a swapfile and it will be just as fast as a swap partition.

    Hibernating is when you suspend your system to DISK and the computer power offs.

    OS X system sleep default is a combo. It suspends to ram, AND hibernates it to disk 'just in case'. I got sick of waiting for it to write 4 gb to disk every time I slept the machine, so I changed it to just suspend to ram.

    Swap is also a place used to store ram that is 'occupied' but isn't being used or called for whatever reason.. so why not shuffle it off to the back of the bus to free up the good seats for the paying customers? You get the idea. Think of it as a caching.

  9. #9
    Join Date
    Dec 2006
    Beans
    485
    Distro
    Hardy Heron (Ubuntu Development)

    Re: How does the 'swap' drive actually work????

    I have no swap partiton or file and my laptop hibernates just fine...


    Russo
    Macbook Pro C2D
    Ubuntu 8.04

  10. #10
    Join Date
    Apr 2006
    Location
    Michigan
    Beans
    55
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: How does the 'swap' drive actually work????

    Quote Originally Posted by Sunspark View Post
    2) Swapfiles cannot be used for hibernate, so if you have a laptop don't use a swapfile.
    This is not true!
    You can still hibernate if you have a swapfile. There is just an extra step you have to take in order to get it to work.

    You have to find out where the swapfile resides on the system by looking up it’s FIRST SECTOR:
    sudo filefrag -v /swapfile

    Then add "resume=/dev/sdx resume_offset=xxxxxx" to the kernel boot options in /boot/grub/menu.lst, where /dev/sdx is the partition with the swapfile on it and xxxxxx is the first sector the swapfile starts at.
    Ex: kernel /vmlinuz-2.6.24-17-generic root=UUID=021e7fc9-ee7e-49ac-b9f1-2a084d229512 ro quiet splash resume=/dev/sda3 resume_offset=350624

    And then so grub automatically adds the offset to future kernels add it to the end of this line:
    # defoptions=quiet splash resume=/dev/sdax resume_offset=xxxxxx

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •