Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Is Swap Necessary?

michael posted more than 10 years ago | from the got-swap? dept.

Linux 581

johnnyb writes "Kernel Trap has a great conversation on swap, whether it's necessary, why swapless systems might seem faster, and an overall discussion of swap issues in modern computing. This is often an issue for system administrators, and this is a great set of posts about the issue."

cancel ×

581 comments

Sorry! There are no comments related to the filter you selected.

fpppppp (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283370)

fp

I agree!@ (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283376)

first post!

IMHO (3, Interesting)

rd4tech (711615) | more than 10 years ago | (#9283378)

One can have 1GB of RAM for a fairly cheap price.
I really doubt that majority of newest desktop PCs need to swap on the HD at all.

The unused/used portions argument from the article isn't quite true. You don't have to swap every unused bit,
if you have enough RAM, leave everything there. It's R-A-M. don't access parts you don't need.
If you don't have them in the RAM, read them from the drive,
don't waste time putting them where they mostly are in the first place.

I'm willing to bet that people who need performance, don't often run 10 applications at the same time. If they do, they
surely know what are they doing.

IMHO the average user should get enough RAM and no swap, let the OS optimize things a bit.

You've some good points... (5, Interesting)

robslimo (587196) | more than 10 years ago | (#9283428)

but today's production, heavily loaded system will still need the ability to swap to/from disk.

Already, there are systems that minimize that need, set-top boxes, embedded systems in general. But each of those is seriously modified (kernel-wise, mostly) to achieve the responsiveness, the frugality of resource treatment that a general purpose desktop computer can't expect to enjoy.

That doesn't mean that developers should stay in the same rut, assuming that hardware that confined system design in the '60s, '70s... '00s will perpetually assign similar constraints.

IMO, desktops still need to swap... for now. but let's not paint ourselves into a performance corner.

Re:You've some good points... (5, Interesting)

Goldberg's Pants (139800) | more than 10 years ago | (#9283478)

If you've just got a box sitting not doing much, in other words not serving pages, SQL or whatever, you can run with minimal ram. My laptop has 24 megs of ram. I did have a 100 meg swap partition, but needed the space for a particular huge DOS game I wanted installed, so nuked it and converted it to DOS. Booted Linux and checked the ram usage and most of the ram was used.

However, when I ran a program, the amount of used ram DROPPED.

Of course in an environment where the system gets hammered, it's all very well talking about how cheap ram, but so is hard disk space. Is it really worth not setting up a bunch of swap space? What if a rogue process munches it's way through the ram while you're away? Would it not be better to have swap space and have it so the system can run, albeit not very well, than just die on you?

I don't know, I ain't a sys admin, but performance issues aside, I don't see why you should risk it. I'd rather have swap partitions on a hardcore system than not.

Re:IMHO (5, Interesting)

Trepalium (109107) | more than 10 years ago | (#9283446)

The other side of this is that memory that is not being used is wasted. Getting unused memory out of RAM, and into swap, so that memory can be used for real work can improve performance. This isn't just about memory that your applications are using. It's also about memory that is being used as cache for the disks you're using.

Maybe you have enough memory to run your program, but you don't have enough memory to keep enough directory structures into RAM, so you keep needing to read the disk. If there are unused pages in that program that were only used once during startup, for example, it makes sense to get them out or memory, so that memory can be used for disk caching instead.

Now, you have to understand how Linux handles paging, too. Unmodified pages from executables that are running may be discarded by the kernel at any time, because it knows where to get them. They won't be thrown into swap because it's not necessary. On the other hand, if that particular page has been modified (and some are modified as they are loaded by ld.so, for example), then the page must be copied into swap before it's discarded.

Re:IMHO (5, Informative)

irokitt (663593) | more than 10 years ago | (#9283452)

Linux has two properties that make swap a good thing (TM).

The first thing to remember is that, for many Linux users, they have a newer PC running Windows (or a Mac ;) and a less recent PC running a Linux distro. The RAM threshold is realistically around the 128-512 MB range. Those who are dual-booting on a brand new machine can use 1 GB, but the rest of us put up with less than that (I for one want to avoid MBR screwups and the hassle of communicating with NTFS, so I don't dual boot. I had a nasty GRUB incident, so I'm probably paranoid).

Finally, every Linux user that has compiled a kernel knows that it can really tax a system. Gentoo users also know how strenuous a XFree86 or KDE/Gnome compile can be. Being able to work on another terminal while compiling is one of the most beautiful things about *nix, and to do that on anything with less than 512 MB or 1 GB or RAM you want to have some swap.

And finally, while RAM is very cheap, so are hard drives, and how hard is it to squeeze a swap partition out of a hard drive? Can it really hurt that much to let the system use it?

As for Windows, swap is absolutely required for a lot of the games that are out there. I've heard that Unreal-engine based games in particular make heavy use of swap filing.

Uninformed opinions (1, Informative)

Anonymous Coward | more than 10 years ago | (#9283563)

I for one want to avoid MBR screwups and the hassle of communicating with NTFS, so I don't dual boot.

The fact that you irrationally avoid two very mature and easy-to-understand technologies implies you are uninformed and compels me to ignore any suggestions you might have.

I've heard that Unreal-engine based games in particular make heavy use of swap filing.

"You've heard"? As in, someone told you to believe it but you didn't take the time to think about the claim yourself? No application can "make heavy use of swap filing". Either it uses a lot of RAM or it doesn't. And either it accesses RAM in a predictable pattern (condusive but to swapping) or not. But an application can't actually make use of swap filing: it always -thinks- it's using RAM. The OS will always decide whether it's time to swap in or out.

Re:IMHO (4, Informative)

zoloto (586738) | more than 10 years ago | (#9283572)

My take on the swap -vs- no swap.
I have no data, links or proof to back it up. Only the system responsiveness under two different setups.

Setup A) 300mhz intel, 256mb ram, 6gb hdd, swap 512mb.
Taking the swap out of that setup and the system crawled to a halt, expecially when using X. Re-enabling it and it ran just fine.

Setup B) 2GHz Intel, 1gb ram, 40gb hdd, swap 2gb.
Taking out the swap in that machine and the system ran fine. Even running Half-Life: Counter-Strike via WineX by transgaming. Re-enabling the swap, and I noticed a little performance increase, but I couldn't measure it b/c I didn't know how.

Just my take on it. Swap is generally a good thing in older machines, while in newer systems it isn't a critical thing to have. HOWEVER, I did not run many tests with and w/o swap. just basic use, and Setup B's HL:CS test was only to make sure!

YYMV, KBD.

-zoloto

Re:IMHO (1)

jrockway (229604) | more than 10 years ago | (#9283505)

I have 1G of RAM, and no swap. Works great, even with eclipse, maple, firefox, and other stuff open at once. Having 10 things open at once doesn't degrade performance under Linux. That's a feature reserved for Windows...

IYHO (1)

nfabl (748199) | more than 10 years ago | (#9283570)

From what i gather one of the reasons swap is considered necessary is that its not possible to shift pages around in physical memory to optimize things.

(Note: this is me speaking out of my arse, please correct me flamefree :P)

Say you have 100 meg of ram (to make things easier) and 5 applications have 10 meg of ram allocated to them at equally distant addresses. Application #1 says it needs 60 meg allocated sequentially. In order to do that 60 megs, a couple of other apps will need to be swapped out.

Now, without swap that wouldn't be possible, so the allocation would fail.

So what interests me is if you had a RAM disk set as swap would that make this possible, and the whole swap thing more efficient? Say 1/4 ram is ram-swap, and have another 512meg as disk swap at a lower priority?

asdf (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283380)

a;lkdjf;alskjfd - first post

YES SWAP IS NECESSARY (-1, Flamebait)

Anonymous Coward | more than 10 years ago | (#9283382)

I SWAPPED SPIT WITH KATHLEEN MALDA, AND RIGHT NOW I'M JACKING OFF TO MY PRECIOUS PICTURE OF HER.

HERE'S ONE FOR YOU SLASDHTOT FAGS TO ENJOY, LAMERS:

*_g_o_a_t_s_e_x_*_g_o_a_t_s_e_x_*_g_o_a_t_s_e_x_*_
g_______________________________________________g_ _
o_/_____\_____________\____________/____\_______o_ _
a|_______|_____________\__________|______|______a_ _
t|_______`._____________|_________|_______:_____t_ _
s`________|_____________|________\|_______|_____s_ _
e_\_______|_/_______/__\\\___--___\\_______:____e_ _
x__\______\/____--~~__________~--__|_\_____|____x_ _
*___\______\_-~____________________~-_\____|____*_ _
g____\______\_________.--------.______\|___|____g_ _
o______\_____\______//_________(_(__>__\___|____o_ _
a_______\___.__C____)_________(_(____>__|__/____a_ _
t_______/\_|___C_____)/______\_(_____>__|_/_____t_ _
s______/_/\|___C_____)EAT_IT_|__(___>___/__\____s_ _
e_____|___(____C_____)\______/__//__/_/_____\___e_ _
x_____|____\__|_____\\_________//_(__/_______|__x_ _
*____|_\____\____)___`----___--'_____________|__*_ _
g____|__\______________\_______/____________/_|_g_ _
o___|______________/____|_____|__\____________|_o_ _
a___|_____________|____/_______\__\___________|_a_ _
t___|__________/_/____|_________|__\___________|t_ _
s___|_________/_/______\__/\___/____|__________|s_ _
e__|_________/_/________|____|_______|_________|e_ _
x__|__________|_________|____|_______|_________|x_ _
*_g_o_a_t_s_e_x_*_g_o_a_t_s_e_x_*_g_o_a_t_s_e_x_*_


Important Stuff: Please try to keep posts on topic. Try to reply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account.

Important Stuff: Please try to keep posts on topic. Try to reply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account.

Important Stuff: Please try to keep posts on topic. Try to reply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account.

eply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account. Problems regarding accounts or comment posting to reply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account. Problems regarding accounts or comment posting to reply to other people's comments instead of starting new threads. Read other people's messages before posting your own to avoid simply duplicating what has already been said. Use a clear subject that describes what your message is about. Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page) If you want replies to your comments sent to you, consider logging in or creating an account. Problems regarding accounts or comment posting

Re:YES SWAP IS NECESSARY (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283509)

Cowboy? is that you?

Swap sucks (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283383)

Free Michael Jackson!

Re:Swap sucks (-1, Troll)

Anonymous Coward | more than 10 years ago | (#9283402)

better idea
lets install a pickle sized tracking device in his anus, maybe he will think twice about molesting people then.

Re:Swap sucks (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283437)

You put it in though, OK?

Swap is definitely necessary (3, Insightful)

betterthanducttape (763202) | more than 10 years ago | (#9283386)

When I was running Linux on my 350 mHz Pentium II with 128MB RAM, you can dang well bet I wouldn't have made it without a swap partition. I probably would have gone back to Windows if swap hadn't existed.

Re:Swap is definitely necessary (2, Interesting)

Anonymous Coward | more than 10 years ago | (#9283422)

Not for everyone. I've got 1GB in my machine, and I don't think I've ever come near maxing it out. I've actually turned off the pagefile* in Windows and haven't had any problems other than Photoshop whining everytime I start it (even if it never uses more than 100MB of RAM, it still whines if there's no pagefile present).
I don't use linux, so I can't say how well it'd work on my machine without swap, but I can't imagine it'd be any worse.

* For the Windows-ignorant: a pagefile is the Windows equivelent of swap.

Re:Swap is definitely necessary (1)

user32.ExitWindowsEx (250475) | more than 10 years ago | (#9283507)

Wait...you got Photoshop to actually RUN?

I tried it and I don't remember getting it to actually run..it would whine about no swap file and the error box about no swapfile would basically quit the prog

Re:Swap is definitely necessary (1)

irokitt (663593) | more than 10 years ago | (#9283519)

Yeah, it's really just a swap file. You can do the same thing in Linux, which allows you to avoid partitioning your hard drive and also allows you to adjust swap size on the fly.

I still use a page file because you need it for gaming. In fact, I heard somewhere that there are games that freak if you don't have a larg page file, even if you have more than enough RAM to do without. Kinda like a security blanket...

Re:Swap is definitely necessary (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#9283485)

OHOHO! YES YOU ARE FUCKED otherwise

am i right bitched??Es?

If You have enough RAM (5, Funny)

Greyfox (87712) | more than 10 years ago | (#9283388)

You could make a big ramdisk and swap to that!

Re:If You have enough RAM (5, Funny)

whiteranger99x (235024) | more than 10 years ago | (#9283416)

Yeah, just remember to allocate twice the amount of ram that you have installed! :)

Re:If You have enough RAM (0)

Anonymous Coward | more than 10 years ago | (#9283418)

I have often wondered about this, is this a valid approach??

Re:If You have enough RAM (1)

josh3736 (745265) | more than 10 years ago | (#9283455)

You could make a big ramdisk and swap to that!
I have often wondered about this, is this a valid approach??

No.

By definition, a RAM disk is kept in RAM. Therefore, you'd be swapping out of RAM... into RAM. It's the same as if you would put a divider in a storage shed because you were running out of room. You can move stuff on either side of it, but in the end, you still only have a fixed amount of space.

Re:If You have enough RAM (1)

arekq (651007) | more than 10 years ago | (#9283466)

It is an approach that won't do you any good.

Think about it: Amount of RAM stays constant. Instead of just leaving the data where they are, you waste some cpu cycles moving them to another part of the memory space...

Re:If You have enough RAM (1)

machacker (772227) | more than 10 years ago | (#9283461)

ive thought of this before but never tried it. its the best of both worlds, speed of ram and the advantages of swap

Re:If You have enough RAM (1)

arekq (651007) | more than 10 years ago | (#9283495)

Are you serious?

The advantage of swap is that it increases the amount of memory applications can use without adding more RAM.

If you use RAM disk for swap, it'll only decrease performance because of the unnecessary moving of memory blocks.

Re:If You have enough RAM (0)

Anonymous Coward | more than 10 years ago | (#9283552)

but supposdly there are technical differences in the way the os handles memory between ram and hd besides speed. i would like to see some actuall tests comparing for example:

256 ram + no swap

128 ram + 128 ramdisk as swap

128 ram + 128 swap

Re:If You have enough RAM (1, Interesting)

Anonymous Coward | more than 10 years ago | (#9283546)

This might not be such a funny comment considering that why they swap improves performance is

"well it is a magical property of swap space, because extra RAM doesn't allow you to replace unused memory with often used memory. The theory holds true no matter how much RAM you have. Swap can improve performance. It can be trivially demonstrated."

Wouldn't having a swap drive in ram improve the overall performance of having a swap drive and still keep the above true?

Re:If You have enough RAM (0)

Anonymous Coward | more than 10 years ago | (#9283549)

I know one person that is quite good at tweaking MS Windows that actually claims this can be a good idea.

On a related note, back in the late System 7, early Mac OS 8 days, I used to create a RAM disk to use as my Netscape cache. It resulted in a HUGE increase in speed when surfing on an 8500/180.

they need updated docs for todays ram amounts (5, Insightful)

Anonymous Coward | more than 10 years ago | (#9283391)

All the docs on Linux and swap amounts to use are from the days of 386s and 4 megs of ram!

I want to know how much swap I should REALLY be using for a system with 1 gig of ram.

Same for some of the kernel compilation docs. Maybe on a 4 meg system compiling that extra option might cause slowness but on a 500 meg system does an extra 30k in the kernel matter?

Can we get some docs that aren't from the mid 90s!

Re:they need updated docs for todays ram amounts (2, Insightful)

rd4tech (711615) | more than 10 years ago | (#9283407)

Start running bunch of applications and seeing what happens with the memory and the swap. The swap hardly gets used at all if you have 1GB RAM. On the other hand, on my old 486 with 32MB of RAM, swap was the main thing.. Sometimes several hundred MBs

Where many people miss the point... (4, Insightful)

NerveGas (168686) | more than 10 years ago | (#9283394)


People like to claim that swap can always improve performance, by swapping out unused sections of memory, allowing for more memory to throw at apps or disk cache.

Well, *most* apps won't just arbitrarily consume memory, so endless amounts of memory won't help. And disk cache gets you greatly diminishing returns.

One of the machines I use has 3 gigs of memory. It will swap out unused programs, in an attempt to free up more memory. The joke is that it simply can't use all three gigs. After half a year of uptime, there's still over half a gig completely unused, because the apps don't take memory, and there's not that much to put in disk cache.

Obviously, that's a pathological case. And there are pathological cases at the other extreme. But as memory prices keep dropping over the long run, swap does become less and less useful.

steve

Re:Where many people miss the point... (0)

Anonymous Coward | more than 10 years ago | (#9283415)

Actually Linux will use every MB for diskcache and will continue keeping it in memory aslong as the cache is consistent or it has to cache new things
(very funny with having complete CD images in memory and such)

Re:Where many people miss the point... (1)

arekq (651007) | more than 10 years ago | (#9283569)

Sometimes when I need to use some big files, especially over the network, I "cat file >/dev/null" first and watch it fill the memory. :)

Re:Where many people miss the point... (2, Informative)

Anonymous Coward | more than 10 years ago | (#9283475)

One of the machines I use has 3 gigs of memory. It will swap out unused programs, in an attempt to free up more memory. The joke is that it simply can't use all three gigs. After half a year of uptime, there's still over half a gig completely unused, because the apps don't take memory, and there's not that much to put in disk cache.

Yes, it is swappnig because it is trying to free up "low memory", of which you have less that a gig. This is unfortunately an inevitable failure case of Intel's brain damaged (although practical) PAE schmeme.

Were you to have no swap at all, you may have had to reclaim important kernel side caches (inode, dentry caches), or even had memory alloction failures in eg. the network stack (common).

Re:Where many people miss the point... (0)

Anonymous Coward | more than 10 years ago | (#9283538)

schmeme

Err, scheme. OTOH, schmeme sounds pretty funny and is possibly an accurate description of IA32's PAE.

Re:Where many people miss the point... (1)

anthony_philipp (710666) | more than 10 years ago | (#9283527)

but one nice thing about swap is that when your system fails everything in RAM can be dumped into swap, this may help give you and idea about what caused the problem in the first place. however in your case keeping 3 gigs of swap around just in case your system fails probably isnt worth it. then again if you have 3 gigs of RAM you can afford a larger hard drive and put some swap on it.

Eventually... (1)

aphor (99965) | more than 10 years ago | (#9283558)

Eventually my persistent storage device will be solid state with ultra-efficient DRAM and integrated batteries, and my system RAM will be a big SRAM space. I will want to swap to DRAM.

Re:Where many people miss the point... (1)

zx75 (304335) | more than 10 years ago | (#9283562)

Ok, well you might not have a use for an OS that swaps, but most of the rest of us don't have three gigs of memory on our systems and run them for months at a time.
Myself? I code for fun and profit, and I know that there are times that I need to push my computer hard, and I do have a gig worth of memory, but even so I've run out of swap space of my system partiton a time or two despite having another gig and a half allocated for that purpose.

swap rule! (5, Informative)

Coneasfast (690509) | more than 10 years ago | (#9283395)

the rule is swap should be 1.5x your RAM! ;)

actually MS followed this rule, in win2k, the default swap size is set to exactly 1.5x your ram, was 176 for my 128mb system, and 384 for my 256mb system, not sure about XP though, someone fill me in
(yes, some great minds working at MS)

Re:swap rule! (0)

Anonymous Coward | more than 10 years ago | (#9283434)

Yeah, WinXP recommends 1.5GB on my system. I have it set to 0 though. :)

Re:swap rule! (0)

Anonymous Coward | more than 10 years ago | (#9283443)

I probably should have stated I have 1GB or RAM, so XP still conforms to the 1.5x rule you talked about....

Re:swap rule! (1)

archen (447353) | more than 10 years ago | (#9283441)

I thought it was 2x RAM. Which brings up the point, if I have say 3 Gigs of RAM, do I really NEED 6 Gigs of swap? Hell look at how long it wout take to read 6 Gigs off the hard drive. I agree with the article that swap is probably still neccesary, but perhaps the rule of thumb needs to be adjusted according to usage and needs. Personally I never go over 512M of swap no matter how much RAM I have, but I'm not a kernel hacker either and I have yet to see a good answer concerning when I can make due with a more RAM than swap.

Re:swap rule! (1)

gasgesgos (603192) | more than 10 years ago | (#9283457)

My computer (windows xp) has 1.5gb of RAM, so it has a swap file of over 2gb...
My roommate has 2gb of RAM, and a 3gb swap file, also using windows xp...
If he's already got 2gb of RAM, what the hell does he need 3gb of swap space for!?

windows needs to create swap file sizes inversely proportional to the amount of RAM....

no swap? (3, Interesting)

hawkeyeMI (412577) | more than 10 years ago | (#9283398)

I ran linux without a swap file on 128 MB of memory a couple of years go. It was an accident, I didn't create a swap partition. I never had a problem (forutnately). Of course, I wasn't doing the heavy duty stuff I am now (scientific computation).

Re:no swap? (1)

hawkeyeMI (412577) | more than 10 years ago | (#9283476)

Oh man the typos are killing me... should have previewed.

Swap space not needed.... (4, Funny)

kidgenius (704962) | more than 10 years ago | (#9283400)

If you've got 128MB of RAM you have plenty and therefore will have no need for swap space. I mean, isn't 640k enough for everyone?

Re:Swap space not needed.... (4, Insightful)

Coneasfast (690509) | more than 10 years ago | (#9283438)

isn't 640k enough for everyone?

people constantly make this joke, but seriously, at the time BG said this, it was probably true.

if today i say "1 gig ought to be enough for everyone" it is true, but in 10 years from now you will be laughing at this.

he never claimed it would 'ALWAYS' be enough (unless there is more to this quote???)

Re:Swap space not needed.... (0)

Anonymous Coward | more than 10 years ago | (#9283516)

If 1 gig ought to be enough for everyone (I presume you mean anyone), then why are there computers out there with 8TB+ RAM today?

You think they are just waiting for Windows(c)(r) Special(c)(r) HPC(c)(r) Super-Friends(c)(r) BSOD(c)(r) Matrix Reloaded(c)(r) Cool(c)(r) 2010(r)(c) Edition?

Yes, It's Necessary (3, Insightful)

rsmith-mac (639075) | more than 10 years ago | (#9283410)

As long as users can eat up more memory than they have available, and as long as hard drive space is cheaper than RAM space, swap will always be necessary.

On a laptop... yes, for the wrong reason (0)

robbo (4388) | more than 10 years ago | (#9283413)

Goddammit I can't suspend my laptop because my swap partition is insufficient in size. Why should I have 2 GB of disk space *empty* all the time just so I can close the lid.

Someone please fix acpi hibernate to do something sane...

Re:On a laptop... yes, for the wrong reason (2, Informative)

whiteranger99x (235024) | more than 10 years ago | (#9283425)

Yeah, because God forbid you should have to use the SAME amount of disk space as the ram you have installed to save a few seconds to bring the laptop up :P

Re:On a laptop... yes, for the wrong reason (2, Interesting)

robbo (4388) | more than 10 years ago | (#9283470)

It's all diskdrake's fault. I didn't choose my swap size, afair, although it's weird it's smaller than my RAM. Beyond that, acpi recommends you have swap about 30% larger than your RAM. While it would slow down the suspend, I don't see why acpi doesn't pipe /dev/mem through bzip first, or for that matter, why hibernate can't just dump to a file.

Re:On a laptop... yes, for the wrong reason (1)

kayen_telva (676872) | more than 10 years ago | (#9283501)

there is nothing "informative" about the parents post and the GP has a valid point.
surely the contents of ram can be compressed ?

Re:On a laptop... yes, for the wrong reason (1, Informative)

Anonymous Coward | more than 10 years ago | (#9283502)

I don't know if it works for SWSUSP (the hibernation driver), but you can actually swap to a file under GNU/Linux. You can add and remove swap files while the system is running, so you might even be able to add a power management script that creates and formats a swap file right before hibernating, and deletes it after unhibernating.

speaking of which (1)

MasTRE (588396) | more than 10 years ago | (#9283417)

Does anybody have experience with running swapless Linux servers? I am looking for a best practices for setting memory and virtual memory limits (presumably, using ulimit). Can setting soft (ulimit -aS) and hard (ulimit -aH) limits guarantee that your programs will not eat up all of the system's RAM and cause an OOPS? I'd love to hear about your experiences.

Re:speaking of which (1)

wotevah (620758) | more than 10 years ago | (#9283473)

When a process tries to eat more RAM than is available, the kernel will not panic and will calmly kill the bad process.

Swap nessisary in low mem (128M) systems (4, Informative)

strredwolf (532) | more than 10 years ago | (#9283419)

Swap improving performance... yeah. On slow systems and low memory, every byte freed up helps. But not swapping in the first place is good too.

I'm now expermineting with replacing various tools with smaller versions, such as dropbear, udhcp, tinylogin, and buzybox. I'm also slowly writing up a "exec and restart shell afterwards" utility called PivotShell.

Hardware wize, I have swap on a CF drive. 32 megs so far, but if I can afford larger CF drives, I'll format 'em as swap and use them.

Why all of this? 40 megs swaps to HD, and on a laptop, any HD access sucks battery power. When you're using Xfree (or even Kdrive) and Firefox, you're going to swap. Period.

Re:Swap nessisary in low mem (128M) systems (4, Informative)

BiggerIsBetter (682164) | more than 10 years ago | (#9283486)

Don't do that. CF has a limited number of write cycles (100,000 or so, typically), and swapping to it will kill it quite quickly.

Re:Swap nessisary in low mem (128M) systems (1)

beerits (87148) | more than 10 years ago | (#9283555)

Doesn't Compact Flash have a limited number of write/rewrite cycles? I would think using it for swap would burn through those cycles very quickly.

Swap can save your ass (4, Interesting)

Julian Morrison (5575) | more than 10 years ago | (#9283426)

Sometimes, when a process goes haywire, it will start munching RAM. If important programs like, say, sshd or X, can't malloc when they need to, they'll die ignominiously. Swap gives you the chance to kill the rogue process before your OS goes kaput. Its slowness can actually help for this.

Re:Swap can save your ass (1)

robbo (4388) | more than 10 years ago | (#9283523)

Once upon a time, like kernel 2.0, rogue processes would go haywire, consume all available memory (and swap), and then die quiet deaths without any real effect on system stability. When 2.2 came out, I remember submitting a bug because rogue processes could render the entire system unstable by consuming all the ram and swap. I haven't tried it on 2.4 or 2.6, but I remember the bug was squashed as NOTABUG.
One would think that ensuring system stability against such a simple DOS attack would be a priority.

Re:Swap can save your ass (0)

Anonymous Coward | more than 10 years ago | (#9283575)

No, the 2.0 kernel can't magically make swapping efficient.

More likely, as the gap between RAM size and harddisk speed vastly increases, you simply noticed the increased impact of having all your memory swapped out.

ulimits are what you are after.

Relation to 40h bit computing? (0)

Thinkit4 (745166) | more than 10 years ago | (#9283435)

On one hand you can have a huge amount of RAM. On another, you can have memory mapped I/O. Anyone see the future of this?

Swap is vital (1)

psetzer (714543) | more than 10 years ago | (#9283444)

Swap files are how we are able to get those $400 computers. I don't have any idea how a modern person can put up with 128 megs of RAM and Windows XP, but some people out there do. Doing without swap is only really feasible if you aren't running many different things on your computer at once, and what you do run isn't as much of a hog as many programs are nowadays. I guess if you were to use as small of a Linux kernel as you could and didn't install X on your computer, it wouldn't be much of a problem and you could do without swap. If you really want to go light on the memory usage, just use ed.

Re:Swap is vital (0)

Anonymous Coward | more than 10 years ago | (#9283477)

Well, in linux I don't need swap except when I am using maya. I generaly use about 50 of my 192 megs. In windows though I definately need it. I turned it off once to get rid of that unmoveable sector when I was repartitioning it. Sickening...

Re:Swap is vital (1)

L0stm4n (322418) | more than 10 years ago | (#9283497)

I run fedora core 1 and I use X. I use fluxbox as my window manager and I ussually have a few mozilla windows ( mozilla, not firefox ) konqueror, xchat xmms or mplayer.

I have 640MB RAM in this machine. 415MB is cache right now. I barely touch my ram and could probably do without it MOST the time. Then there are those few times where your system would slow to a crawl without swap.

A no swap system can be done if the memory usage is a known constant, otherwise leave some room for yourself.

Re:Swap is vital (1)

Doppler00 (534739) | more than 10 years ago | (#9283503)

Doesn't anyone remember the days when we had full graphical user interfaces in less than 8MB of RAM? What's this about needing 128MB of ram? Where did all our memory go?????

Re:Swap is vital (1)

Stevyn (691306) | more than 10 years ago | (#9283541)

Remember how ugly those gui's looked? I remember running windows 3.11 and netscape on 4 megs back in the day. It actually had this problem where it would saturate the system and completely reboot in the middle of browsing.

Where does the ram go? Well in windows, I don't know. It always seems to disappear with each new version. However, you can see how some applications are really wasteful. I've seen AOL instant messenger take about 25 mb of ram. Photoshop opening large files will take well over a hundred. Explorer, you're talking 20-30. Basically that's 150 without even considering windows, which needs a minimum of 128 to get started. I think developers are taking it for granted because ram is getting cheaper. There is no reason AIM should require so much ram though, that's crazy.

Try this with linux (4, Interesting)

arvindn (542080) | more than 10 years ago | (#9283451)

Notice how sluggish the system is after doing something disk-intensive like watching a movie. That's because the kernel is caching as much of the movie as possible to memory and swapping your running apps out. And kernel developers think this is a good thing, so it isn't going to change any time soon. IMHO for a desktop system this makes no sense, that's why I run my 1GB RAM machines with zero swap.

The Kernel Can Take a Hint (5, Informative)

EventHorizon (41772) | more than 10 years ago | (#9283539)

In the average case code and data _do_ tend to be accessed more than once. We would all be complaining a lot more if the kernel NEVER cached... remember the huge performance boost SMARTDRV made in DOS?

So, frankly, the default kernel behavior is right.

To fix the movie/updatedb/jumbo cp/etc issues see "man madvise" and check out MADV_DONTNEED. I am hoping applications will start using this syscall sooner, rather than later. The Linux VM can take a hint, and it's pretty easy to give it one.

Re:Try this with linux (1)

Rashkae (59673) | more than 10 years ago | (#9283548)

Actually no,, I agree that it's unfortunate the Disk Cache ends up holding useless data, (like a movie file that gets read once sequentially). But even so, switching tasks is almost always instant. The only problem I've ever encoutered is with applications that eschew senseless amounts of memory. (Like Mozilla or Firebird. The longer those have been running, the longer they will have to swap when I switch back. For Mozilla, I find it necessary to close the application from time to time and restart it to prevent the eventual memory leak from causing swap storms.)

Besides, if this behaviour bothers you, you can change the value of swappiness to prevent your applications from being swapped out. Overall, however, on most average workloads, the default settings provide the best performance.

With the amount of RAM available (1)

czephyr (706389) | more than 10 years ago | (#9283458)

Why are we whining about swap files any longer?

IMHO, anyone running a system (WIN ME - XP) with less than 256MB RAM is nuts.

I feel that if you want to remove swapping then have more memory than memory addresses. Let's see what happens when the machine has to figure out what to do with the extra memory it has.

Back to topic: Really, how much is a GIG of RAM nowadays?

I'm only just a l'il punch drunk :-)

I just don't get it. (2, Interesting)

mcg1969 (237263) | more than 10 years ago | (#9283465)

Seriously, I don't get it. How in the world can swap ever increase performance.

Specifically, suppose I have one computer with 1GB of RAM and 1GB of swap, and another computer with 2GB of RAM and no swap. Under what circumstances will the first computer be any faster?

Now I suppose if the swap is used for other things besides memory space then I could understand it. But then it seems like a simple solution would be to allocate a fraction of RAM for those things. In effect, create a swap partition on a RAM disk :)

Seriously, I'd appreciate some education here, but make sure you answer my specific scenario above if you reply... thanks

Re:I just don't get it. (1)

multriha (206019) | more than 10 years ago | (#9283531)

Physical memory is always better than swap, nobody is claiming otherwise. A system with 1GB of RAM and a 1GB of swap should be faster than the same system withou swap.

Should is the tricky part.

Re:I just don't get it. (0)

Anonymous Coward | more than 10 years ago | (#9283534)

I can't answer your scenario because your scenario is FLAWED. Of course having more ram will make the second system faster. There is no way the first could be faster. Thats not the issue. The valid comparison is a 1G machine with swap and a 1G machine without.

Re:I just don't get it. (5, Informative)

sprag (38460) | more than 10 years ago | (#9283535)

The potential speed increase isn't seen when comparing 1G RAM vs a 2G RAM system. Its comparing a 1G RAM system with a 1G RAM system with swap.

The gist of it is: with swap you can put things that aren't being used (like mingetty, gdm, etc) into swap to free up space for things that are running now. Without swap you have to keep the little-used processes in memory and you don't have as much 'free' space to use for things like caches.

Its also important to note that the kernel will swap out code segments regardless of whether or not you have a swap partition: they get swapped out to nowhere. When they need to be swapped back in, the executable file itself is read.

Re:I just don't get it. (1)

gerardrj (207690) | more than 10 years ago | (#9283565)

For the most part these people are wrong when they say that.
There is no point where replacing disk swap with real RAM will slow things down in an average system, or conversely that using disk swap instead of RAM will speed things up.

If you have 1GB RAM and 1GB swap, then change to 2GB RAM and 0GB swap, the OS will run faster. For one thing, there's a whole chunk of memory management code that doesn't need to run. Second you never have to wait for the relative eternity for data to get to/from disk.

There is one possible exception that involves running mostly idle applications that get swapped out, and a one/ a few very active ones that do a lot of processing on a few files. In this case a swap enabled system could run some tasks faster. Assuming that the apps swapped out run only very infrequently, the space opened up in RAM would allow for more of the large files to be cached and hence accessed faster. But a significant portion of the data would need to fit in RAM, or you'll just wind up going to disk anyway and loosing the swap advantage.

Personally, I don't use swap unless the system just physically can't handle the memory I need or I just can't get it installed at the moment. Once I know what the RAM requirements for the system will be, I configure enough to handle that and disable swap.

One other thing: disabling swap may well let you spin down the hard drives more often, the system is (from my experience) much more tolerant of spin-up delay for accessing normal filesystems than swap.

I'm curious how windows does it (2, Interesting)

Stevyn (691306) | more than 10 years ago | (#9283468)

This may be slightly off topic...

Running KDE 3.2.1 now, I notice it takes longer to open apps than it does in windows. Mozilla for example takes literally a few seconds longer to open each window than it did in windows. Another thing windows does is make it faster when you run an app right after you ran it then closed it. Say for example in windows I run mozilla, then close it, then open it. When it opens it the second time, it's almost instant. However in linux, it seems to take the same original amount of time to load it completely. I'm sure it has to do with an entirely different process of loading programs, but apps always seemed to open faster in windows than in linux, in my view.

Then again, graphics used to be in the NT kernel and that's what made it appear fast, but lead to a lot of problems and crashes, so maybe the longer load time is worth the wait when compared to a reboot.

gmail (3, Funny)

maxbang (598632) | more than 10 years ago | (#9283482)

I use my gmail account as my swap partition. It's fully searchable and displays helpful advertisements every time I load fifty tabs in Firefox and OpenOffice goes idle. I don't know what I'd do without it. I'd probably be less of an unfunny jackass.

Re:gmail (1)

djplurvert (737910) | more than 10 years ago | (#9283533)

Every time I read "g"mail, I read it as "gay"mail...I'm not saying that means anything or anything, just something I observerd.

Re:gmail (2, Funny)

maxbang (598632) | more than 10 years ago | (#9283551)

Dude, that's the funniest thing I've read today. And I'd totally date you, but my IQ is four. I'm typing this with a toothbrush that's stapled to my head.

okay, here's a challenge... (4, Insightful)

Doppler00 (534739) | more than 10 years ago | (#9283488)

Does anyone out there want to run a series of benchmarks with a few standard applications to prove/disprove whether disabling swapping improves performance?

I'm tired of just hearing antidotal evidence on this. Everyone has their stories about turning off swap files and improving performance, but in what cases? Are there some users this would harm?

Re:okay, here's a challenge... (1)

thebatlab (468898) | more than 10 years ago | (#9283508)

I'm even tired of hearing anecdotal evidence

Re:okay, here's a challenge... (1)

Doppler00 (534739) | more than 10 years ago | (#9283537)

okay, I made a typo and I'm tired.

Swapless even with 1GB of ram (1)

Piranhaa (672441) | more than 10 years ago | (#9283504)

I remember when I had disabled swap completely under windows XP. The first program that gave me annoying errors was photoshop. Every time it would start up it would say "Photoshop detects there is no swap, and it should be used or problems can occur with your system". (something like that). Also, some games (empire earth for one) would not even run without a swap partition. So even though you don't technically NEED one, some programs still rely on it!

Hardly ever use swap (1, Offtopic)

yhetti (57297) | more than 10 years ago | (#9283506)

None of my machines have less that 512 megs of RAM, (or more than 1.8GB) and I never use swap...never have a problem with it. It's faster because drive access doesn't have to compete w/ swap (even on SATA it's annoying).

Okay...I lied. Does anybody else use Pan? I mean..wtf?! When I run Pan it's more like

$ cat /dev/zero > /swap.tmp
*wait 20 seconds*
$ mkswap /swap.tmp
$ swapon /swap.tmp
$ exit
# pan

Pan is an awesome program, but seriously...when it can single handedly use > 1GB of RAM just stealing divx rips...

We don't need swap (1, Funny)

Anonymous Coward | more than 10 years ago | (#9283513)

We can just make an OS that reboots every time it runs out of memory. Oh, wait, someone already did that...

What about Diskless Drives! (0)

Anonymous Coward | more than 10 years ago | (#9283518)

Alot of companies around here have started purchasing diskless drives for their workplace. SWAP is pretty darn useless then.

If you need to use Swap for what your doing with your computer, then you obviously don't have enough ram!

well one reason (2, Informative)

discogravy (455376) | more than 10 years ago | (#9283521)

one reason you'd want swap on a system is to have someplace to dump/savecore information in the case of system crashes. Kind of hard to do with volatile memory.

It's a choice... (4, Interesting)

Beolach (518512) | more than 10 years ago | (#9283526)

As I RTFA & previous comments here, I was rather suprised at how argumentive people were getting over this. Some people are saying swap is an absolute necessity & a swapless system was a broken system, while other's said swap was an obsolete solution to a problem that no longer exists (expensive RAM). This seems odd to me, because as far as I can tell, the decision of whether & how much swap to use is based mostly on two things: specific situations (and thus there is no general answer to 'Is Swap Necessary?'), and opinion. And either way, with the Linux kernel today (and for quite a while now), I can choose for myself whether or not, and how much, swap I want to use. So if I am in a situation that I think requires swap, I can use it, and in a situation that I think would be hurt by having swap, I don't have to use it. So I don't see why there's so much hoolabaloo about this: nobody is forcing anyone to do it one way or the other. And if someone else thinks it should be done different from how I would do it, that's their decision, not mine.

Run Pan (0)

Anonymous Coward | more than 10 years ago | (#9283529)

load a binary newsgroup of 500K+ posts (on my system)
watch performance drop to zero.

or load one with 750K+ posts and watch you run out of memory. dmesg errors (process killed out of memory)

thats when swap and RAM were filled

swap deals with bloat (4, Insightful)

wotevah (620758) | more than 10 years ago | (#9283532)

Most applications today have unnecessary or rarely used portions of code or data - bloat. These get swapped out first. Also there are various memory leaks here and there, which means the programs sometimes forget to release allocated memory they do not need any longer.

Look at the size of your X server, or mozilla, or apache, or pretty much anything else and you will see over the course of a few weeks that it has grown beyond reasonable operation demands.

The memory lost this way is never accessed from there on, but the system cannot release it without the program telling it to, so it does the next best thing and shoves it in the swap. Not a solution since eventually swap gets full, but since the leaks are slow to begin with, at least it prevents them from affecting system performance too early.

Amiga (4, Interesting)

Jace of Fuse! (72042) | more than 10 years ago | (#9283566)

In the 90's, I ran a 10 line BBS on an Amiga 4000 with 16 megs of Fast ram, 2 megs of Chip ram, and 0k for the swap file. :)

I know, I know, the Amiga didn't HAVE virtual memory. Well actually it did if you had an 040 and installed a memory management program such as GigaMem, but so few people had a use for such a thing that it was practically unheard of.

Oh, and before someone jumps in saying that I wasn't able to do anything else, that is totally NOT the case.

Very often I was doing lots of stuff. The difference is developers were used to working within memory constraints, and now days developers are used to systems growing into the applications.

Rule of Thumb: 256MB on x86 (0)

Anonymous Coward | more than 10 years ago | (#9283571)

when a board has more than 265MB RAM, swap may be well suited for 3 things.

1. Java
2. Python
3. Earwax

All 3 in common; when unchecked, they fall down at most inappropriate time.


=================
Q: What's your name?
A: Slim
Q: Slim Shady?
A: No, Slim Jim
Q: A Beef Jerky?
A: No, I'm just black on the outside and light in the inside.

I have never... (0)

Anonymous Coward | more than 10 years ago | (#9283573)

... seen any swap usage, at all, on my Linux box... OK, granted I have a gig of ram. But I do like to use xmms, kde 3.2, mozilla, and other memory hogs. I guess what I'm saying is that for people like me, swap is pretty much necessary, because not everyone has a gig of ram.

Now, I would like to see Windows manage the above scenario... I had Win2k on the same hardware and it never used more than around 650 MB of the physical RAM, and still swapped around 200MB when I was using stuff that wanted huge amounts of ram (photoshop, etc)
Load More Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>