Should I put the swap partition at the beginning or the end of the drive?
I did a search, but I didn't find the answer. Where do I get better performance? Putting my swap at the beginning of the drive or the end of it? I've installed Linux soooo many times and never bothered to ask. I just put an 80GB hard drive into my Sony PCG-F180 and even though the hard drive is 5400 RPM, I need more speed (it's a PII333, 192mb RAM....every little but helps)
P.S. I'm installing slack 10.2 |
I have always read to put it on the beginning of the drive, the first partition that you can. I always set up my /boot partition first then my swap space right after. If you think about it the inside of the drive can be read faster than the outside part. That is what I have read anyway. I know there is a difference on the old audio records too.
I have never tested this myself though, this is just what I have always read. I don't know if you can test it either. :scratch: That help any? :D :D :D :D |
I just did some experimenting with dd. It seems that I get better read response from the end of my Western Digital. This isn't what I would expect. There may be other factors involved here. It would probably be much more objective if I didn't have linux running on the drive.
Bear in mind also, that all new hard drives lie about their geometry. Any given sector that you specify can physically be anywhere on the drive. Some will silently replace tracks with bad sectors for spare ones. |
Quote:
I have 1GB of ram so I rarely use swap. I have no clue how fast it would be or how to test it. It is the second partition on mine though. I used the swapiness thing to make it not use to much swap too. I can't remember where I put that. It's in /etc somewhere. Well, I just came back fom town. They are saying gas may go up again so I went and filled up my tanks, again. It is $2.54 a gallon here. It was $3.55 a few weeks ago. Greedy oil companies. :mad: Later :D :D :D :D |
Re: Should I put the swap partition at the beginning or the end of the drive?
Quote:
The most important thing you have to bear in mind is that the harddisks have to move the heads and this costs time. The plates (there more than one to conform what we know as a 'hard disk') spin faster on the border as in the middle. But having only one disk the key bottleneck is not this speed difference but the time lost in moving the heads form one part of the disk to the other. What we need to search is a way to minimize head movement placing the swap partition in a proper place. If we have two or more disks the obvious place are the first sectors of the disk taking also advantage of paralelization, so one head on one disk can always be there writing into the swap while the other on the other disk is reading or writing somewhere else. But this advantages disappear if we only have one disk. then the approach is radically different: With a single disk we need to minimize the travel time of the heads as much as we can. And we can achieve this using the middle of the HD as a swap partiion. This way there will always be a header near and the time spent for a head coming from either the border or the center is only half as much as if you place it at the beginning or the end. Placing a swap aprtition at the end of a disk is always a bad idea as you won't get the advantage of the reduced travel time of the heads and you will also get an extra penalty in speed and block density. So the thumbrule is:
This can improve the speed of disk transaction on systems which makes a heavy use of swapping; old systems with less than 64MB of (slow)RAM... In more or less modern systems swap space is almost a relic from the past which we use more as a tradition. So on one of my machines (Duron 1.3 GHz, 758RAM DDR 333, 2xSeagate ATA100 40GB HD's) I never have used more than a 1%-4% of my 0.5GB of swap space. As you see there not much use in faster disk access when we aren't indeed using this space at all. So if you have plenty of RAM (this means more than 128MB) using an alternative solution could be the right solution. This alternative is to use the dynamic swapping daemon instead of a fixed swap partion, the swapd. This daemon takes care of using the part of the disk which fits best to it's needs to place temprorary swap files, so you don't have to bother about where to place them. Drawback is that you have to recompile the kernel. So, swap partitions make only sense in old low-ram systems and in laptops where the swap partition is used as susend-to-disk storage. More info:
|
Re: Re: Should I put the swap partition at the beginning or the end of the drive?
Quote:
Thanx |
If you feel the need for speed, don't forget that you can also get more
from your drives if you'll enable DMA using hdparm. Otherwise, short of buying more ram, with that lappy there's not much difference you're going to get no matter where the swap is located. |
Quote:
Code:
vm.swappiness = 20 Quote:
As to swap speed, get it on a second drive if you can. Try to put it on a different bus to, so a harddrive on a different IDE cable if possible. |
Swap partition placement
A really good discussion.
I help a lot of people set up dual booting, & if possible I like following in a 1 drive situation:
Dual boot w/ 2 drives -- put it on the <choke>Winders</choke> drive. I was given an ancient (full height) 3G SCSI & I have always wondered if it would be of any use for swap. I suspect it's so old that it isn't very fast by modern standards. |
Zoned Bit Recording explain partly the why of outer use of HD for swap
excellent thread!
more sectors on the outer tracks of the hard drive platter than on the inner tracks see picture and details about Zoned Bit Recording http://www.pcguide.com/ref/hdd/geom/tracksZBR-c.html |
So basically the answer to my question is.... Put the swap at the beginning of the drive. ?
|
no the answer depends on
- how many drives - what you (the applications) do with the HD I have no data, just wanted to bring the info to light. swappiness is still very important AFAIK this is still relevant Quote:
Anyway I am no specialist of the question |
Nope - the real answer is that with modern hardware and kernels it's pointless worrying about it.
If you are swapping that hard, dedicate disks (and paths) solely to swap devices. If that can't handle it (say you're doing cyclone simulations for NASA), get PCI memory cards and use them. |
As I said in the top post, it is a single drive Laptop with a 5400RPM 80GB Hard drive. So putting it on a second drive is not an option, and with only 192MB ram, I don't think going without a swap is an option either.
|
Stick it wherever you have room - minimum half a gig. Full gig is better.
The kswapd code allocates by segments, and tries to use a segment that "best fits" what you are trying to swap-out. Swap-outs are also delayed (like normal I/O) in an attempt to aggregate the physical I/O. Swap-ins are more "on demand", but are optimised where possible. With the other I/O that will also be hitting that disk, just let the VFS layer handle it. It'll be a lot better than any of us will ever be at trying to second guess it. |
Quote:
How much memory should you have before you don't need a swap partition? Obviously @192MB I need one, but with 512? I heard the general rule, your swap should be double your RAM up to 1gig (swap size). |
I have 1Gb of ram and 1Gb of swap. Mine rarely uses more than a couple Mbs of swap though. A lot of it depends on amount of ram, what you are running and what you set swappiness too. For a laptop you should have that set low since the drive is slower.
:D :D :D: D |
Quote:
I allocate (at least) a Gig on every system - and add more as needed. Yes, I know Linux will run without swapspace. In 2.6, you can use either swap partition or file, without (performance) impact. |
Quote:
I disagree with your absolute statement! You don't need swap space, not a requirement. The system will function but at a sacrifice of time if the memory is fully utilized. A swap file could be used instead of a swap partition. This can get into a really big bag of worms. The debate is very active about the subject. Some advantages of a swap file are that the size can be adjusted. The file system will be the bottle neck for the file. Where the swap partition will be limited to the pre-defined allocation. The speed advantage would be the swap daemon for the swap partition. The paging will be better handled here. You could read Swapping Out and Discarding Pages for a good explanation. |
Quote:
There is no difference in speed between using swap file or swap partition. As for changing the size, I just add more extents as needed - they can also be swapoff'd later. |
Quote:
When you are speaking about swapfile vs swap partition then there is differnce. And there is a time difference via the kernel swap daemon and a swapfile. You are dependent on the way the information is paged out. I really don't want to get into a debate that has been going on for all to long a time. Just look at the data. When a file is used to move the page another layer is used. When a swap partition is used then the kernel swap daemon controls paging to the swap partition. So I don't have to write the explanation, look at the LDP for virtual memory. The 'man mkswap' doesn't reference timing. You can have multiple swap files or multiple swap partitions. And yes you can switch them on or off. Hope this helps! |
All 2.4 related - of no relevance to the modern world. Don't offer that as undeniable truth when you don't know.
I didn't mention the manpage - I said read the mkswap source. And while you're there have a look at kswapd. You have a lot to learn. |
Quote:
What has the source of mkswap got to do with the operation of the swap file or swap partition? You use the mkswap command to 'make swap area'. Sure if the swap file is not contiguous then problems can appear even for the 2.6 kernel. That is one of the strengths of using a known good disk area as a partition for swap instead of a swap file. The reference to the 'kswapd' source is valid. If you are speaking about the memory allocation of the main page allocator then we can still debate about the 2.4 or 2.6 kernel differences. Let us decide which kernel we will continue the discussion with. Your assumption and mine were different. The OP never stated he was using the 2.6 kernel. I assumed he was using the 2.4 with the 10.2 install. As for personal attacks. I'll leave that to people like you! You don't know what my experience is and I haven't made an attack on your abilities so don't defend yourself in that manner. Maybe someone else has a lot too learn? |
Please tone the rhetoric down -- stick to facts & avoid the personalities & rudeness.
I would hate to ask the mods to close the thread. |
Hi,
Report if you wish! There was nothing wrong with my or syg00 comments. Sure personalities are involved. But when are they not? I am an adult that can communicate and I do not need someone else for defense. Viewpoints and intelligent discussion are good about the subject as long as everyone agrees on the subject to discuss. I was speaking about the 2.4 kernel since the OP installed 10.2 and I assumed a basic install. We should have requested which kernel from the OP. As to your statement; Quote:
Quote:
My reason for response to you is that LQ is a good place for discussion. We don't need a rigid format but we do need good open discussion to help each other when problems arise. |
I have a 2.4 Kernel.
Yes, you are correct in assuming I am using 2.4 for a Kernel. So only 2.4 information is relevant for me. Sadly I have an abundance of "legacy" equipment so I've not moved to 2.6 as of yet. I appreciated your discussion about the swap differences between 2.4 and 2.6 though. I was not aware 2.6 had those capabilities. However, I would not feel comfortable using a swap file as opposed to a swap partition. As onebuck said:
Quote:
I don't want to turn this thread into a discussion of 2.4 vs. 2.6. So please, even though you both have excellent points, stick to the topic. I don't think outside intervention is necessary, no rules were broken. Like I said I have 2.4.:) |
Hi,
Even for a swap partition you should do a bad block check when you create the partition. You should even test the 'swap file' for contiguous space for 2.4 or 2.6 kernels. There is nothing wrong with using a swap file vs a swap partition. There are times it will be easier to create a swap file. Especially if the swap file is to be used temporarily. The 2.6 kernel will handle the swap much better that the 2.4 kernel. Since the page allocator has been re-written for the 2.6. Placing more than one swap on different drives will help in some cases. Here you will be dependent on the speed of the hardware I/O. I too agree that we need to stay on subject. That was how the discussion developed between syg00 and myself. I was speaking on the 2.4 kernel and syg00 was referencing the 2.6. Apples and bananas! Resulting in each having bruises. |
There is little functional difference between the swap space in a file or a partition. Accessing swap space in a swap file is necessarily a little slower since the file system access time must be added in.
Swap space is not absolutely necessary, but having the smallest possible amount could someday save you from a system hangup. For a long time I ran without any swap at all and the only way I had a system hangup was by compiling the full mozilla with all tests and debug features turned on, which takes about 1.5GB of hard disk space when finished. This was on a MAC(512MB RAM) which may have had something to do with it. Don't get me wrong, I'm not recommending that you run without swap. But do take note that the minimum size of swap is just 4K -that should tell us something. Even if you are running KDE, I doubt that you'd see any improvement in system response times comparing betweeen running with 512MB or 1G of RAM. On my systems which use only lightweight GUI components there is no improvement above 128MB of RAM. The point is that 128-256MB of RAM is usually plenty to run your system and GUI. The rest of the RAM will get used for page-caching when you start to work. If you have as much as 512MB of RAM, your swap will hardly ever be touched. All that said, if you are editing videos, compressed sound files or ISO images, you may easily need 3-5GB of total RAM and swap. Even though there is a slight time penalty with using swap files they make more sense for systems which don't really need any or much swap. It saves creating a separate partition -you can always change the size of your swap file. Trying to optimize swap access times based on physical disk location is extremely difficult. Most of the points have been covered except this: the real hold back on disk access times is not the spin-rate but the time it takes to move the head across the disk. This doesn't necessarily mean that the start of the disk is faster -some manufacturers beat us to the punch and park the head in the middle of the disk radius since they don't know which direction will be needed next. So, if you can really figure out how your disks park their heads and find out for sure that your swap partition begins close to the physical middle of a component disk, well I congratulate you. |
First of all sorry for necroposting. I've got a question after reading this topic.
Quote:
But how could I know numbers of sectors which are placed in the middle of plates? |
Careful reasearch and whitepapers?
|
1 Attachment(s)
Ok, I've read some more whitepapers about modern HDDs' geometry and that what I've got from there. CHS addresses don't reflect the real disk geometry now. So I've thought up a tricky workaround.
I suppose that a number of sectors on each side of each plate in HDD is approximately the same. I need a number of a sector that's located approximately in the middle of a side of plate. In other words a distance from this sector to a hub is equal to one half of a distance from the hub to a border of the plate. One sector occupies some area of the plate. All sectors on one side of plate occupy all this side. A circle with a radius equal to one half of a radius of the plate would occupy a quarter of the side of plate. So one quarter of all sectors on the side of plate would be in this circle. Needed sector is somewhere near of a border of this circle. First sector on the side of plate is at it's border. So number of the needed sector is about 3/4*N (N is a number of sectors on the side of plate). r2 on attached picture is the radius of the plate. r1 is the radius of the circle. r2 == 2*r1. S1 - area of the circle S1 == pi*r1^2 S2 - area of the side of plate S2 == pi*r2^2 == pi*(2*r1)^2 == 4*pi*r1^2 == 4*S1 S1 == 1/4*S2 Is this acceptable way to search the middle of plate? |
To be honest, I don't think it would matter much anymore. Drives are so much faster nowadays plus memory is a lot cheaper. If you really need to worry about speed that much, more ram would be a better solution. I just built a new rig and I got 16Gbs in mine. It was only about $200.00 if I recall correctly. I just caught it on sale.
Also, swap is slow pretty much anywhere. That should be the last thing you want used. :D :D |
Himilhil,
Please post links to the whitepapers you have found, it's hard for the rest of us to discuss this w/o the same background info. you have available. My memory of my research into this subject says that your: "I suppose that a number of sectors on each side of each plate in HDD is approximately the same." is an acceptable simplification. There are 2 things are wrong w/ your method:
Code:
Dh (bearing) == 1-3/16" == 1.1875" == 3.01625 cm dalek is probably right -- just buy more RAM. However, the fact is that info. transfers are ~2.7 times faster from the outer sectors of a drive than from the inner sectors of a drive, & this will remain true for as long as we continue to use drives w/ platters. I think that balancing the speed of transfer against against head movement time is an interesting intellectual -- but not practical -- problem. My seat of the pants guess is that the optimum place for swap is near R75. I usually implement this on a single drive system by making it the 3rd primary partition, just before the extended partition. If you're not going to buy more RAM, then put your swap on the outer sectors of a separate spindle. If you want to get really fanatical about it, track down an obsolete SCSI drive, cable, & card that will give you reasonable speed. See this chart of Parallel SCSI interfaces. Ultra2 SCSI, aka Fast-40, or better would probably do the trick. |
All times are GMT -5. The time now is 10:00 AM. |