Jump to content

My Swap Tip


SoulSe
 Share

Recommended Posts

Ok, if this is tripe, than the admins can tell me so. But I've been thinking about this for a while and it makes perfect sense.

 

n00bies are often stumped/intimidated by Swap partitions in Linux. It seems foreign and weird and one never knows how big to make it or where to put it. I have a special (or maybe not) way of dealing with swap space and it goes like this:

 

~ I am assuming that you know what swap space is and what it is used for ~

 

Firstly, most people will tell you that swap space should be twice the RAM you have (i.e. 128MB RAM = 256MB Swap). While this is a satisfatory rule of thumb, you will never need more than 512MB (according to my limited experience).

 

Now, I'm assuming you know how a hard-drive works. It has a head moving over the surface, reading off the data stored. Lets pretend you have a /home partition at the end of your drive and the Swap space at the beginning. This is all good and well, but to move between the two would take a longish time (well, in nanoseconds anyway, but lets tweak what we can, why not).

 

:idea: So why not split our swap space between two -or more- partitions? :idea:

So, in the original setup, our partitions go something like:

[/swap][/][/usr][/var][/home]

That is a pretty standard example. What I would then recommend is:

[/swap][/][/usr][/var][/swap2][/home]

Obviously now, the head can move to the nearest available swap space, saving time and, well, just being more geeky. I have two hds in my machine and the swap partitions are spread out uniformally throughout.

 

On modern hds, you probably would not notice the difference, but that never stopped anyone from installing Gentoo :roll: so...

 

So, that's my contribution to the swap space debate.... It could be complete horse-shit though, so lets wait and see what the others say :wink:

Link to comment
Share on other sites

How do you have the swaps in fstab? You should be using a pri= option

man swapon

-p priority

             Specify priority for swapon.  This option is only available if swapon was compiled under and  is  used

             under  a  1.3.2  or  later  kernel.  priority is a value between 0 and 32767. See swapon(2) for a full

             description of swap priorities. Add pri=value to the option field of /etc/fstab for  use  with  swapon

             -a.

I tried 2 swaps

http://www.mandrakeusers.org/viewtopic.php?t=3994

and found that the second wouldn't be used until the first was full. I had 1GB/2 swaps of 500 :shock:

 

I guess you could try to give them the same pri= and see if that does what you want....I d/k?

 

That's my 2 cents :)

Link to comment
Share on other sites

To be honest, I just set it up in installation and let Mandy do the rest. I'm no fstab expert, when I get back to my machine, I will post my fstab.

 

I don't even know if the second swap is being used, I never checked... guess I should :oops:

 

Just thought I'd drop an idea and see where it goes. I'm still a semi-n00b messing around.

Link to comment
Share on other sites

The moving of the heads is not what takes a lot of time, the beginning of the drive is where the data is read the fastest, so basically:

 

if you have <192MB of RAM and you like to have plenty of programs open on a 'heavy' DE (kde, gnome), your swap will be used a lot.

If you have >=256MB of RAM, or don't run memory hungry apps as much, you swap may never be used. (I had 512MB for a year before upgrading to 1GB, and it really didn't get used often; I only upgraded since I needed to know for sure if my mobo and the memory would hold with two 512MB sticks and the warranty was running out...)

 

If your swap is used a lot, this slows down the system; by putting the swap file/partition at the start of the drive (which is closest to the center of the drive), it is technically on the fastest part of the HD so gives the best performance. Since the difference in speed (especially latency but also bandwidth) between the HD and main memory is a factor of 1000 or so, it is always better to avoid using the swap space.

 

The command 'free' is your friend, it tells you if your disk swap is being used, and if so, the best way to improve is to

- get more RAM, or

- change your habits in your computer use, use less programs at the same time etc.

 

Optimising with several swap partitions as you propose may or may not improve the speed of your system by 0.1%.

Avoiding to use disk swap improves by a factor (maybe up to 1000x faster, since normally you'd have to wait for the disk swap to be read, now you don't)

 

Please also realise how swap works: it will not be read and written like small (KB) chunks, when it is used it is really several MBs at once. So again, the moving of the disk heads is really not the big delay. The latency (8.5ms) and bandwidth (20-50MB/s) are. Latency of RAM is measured in us or even ns and bandwidth is up to 3.2GB/s or more...

Link to comment
Share on other sites

artee, i've got my hdd like this

 

| /home 2gb | /home/james/music 1gb | / 2gb | Swap 206mb | /mnt/windows/ 1gb |

 

note: /mnt/windows/ is empty and does not, never has and never will contain Windex. I was in disk drake and couldn'tbe stuffed writing the mount point so I just gave it that. IT's empty and I have no idea what to do with it......

 

my swap is near the end of the drive, so it must be slow. Oh well, i don't often use, it. 160mb ram seems to suffice for now.

 

James

Link to comment
Share on other sites

by putting the swap file/partition at the start of the drive (which is closest to the center of the drive)
:? how is it at the start AND the center? I've had a swap everywhere.....no diff. This of course on my old celeron 600 192MBsdram which always used a swap....no diff, well I'm sure there was a diff but not enough to tell, I didn't benchmark. Why would I if I didn't notice a diff? I'm sure on a small P2 with only 128MB it may help an itsy-bitsy bit. I've had Win98, tweaked gaming win98's, ML, RH, Slack, and Debian all on both front and end of a 30GB Maxtor 7200RPM....it makes no diff at all where.....no noticable diff on any of them :wink:
Link to comment
Share on other sites

bvc, I was speaking from a technical standpoint. But when the operation takes 45ms and with non-optimised swap placement it takes 48ms, and you have one such operation every second (whooo, bad swap use, add ram!!) you still wouldn't notice, not even when timing with a stopwatch...

 

So from the standpoint of the user:

if (swapisused)

ram++ ;

 

or should that be a while loop,... ;)

 

Oh and being at the start AND the center, .... drives start reading in the innermost circle, then go outward, just as cd's and contrary to the way vinyl is used: from the outside in.. (which btw on a totally but not quite unrelated tangent is one of the real reasons that vinyl is really not good for audio, the crescendos are often at the end, where with constant rpms the 'resolution' of the vinyl is very bad due to the low relative speed of the needle onto the material; this leads to very bad dynamic range, and guess what, at the crescendos the dynamic range is really really needed the most...)

 

I'm sure if you were to benchmark a drive and have a crappy OS or forced use of small chunks of diskdata, you could tell the difference. Because it's there, it's real. But you'd never know unless you really benchmarked and guess what, that would make you lose more time than the not optimised partitioning table.... :D

And of course, if your system doesn't swap there won't be a difference where your swap partition is. In that case, put the system (root) partition first. There where windows is on other peoples machines (please realise, there is a reason for that!! they know how disks work too! It's not for nothing that they forced that position for older versions of windows!!!).

Link to comment
Share on other sites

I have 768MB of ram and use a 2048MB swap partion, why you ask? Don't know, I just do it. Currently with Gentoo my swap rarely get's touched, wasted space, 80GB, I don't care.

 

THe other end of a 2x ram, who know's? I just installed Solaris on 4 V880 with a swap space of 16GB, depends on what you are going to do I guess??

Link to comment
Share on other sites

I already wrote all I know about it here, but I will sum up my advice:

 

Monitor your memory usage with the command

free

 

and if it tells you you are using swap, add more RAM memory.

 

If you are still using swap after adding the max amount of RAM your system can take, change your habits; even with plenty of large photographs open in the GIMP your should not be using any swap if you have 256 or more.

So: just don't open too many programs/images etc at the same time.

This last thing is also true if you have no money to upgrade/buy more RAM.

 

The contrary is only partially true: if your system is not using any swap but you don't have a lot of ram, adding ram can certainly help, for instance in cases where you restart a program; linux has a very good way of caching, much better than, say, windows (xp or any other).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...