Author Topic: Swap - Size according to usage.  (Read 6705 times)

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11688
  • ----IOFLU----
Re: Swap - Size according to usage.
« Reply #15 on: September 28, 2010, 11:43:08 AM »
Swap can use multiple swap partitions, on multiple hard drives, and one can have their priorities set equal, to use them in a striped fashion, similar to raid 0, to speed up the writing to and and recovery of data from them.

[root@littleboy ~]# swapon -s
Code: [Select]
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       1702880 75400   3
/dev/sdc2                               partition       8096752 75396   3
/dev/sdd2                               partition       6008300 75508   3


Any idea if this arrangement is good for Suspend to Disk?
As I understand it, S2D requires that the Swap space must be one contiguous space to work properly.
I had always interpreted this to mean a single Swap partition/file had to be of sufficient size for the operation.

This has caused me to wonder if it is possible to use multiple smaller Swap partitions/files to make available sufficient space for the suspend operation.

Any info available appreciated   ;)

regards.

Last I heard the swap designated resume, for use with suspend/hibernation needed to be one contiguous space of sufficient size to hold the data involved. In my case /dev/sdc2 is the one specified as being resume, and is ~8 GB.

So although behaving in a striped fashion they will not be 'seen' in that manner, and so that arrangement is no good to get around the requirement .......  if I understand your post correctly.

Oh well!

Basically yes. At least one of the swap partitions needs to be large enough, on it's own to handle the suspend/hibernate function.

I have four drives that are each capable of being independent of all the others. On each there is at least one installed Linux OS, and each has it's own swap partition, twice the size of the RAM present on the machine on which it was originally installed. When the drives are all assembled in a single case, or attached by USB or eSATA connection, all swap partitions are available for use on whichever OS is booted. One of the swaps is turned off by being commented in /etc/fstab, and the remaining three are set to be used in a striped manner. Resume could be set to use any single swap partition present, so with 2 GB ram on this machine I could choose either /dev/sdc2 or /dev/sdd2 for the resume partition and have more than double the capacity of the installed RAM. On a machine with 4 GB physical RAM, /dev/sdc2 would be the only sure choice.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Swap - Size according to usage.
« Reply #16 on: September 28, 2010, 12:04:33 PM »
Yes ......  am using several Swap partitions myself in one PC .......  just thought the way you described the 'striping' of the partitions that this may overcome the need for a contiguous Swap for S2D.

Thanks.

Offline shrinivas

  • Full Member
  • ***
  • Posts: 154
Re: Swap - Size according to usage.
« Reply #17 on: September 28, 2010, 07:21:46 PM »
I just wondered.
Why doesn't Linux create swap in / or home like windows does pagefile.sys ?
Why do we need to create a separate partition for the same ?
I am sure there is an excellent reason for this, but I feel it would simplify installation of Linux.
AMD ATHLON 64X2 5200, 2 GB RAM, nVidia 7600GT 256 RAM, HD0 320GB,HD1 80GB Triple-boot PCLinuxOs Zen Mini/WinXp/E17

Offline T6

  • Super Villain
  • ******
  • Posts: 19051
  • xmas is comming!
Re: Swap - Size according to usage.
« Reply #18 on: September 28, 2010, 07:35:44 PM »
the reason comes from the old days when you could create the swap partition on a second hard disk that could improve drastically performance by unloading the constant read/write process of the swap partition from the main hard disk with the / partition that sometimes has less usage than the swap partition

that was very useful in a time when ram prices were too high/impossible to increase and a swap partition could be as small as 128 mbs in older 1 gb hard disks that you could have around doing nothing

this same trick can be applied to windows to gain the same performance increase

http://www.techtalkz.com/windows-xp/157103-pagefile-sys-placement.html

another reason is to share this partition between multiple linux distros, this was a common practice some years ago, to save space

the swap is also a partition to avoid the situation where you don't have enough free space on hard disk and can't create the swap as a file

this days depending on your system usage you can run the system without this partition at all, this is because the ram usage in linux and the amount/price of ram this days, something that you can't do in windows

remember that swap/pagefile.sys are both extensions of ram but available on a slower device, the hard disk that you don't wish to use to avoid the noise of the hard disk moving and the slowness of the system accessing it(a hard disk is drastically slower compared to the ram of your pc) but if you need it is better to have it available isn't?

more about swap partitions

http://www.linux.com/news/software/applications/8208-all-about-linux-swap-space
"If you wish to make an apple pie from scratch, you must first invent the universe."

Carl Sagan

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11688
  • ----IOFLU----
Re: Swap - Size according to usage.
« Reply #19 on: September 28, 2010, 07:54:04 PM »
I just wondered.
Why doesn't Linux create swap in / or home like windows does pagefile.sys ?
Why do we need to create a separate partition for the same ?
I am sure there is an excellent reason for this, but I feel it would simplify installation of Linux.

If you need extra swap, you can create a swap file withing the / partition. To put all your swap there, it would just take usable space away from the system's usable space, so what would you gain? As a separate partition it is automatically picked up by your installation, and can also be shared with any other Linux installations on the same machine. As a file in the / partition, each OS would need it's own swap file, thereby using up far more of your hard drive overall, and I don't believe you can hibernate to a file; I've not seen a resume parameter other than to a partition.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6471
  • I'm going South
Re: Swap - Size according to usage.
« Reply #20 on: November 16, 2010, 05:26:59 PM »
Personally I would say that striped swap is obsolete. Setting up compcache with a higher priority than the disk swap to me is a superior solution latency and disk throughput wise. Why? Compcache is compressed in-memory swap at a compression of 4-1 to 5-1 ratio. It has no mechanical head latency and swapping to it does not affect I/O throughput, so no linux drive thrashing hell. Also with a higher priority you won't hit disk until compcache is filled with ~compressed~ swap data. Roughly +1GB worth of swap data to fill up the compcache, which would crush a normal disk swap setup.

It acts like a compressed swap buffer. I would not ever suggest striping to the compcache though. Run the system with vm.swappiness=100 and any stale data is dumped in the compcache with thrashing the disk. Win-win scenario and you free up some memory for programs that makes up for allocating to compcache.

Even my phone is much quicker with compcache even when compared to swapping to flash memory on it.

The only scenario I can see which you wouldn't want compcache setup is if you are so low on memory that you can't spare the memory to allocate to compcache. 512M is excessive for me, but I don't ever want to hit the disk(disk thrashing hell).

Here is a compcache to disk swap comparison: http://code.google.com/p/compcache/wiki/Performance/SwapDiskVsRamz

[lexus@localhost ~]$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       4088500 0       -1
/dev/ramzswap0                          partition       516296  0       0



Striped swap may be obsolete. But is compcache really useful if you have enough RAM? I've had 8 GB of RAM on my main box for the last nineteen months and for the last nineteen months I have not seen or heard any swapping on it.

Now, the point of O-P's first post was that if I'd use suspend or hibernation I'd need 16 GB of swap space anyway. This makes sense. But I don't see how compcache would help there.

Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D