Slashdot Mirror


Tuning Linux VM swapping

Lank writes "Kernel developers started discussing the pros and cons of swapping to disk on the Linux Kernel mailing list. KernelTrap has coverage of the story on their homepage. Andrew Morton comments, 'My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful.' Personally, I just try to keep my memory usage below the physical memory in my machine, but I guess that's not always possible..."

324 comments

  1. Ob. /. joke by Anonymous Coward · · Score: 2, Funny

    First swap!

  2. God no... by 0123456 · · Score: 5, Interesting

    "You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful."

    I absolutely despise the way that XP swaps out applications in order to make the disk cache larger. I have 1GB of RAM on my machine precisely so I don't have to wait two minutes for it to swap my web browser back in after it's swapped out... yet if I copy a 2GB file from one drive to another, the stupid operating system will swap out all the applications it can just to make the cache larger.

    Please, please, don't take Linux down the same braindead route as Microsoft has done for XP. It's utterly insane to swap out my browser so that a 2GB file can be copied two seconds faster when I then have to wait two minutes for the browser to swap back in. Or at least provide some kind of '#define STOP_VM_SWAPPING_STUPIDITY' so that I can disable it.

    1. Re:God no... by Anonymous Coward · · Score: 0

      I hate to tell you this but it actually sort of does this already. It swaps out ig chuncks of data that it hasn't seen accessed in a while to increase cache size and IMHO this is a good thing. Why waste ram that could be used for live data?

    2. Re:God no... by ninewands · · Score: 2

      I agree. My box has 768 megs of RAM specifically to minimize swapping. If BloatyApp occupies it all and I start up another app to do something else, I'm prepared to tolerate the swap delay, but if BloatyApp is all I'm using and I start a file copy in a shell, I'd rather get back to what I was doing in BloatyApp than have the copy finish an immeasurable fraction sooner.

    3. Re:God no... by Anonymous Coward · · Score: 0

      I hate that too. Why do I have to wait for my apps to swap back in just because the screen saver comes on when I go take a p break. Stupid design. NT was better.

    4. Re:God no... by 0123456 · · Score: 3, Interesting

      "I hate to tell you this but it actually sort of does this already."

      Maybe 2.4 does, but my 2.2 system has never suffered from this problem (haven't got around to upgrading it yet). Small amounts get swapped out, but nothing noticeable in interactive use.

      "Why waste ram that could be used for live data?"

      Because when I want to use my web browser again after playing a game for an hour, I don't want to have to sit there for two minutes watching it slowly swap back in... interactivity is far more important to me than small performance benefits from an extra 64MB of disk cache.

    5. Re:God no... by Anonymous Coward · · Score: 2, Interesting

      Mozilla is the application I know of that has that demonstrates that behavior under XP so I'd suggest using another browser if it bothers you that much.

      I use XP extensively and it is very agressive at swapping stuff out. However, I've never had the problems with other applications besides Mozilla.

    6. Re:God no... by petabyte · · Score: 5, Informative

      Actually, you can change it on the fly with /proc/sys/vm/swappiness Increasing the number will increase the agressiveness of the swapout. Mr. Morton runs with his set at 100 (the max). 0, I believe would turn swap.

      My kernel has autoswappiness enabled so it figures out the number on its own. I'm running at 64 ATM on a 256 Meg system (ram donations accepted) :).

    7. Re:God no... by kinema · · Score: 3, Informative

      All you need to do is: "echo 0 > /proc/sys/vm/swappiness" and the VM will do it's best to keep from swapping pages to disk.

    8. Re:God no... by Shakrai · · Score: 4, Interesting

      Please, please, don't take Linux down the same braindead route as Microsoft has done for XP. It's utterly insane to swap out my browser so that a 2GB file can be copied two seconds faster when I then have to wait two minutes for the browser to swap back in

      Does it really make it faster anyway? Unless parts of that 2GB file were already in the cache then how is the cache going to make it transfer any faster?

      As a side note I haven't noticed Linux swapping much out in favor of the cache. My home grown samba/sql/dhcp/nat/intranet server has 768 megs of memory. As of today (43 day uptime -- Linux 2.4.25) there is only 2,528k in SWAP. 8,444k of free memory, 191,952k used for buffers, 296,004 used for cache and the rest for applications.

      I wouldn't mind seeing Linux swap out programs that aren't touched in several days/weeks (like the 12 agetty processes on my monitor less machine -- yes I know I could disable them if I wanted) but I definitely don't want to see it swapping out that browser I used 5 minutes ago in favor of increasing the disk cache size. Now if I launch Quake that's a different story.

      As far as the other posts about rule of thumb for swap size go -- I stopped using the 1:1 or 2:1 ratio a long time ago. I have a 256meg swap partition on my 768meg Linux box. That's pretty much as big as I go with swap spaces. Are you seriously going to setup a 768 (or worse x2) swap space? A) You'll never use it, B) If you do use it your machine will barely be useable.

      As far as XP's stupidity goes look under My Computer -> Properties -> Advanced -> Performance Settings -> Advanced and make sure both options (processor scheduling and memory usage) are set to "Programs" and not "background services" or "System cache". That may (or may not -- it is Windows after all) help you a little. On the flipside of the coin I discovered that I needed to reverse the memory option on my Windows 2000 Terminal Server to prevent stupid HP print drivers from sucking up 100% of the CPU and 90% of the physical memory.

      --
      I want peace on earth and goodwill toward man.
      We are the United States Government! We don't do that sort of thing.
    9. Re:God no... by Elm+Tree · · Score: 2, Informative

      If I recall correctly it's runtime tuneable. So us power users with 1+ gig can tune swapping down, and desktop distros can tune it up. That's my favorite part about linux, I can just
      cat 0 > /proc/sys/vm/swappiness
      and I have instant control as to the performance of my machine. In fact... I could even write wrappers to specific programs so that they can tune the system's swappiness to better suit them. I.E. Programs that use huge ammounts of memory, less swappy, programs with repetetive disk access more swappy... Is swappy even a word?

    10. Re:God no... by Anonymous Coward · · Score: 0

      Set the file cahe to be a fixed size. It is not XP's fault. It is yours.

      There are many legitamate things to gripe about MS. Your ignorance of the OS isn't one of them.

    11. Re:God no... by 1000StonedMonkeys · · Score: 3, Interesting

      Java also has the same problem. Almost makes you think they do it on purpose.

    12. Re:God no... by Anonymous Coward · · Score: 1, Interesting

      Have you ever really looked at the results when you do make the changes to the file cache. It does NOTHING! It must be a legacy setting (just one of thousands laying around the registry).

      If you can prove to me otherwise I would be indebted to you forever, cause the file caching management is one of my biggest gripes about W2K/XP.

    13. Re:God no... by nikster · · Score: 1

      i hear you.

      i have the same problem with Retrospec backup software. one run and XP swaps out everything, system, applications, Explorer, etc.., so i have to wait >5 minutes before i can use the system again. This is with 1 G of physical RAM installed.

      the solution would be a limit to the disk cache to a reasonable size. i can see that servers would want all RAM for caching, but desktops? probably not. there should be a limiting percentage, like 10% of RAM. 100M is plenty of disk cache for my use...

      be sure to check if system properties->advanced->performance options->advanced->memory usage is set to "Programs".

      hmm... did i mention this is extremely LAME?

    14. Re:God no... by Monkelectric · · Score: 1
      That's odd because the NT swapping strategy shouldn't do that (unless they've changed it for XP?).

      NT is supposed to maintain *small* disk caches to avoid the situation you're talking about, where as linux has always had a less conservative policy of using pretty much all avaliable ram for disk cache and pushing things out when needed.

      I would actually be pretty surprised if that was the case... the os SHOULDN'T kick programs out for disk cache except under extreme situations. For all the shit we give MS their kernel design is usually pretty damn good. Next time you do something like that check your disk cache levels and see if thats whats actually whats going on. If you are concerned O&O soft makes software to manage disk cache, and I believe nt internals has a utility to alter some of the disk cache properties.

      --

      Religion is a gateway psychosis. -- Dave Foley

    15. Re:God no... by ByteSlicer · · Score: 1

      If you have 1GB of RAM, as I do, you can just disable the swap file. I'm running XP for a few months like that now, seems to work fine. Or at least set the minimum and maximum swap sizes to 100MB, to reduce that rediculous 1.5GB swap file (although XP can still resize it then if it runs out of RAM).

    16. Re:God no... by MikeHunt69 · · Score: 0, Offtopic

      ... and how exactly will that help the OP in XP?

    17. Re:God no... by Anonymous Coward · · Score: 0

      This is the part of the thread where the no-nothing freshman CS majors tell Microsoft and lead kernel developers that they don't know what they're doing.

    18. Re:God no... by sweet+cunny+muffin · · Score: 1

      He doesn't mean cache. He means the size of the buffer used to copy files. With a larger buffer there are fewer reads and writes (each with more data though), so the process is faster. A larger buffer needs more RAM, so something may have to be swapped out to make space.

    19. Re:God no... by ckaminski · · Score: 4, Interesting

      Mozilla has the problem specifically because it's memory footprint gets so large with all those tabs. If you don't use process separated IExplore processes, you get the same problem with IE when it's footprint gets up around 70+ MB.

      The only way to stop this madness on XP is to turn off the swapfile. I'd REALLY hate to see Linux go down this route. Big bloaty applications need to stay IN MEMORY unless there is memory pressure being exerted on the system. That is the only time swapping should occur.

    20. Re:God no... by colinleroy · · Score: 1

      Or at least provide some kind of '#define STOP_VM_SWAPPING_STUPIDITY' so that I can disable it.

      like /proc/sys/vm/swapiness

      --
      blah
    21. Re:God no... by Anonymous Coward · · Score: 0

      I have. Visual Studio, IE, Notes, Word, Excel, OO.org, the list goes on.

    22. Re:God no... by ckaminski · · Score: 3, Interesting

      Windows 2000 and XP both give preference to the cache, no matter what your system preferences are. I've had a network copy/backup going while trying to run Word, and the damned OS consumed 300 of 500MB of memory for the disk cache. It's a problem I've been trying to rememdy for a long time now. Supposedly there's a registry setting for the cache, and a size limiter, but I've not been able to get it to work...

    23. Re:God no... by illtud · · Score: 1

      Please, please, don't take Linux down the same braindead route as Microsoft has done for XP. It's utterly insane to swap out my browser so that a 2GB file can be copied two seconds faster when I then have to wait two minutes for the browser to swap back in

      Does it really make it faster anyway? Unless parts of that 2GB file were already in the cache then how is the cache going to make it transfer any faster?


      It doesn't, but the OS might imagine that you're going to use that file again, so it caches it in the disk cache. I'm unsure as to whether the linux kernel will cache a file as you copy it - I wish it wouldn't on a simply filecopy, but it may work at a much lower i/o level, so it doesn't know whether you're opening/reading the file for copying or for something that may benefit from caching (opening an application, for example).

      Anybody know if the linux disk cache is intelligent?

    24. Re:God no... by The+Spoonman · · Score: 5, Informative

      Right-click My Computer -> Advanced -> Performance -> Advanced -> Memory Usage. Set to Programs. Now, click Change under Virtual Memory. Set your cache size small. For 1G of RAM, you prolly don't need a biggun. I usually set it to 100M for Inital and Max and then up it based on how often the machine swaps.

      Then, make the following changes to the registry:

      HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\ClearPageFileAtShutdown, set to 1. I don't shut my machine down very often, but occasionally XP will increase the size of the pagefile if it absolutely needs to depending on circumstances. This forces it back to the size you want it when you restart.

      HKLM\System\CurrentControlSet\Control\FileSystem\N tfsDisable8dot3NameCreation, set to 1 ONLY IF YOU USE NO 16-BIT APPS ON YOUR MACHINE. Speeds up writes.

      HKLM\System\CurrentControlSet\Control\FileSystem\N tfsDisableLastAccessUpdate, set to 1 if you don't care when files are accessed. This is rarely needed, and the setting speeds up writes.

      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Contro l\Session Manager\Memory Management\IoPageLockLimit. Little more complex:

      Set to 4096 if you've got more than 32M RAM

      Set to 8192 if you've got more than 64M RAM

      16384, 128M

      32768, 160M

      65536, 256M

      131072, 512M

      This changes the maximum number of bytes that can be locked for I/O operations. The default is 512Kb. While the above are the recommendations, I've found stepping down one level to provide the most performance for my needs, YMMV. (For example, I have 256M, but I set my IO limit to 32768.)

      HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management\DisablePagingExecutive, Set to 1 to disable paging of the kernel.

      There, that wasn't so hard, was it? For those who want to flame that statement, keep in mind, that the information above is easier to find than some of the tuning suggestions I've heard for Linux. I've used Linux for 10 years, and only today heard about /proc/sys/vm/swappiness. Oh, and all of the above apply from at least NT4+.

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    25. Re:God no... by mdfst13 · · Score: 2, Funny

      Don't you know?

      It's impossible to help people in XP. :)

    26. Re:God no... by straybullets · · Score: 1

      That may (or may not -- it is Windows after all) help you a little.

      well i don't know but it sounds that the swapinness settings may or maybe not help you a little.

      It's the point of the whole article, which, for once, i read : swapiness may not do what you think it does, that is set it to zero and speed up the desktop

      --
      With that aggravating beauty, Lulu Walls.
    27. Re:God no... by AKAImBatman · · Score: 1

      Stupid design. NT was better.

      Better? The same NT that would swap an entire program to disk the moment it was minimized? Those of us on 2000 always felt sorry for our fellows on NT4. Every time they minimized their app server to get it out of the way, or switched to it to see the error log, their machine would die for about 2 minutes. NT better - that's a good one.

    28. Re:God no... by The+Spoonman · · Score: 1

      Don't you hate people who reply to their own posts? :) One caveat for the above. I've been trying to install SameTime for Lotus Notes on my machine, and just figured out why it wouldn't install...the installer's 16-bit. Disabling 8.3 name creation is the problem. Actually, it's not the installer, but the self-extracting exe, so what I did was copy the sametime.exe to another machine started the setup, copied the setup files when they're uncracked back to my machine and ran setup. Yeah, it's a pain, but if people would use 32-bit apps....besides, this is only the second time in 7-8 years I've needed to do this, so I ain't complainin'.

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    29. Re:God no... by SkunkPussy · · Score: 1

      " Actually, you can change it on the fly with /proc/sys/vm/swappiness Increasing the number will increase the agressiveness of the swapout. Mr. Morton runs with his set at 100 (the max). 0, I believe would turn swap."

      Its a sad day when paraphrasing the article and providing no new information is rated as +5 informative.

      --
      SURELY NOT!!!!!
    30. Re:God no... by ggeens · · Score: 1

      Most of the time, my laptop handles things quite well. Even with several (rather large) applications open. (Including WSAD, FireFox.) The system has 1GB of memory, so I'm not really stressing it.

      Once a week, when the virus scanner pops up, things are different. As mentioned above, XP starts swapping things out to make room for disk cache - rather useless, since the virus scanner will read each file only once, and pass on to the next one. (Admitted, the OS has no way of knowing that.)

      --
      WWTTD?
    31. Re:God no... by Anonymous Coward · · Score: 1, Insightful

      One of the best methods I've heard of for swapping stuff out is to be aggressive about it but not complete the process; that is, the VM manager can write hundreds of pages to disk but not remove them from memory. Then if another application suddenly needs a lot of memory, it can very quickly free up the memory without the delay imposed by swapping it out. Or if the "swapped out" application needs to use its memory, the pages on disk can be quickly marked as invalid and pages in memory used instead.

    32. Re:God no... by frostjoe · · Score: 0

      This is the part of the thread when those very same "no-nothing freshman" (sic) tell you that you can't spell.

    33. Re:God no... by 5E-0W2 · · Score: 2, Informative

      There's no "copy file" system call, it's just a read and then write loop. However in many cases, the program doing the copying should use O_DIRECT or posix_fadvise DONTNEED.

    34. Re:God no... by Gilk180 · · Score: 3, Informative

      Duh.

      Who thinks that writing a page to disk immediately wipes the ram it came from. This is how things really do work.

      The problem is whether this paged but still valid ram should be given to other processes. I would say it is a tuning thing. There is no perfect method that will be best for all situations.

      Whoever modded this insightful needs to do a little reading about operating systems.

    35. Re:God no... by Fjord · · Score: 2, Insightful

      The thig I hate about 2000 is that it seems to hold on to this disk cache RAM for dear life. Eventually, if you hibernate/unhibernate, or just don't turn off the computer, you swap for everything. It's a real pain in my assass well. I've disabled virtual memory on my windows machine at home (at work, I run too much to do so), just because it's not really needed and makes it much faster.

      --
      -no broken link
    36. Re:God no... by psavo · · Score: 1

      I'd make that 'echo 0 > /proc/sys/vm/swappiness'. I really don't think that having ./0 would help you in a day-to-day life.

      --
      fucktard is a tenderhearted description
    37. Re:God no... by Fjord · · Score: 1

      That is pretty good. You could have this as part of your X startup scripts, so when you login, it makes it more snappy, and when you log out, it undoes it. It might be possible to undo it on screensaver and redo on return as well, but I've never done that kind of thing.

      --
      -no broken link
    38. Re:God no... by ostrich2 · · Score: 1

      I think the 1:1 and 2:1 ratios were so that if the system goes into a panic, it can copy the contents of memory to swap. If you're running with less than 1:1 ratio, you'll lose sections of memory that might help you deduce the cause of the crash.

    39. Re:God no... by scrubmuffin · · Score: 1

      Obviously, there should be an easier way to configure a swap mechanism for desktop or server specific activity. I would prefer that my server not sacrifice the performance of moving data across my network in order to accomodate someones desire to access a running application a little quicker. Of course, as linux gains more of the desktop market share, this will not be the norm.

    40. Re:God no... by jbayes · · Score: 2, Informative
      I've used Linux for 10 years, and only today heard about /proc/sys/vm/swappiness.

      That's 'cause "swappiness" was just added in the 2.5 series. It hasn't been around that long.

      --

      "It sure was strange to see something on Usenet about me that didn't involve Klingon gang rape." -- Wil Wheaton

    41. Re:God no... by WaltFrench · · Score: 1

      As a longtime Mac user, I'm used to hearing that my machine is slow. But 2 minutes for a browser to swap back in?!? I can't imagine ANY program taking that long to load AND initialize, let alone merely shuffle back into memory.

      I routinely have a couple gigs of apps running, necessarily overflowing available RAM, so my Powerbook swaps to a (not ultrafast) laptop drive. I maybe see 2 or 3 seconds, tops, of wait time, ever. Is your swap area on a tape drive?

      This thread seems to be rife with all sorts of speculation about optimizations and very little data other than examples that suggest the problem is severely mis-identified. Seems that gross exaggeration is suggesting, wrongly, that a generally useful swap mechanism is awful when it is less than optimal. Dedicated-use servers might perform a little better with hand-tuning, but general-use machines, where usage patterns are highly unpredictable, seem very unlikely to benefit from extreme variances from a generally-useful approach.

      --
      "Inquiring Minds Want to Know!"
    42. Re:God no... by Anonymous Coward · · Score: 0

      ahhh.. slashdot. One of the only places where an on-topic MS comment is rated -1 Offtopic.

    43. Re:God no... by scrubmuffin · · Score: 1

      "I wouldn't mind seeing Linux swap out programs that aren't touched in several days/weeks (like the 12 agetty processes on my monitor less machine -- yes I know I could disable them if I wanted) but I definitely don't want to see it swapping out that browser I used 5 minutes ago in favor of increasing the disk cache size. Now if I launch Quake that's a different story."

      We are talking two different purposes here though, desktop and server and cacheing/swapping should be optimized for one or the other. I have three simple rules for servers.

      Rule 1. Don't play quake on them.
      Rule 2. There is no rule 2.
      Rule 3. See rule 1.

    44. Re:God no... by Spackler · · Score: 2, Funny

      And I would like to thank God for this being so intuative. It was right on the tip of my tounge the whole time.

    45. Re:God no... by CommandNotFound · · Score: 1

      That's odd because the NT swapping strategy shouldn't do that (unless they've changed it for XP?).

      I enjoyed NT4 as a dev box. With Win2K and WinXP, there are two basic features that have gradually deteriorated, however, and those are swapping and multitasking. Everything the posters have said is true: if you touch the filesystem in a big way (including the extremely borken file search utility in XP), it will swap out all your apps so that when you go to check your mail, etc, you get to watch your windows redraw pixel by pixel while the H/D goes nuts. How I wish the old Win9x MaxFileCacheSize setting was still there.

      And without dual CPUs, WinXP is not a multitasking OS anymore. Try starting a compile/search/whatever and do something in the foreground... it's too frustrating, so it's best to just put the background task back in the foreground so it can get its priority boost and just go get some coffee. Yes, I've tinkered with the foreground/background switch; I don't think it's wired up anymore. I hate to see how boggy Longhorn will be; but hey, some newb will be able to share photos more easily once a year, so it's worth it to spend my 8 hour day in front of the PC frustrated.

      But I'm not bitter. :)

      For all the shit we give MS their kernel design is usually pretty damn good.

      My guess is that the original authors are long gone or promoted, and the code is so taped-together that everyone is too scared to touch it anymore. Would you change a module of code if it could cause 20 million support calls when it crashes on a brandX mobo?

    46. Re:God no... by Darth+Daver · · Score: 3, Insightful

      I have been using Windows for 12 years (and Linux for 10), and this is the first time I have heard of the obscure registry hacks you just listed. Besides, I thought Windows users argue they should not have to find, learn or research anything at all. It should just work, right?

      When I just searched for '/proc linux vm swap' in Google, /proc/sys/vm/swappiness was in the fourth hit from the top. There, that wasn't so hard, was it?

      I can tell you one thing. I would rather poke around the /proc filesystem than wander through the Windows registry any day.

      By the way, if you are not shutting your XP system down often, you must not be rebooting for the security patches, and that can be a problem for everyone. (Yes, I am aware that Microsoft has gone to a monthly release cycle now while simultaneously claiming to release within hours versus the weeks they claim FOSS takes.)

    47. Re:God no... by julesh · · Score: 1

      There is no perfect method that will be best for all situations.

      True, but I think in most cases it is fair to say that reusing a live process's page for disk cache is usually undesirable.

    48. Re:God no... by Anonymous Coward · · Score: 0

      You know, for 99.9% of the users out there your Disable 8.3 suggestion is a ridiculous micro-optimization. The time spent debugging the sametime install was probably a 10x the computer time you'll ever spend writing 8.3 names over your whole lifetime.

      And there's a bunch of ~1 references in the registry, so breakage is inevitable.

    49. Re:God no... by Shakrai · · Score: 1

      Maybe 2.4 does, but my 2.2 system has never suffered from this problem (haven't got around to upgrading it yet). Small amounts get swapped out, but nothing noticeable in interactive use.

      Here's a question that maybe a developer can answer. Isn't there a system call in Linux (or Unix as a whole? Posix standard perhaps?) that you can use (assuming root privileges) to prevent a program's memory pages from being swapped out in the first place?

      I seem to recall a patch for the old version of PGP that would do this because of the paranoia of allowing PGP to swap out (possibly unencrypted) data to disk where it could later be recovered. If such a system call does exist it would probably be child's play to patch Mozilla to prevent the swapping out in the first place.

      That's probably a better solution then screwing with the Kernel -- which usually at least has good intentions behind it's swapping.

      --
      I want peace on earth and goodwill toward man.
      We are the United States Government! We don't do that sort of thing.
    50. Re:God no... by Anonymous Coward · · Score: 0

      Here we go with religon entering the conversation on /.

      Did God himself put the swappiness parameter in or was it the imperfect man trying to emulate God that caused swappiness to be an obscure setting in Linux?

    51. Re:God no... by Anonymous Coward · · Score: 1, Informative

      man 2 sendfile

    52. Re:God no... by Gilk180 · · Score: 1

      unless you're running a database, a web server, etc and the 'live' process isn't gonna use those pages for a little while. If it really is a 'live' process it won't get swapped out. If you mean 'interactive' process, then you get into the windows trap of optimizing everything for foreground processes and killing your ability to do real multitaking.

      Particularly from the linux point of view, dbms/web server/etc performance should be a big issue. This is where linux thrives. And as was mentioned before, this is tunable for desktop users who want to keep the disk cache small because most pages are only needed once anyway.

    53. Re:God no... by Telex4 · · Score: 1

      For those who want to flame that statement, keep in mind, that the information above is easier to find than some of the tuning suggestions I've heard for Linux. I've used Linux for 10 years, and only today heard about /proc/sys/vm/swappiness.

      Nevermind the fact that the kernel with support for that has only been out in the /. mainstream for maybe half a year, how can you claim that making hacks in a registry like:

      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Contro l\Session Manager\Memory Management\IoPageLockLimit. Little more complex: Set to 4096 if you've got more than 32M RAM

      Is no more complicated than doing a quick grep on the kernel documentation, or in Google, and finding out about a file in /proc called /proc/sys/vm/swappiness, which has values between 0 and 100?

      Yegads man, not to mention that nobody but the craziest geek or compulsive sysadmin is going to want to play with the swapping settings of their kernel, having an obvious, documented setting placed in an obvious, standard and well-named place must be more simple, surely?

    54. Re:God no... by dasmegabyte · · Score: 1

      I think it's funny how some Linux users seem to think less than less than a month of uptime is no uptime at all, while most Windows users consider going a week without shutting down to be a long time.

      I find that the challenge of extending my Windows 2000 uptime (26 days as of yesterday) to impress my Linux friends sometimes causes me to keep my system up too long. My machine was moving slow as hell over the past two weeks, despite the fact that my processor time was under 20%. Come to find out it's using 800 meg out of 512 with only 300 listed in processes. Meaning that I had 500 meg worth of leaked memory clogging my page file, a page file on the same drive as all the file operations I was performing. A quick reboot and it was much snappier.

      Oh, and before you cajole me about how Windows always gets leaks, you should know that memory leaks are a big pet peeve of mine. I once uninstalled a beautiful $300 capture card because the drivers leaked memory. I traced the leak back to GTK+ 2 for Windows. The Gimp kept crashing on me whenever I'd load a certain font and GTK+ 2 wasn't reporting the memory it was using back to the stack. Not dissing the Gimp or GTK's developers -- after all, the GTK+ toolkit is finally nice enough to hook me on this fine program -- but I can't use a program that bloats up my ram like that. My kingdom for some exception handling! This computer is slow enough as it is!

      Incidentally, most of the recent security updates for Windows haven't required a reboot lately. I've installed the last 3 or 4 with no reboot needed. Microsoft seems to be making a real effort to avoid reboots whenever possible, which is to be lauded -- I remember when you could expect to be forced to reboot any time you'd install a program. Which is something I wish that Apple would do...iTune 4.5 didn't NEED a reboot, but it asked for one anyway. The whole "reboot just to be sure" think is silly.

      --
      Hey freaks: now you're ju
    55. Re:God no... by ctr2sprt · · Score: 1
      Most computer users don't have 1GB RAM. I'd put it at about 70/30 256MB/512MB. That's the target audience XP has, and that's where their aggressive swap-out strategy works best. I know that I find it useful on my 256MB system (actually I wish it were more aggressive).

      I agree that XP's implementation is perhaps not so great; it should deal more gracefully with situations where you have plenty of physical memory. But that doesn't mean the entire approach is bad.

    56. Re:God no... by dasmegabyte · · Score: 1

      Few things about cache: I always set it to twice the physical ram. Windows seems to like that. And the last thing you want is some hardly used memory hog eating up the physical memory when it could sit silently on disk.

      Second: you mentioned using the same value for Initial and for Max, but you didn't mention why. Here's why: using the same value allows you to lock the size of the page file, meaning Windows never tries to allocate more disk space to it. You can then defragment the drive and optimize where this file sits on the disk to improve performance significantly.

      --
      Hey freaks: now you're ju
    57. Re:God no... by Darth+Daver · · Score: 1

      I definitely agree with your comment about Apple. OS X is really nice, especially coupled with a PowerBook, but it feels like half of their updates require reboots, which is silly considering what is being updated in most cases.

    58. Re:God no... by dasmegabyte · · Score: 2, Funny

      And here, I thought swappiness was a warm gun.

      --
      Hey freaks: now you're ju
    59. Re:God no... by Anonymous Coward · · Score: 0

      Isn't that one of those chmod sticky bits is for?
      That's what I use on my home computer - a PDP 11/70 running AT&T v7 UNIX

    60. Re:God no... by MenTaLguY · · Score: 1

      If the memory a process allocated isn't unconditionally freed when the process exits (crash or no), that's an OS bug, not a bug in the application.

      It's probably GDI resources and things, though, not memory per se. The Windows GDI design is such that there is no way a process' GDI resources to be freed if the process crashes.

      Which, again, is an OS (design) issue.

      --

      DNA just wants to be free...
    61. Re:God no... by Anonymous Coward · · Score: 2, Informative

      Yes, a program can use the mlock(2) and munlock(2) calls to disable swapping of its memory on a page granularity (usually a multiple of 4096 bytes).

    62. Re:God no... by Foolhardy · · Score: 1
      (Admitted, the OS has no way of knowing that.)
      Actually, it does, if the app tells Windows. You can open a file with a flag that specifies no buffering. It's the antivirus app developer's fault for not using it. It's not even obscure: see CreateFile and FILE_FLAG_NO_BUFFERING from MSDN.
    63. Re:God no... by Foolhardy · · Score: 1
      The Windows GDI design is such that there is no way a process' GDI resources to be freed if the process crashes.
      That's bogus. It was only true in 16 bit windows where there was no process seperation. Add the column GDI and USER handles in task manager. Processes create GDI and USER handles the same way as other handles; they are freed when the process terminates, wether it closes them or not. They are tracked by the win32 subsystem in win32k. Try creating a program that leaks 10000 gdi handles (the default process limit) and then close it (or crash it or whatever). They will all be freed.
      If the memory a process allocated isn't unconditionally freed when the process exits (crash or no), that's an OS bug, not a bug in the application.
      It is freed when the process exits. Try the above test with memory.

      As for uptime, my main computer (XP sp1) has been up for 42 days, since I upgraded the video drivers. It hasn't crashed since I dumped nVidia's crappy 53.03 drivers about 70 days ago. No slowdowns. No global memory leaks (although I think Mozilla is leaking: it's up to 70MB of private memory.) My laptop has been up for 124 days (also XPsp1). (hibernating 3/4 the time, so its about 30 days of actual use)
    64. Re:God no... by whitmer · · Score: 1

      Right-click My Computer -> Advanced -> Performance -> Advanced -> Memory Usage. Set to Programs. Now, click Change under Virtual Memory. Set your cache size small. For 1G of RAM, you prolly don't need a biggun. I usually set it to 100M for Inital and Max and then up it based on how often the machine swaps.

      Then, make the following changes to the registry... [ lots of registry entries ]


      Wow, I really appreciate that Windows swap control is much more intuitive than doing 'echo 0 > /proc/vm/swappiness' in Linux. ;P

    65. Re:God no... by diegocgteleline.es · · Score: 1

      Linux has always had lots of VM tunables, ie: /proc/sys/vm/bdflush etc. swappiness is just a abstraction.

    66. Re:God no... by Anonymous Coward · · Score: 0

      Not that this is a POSIX call. Here is an example of its use in GnuPG. They use it for security reasons.

    67. Re:God no... by The+Spoonman · · Score: 1

      Is no more complicated than doing a quick grep on the kernel documentation, or in Google, and finding out about a file in /proc called /proc/sys/vm/swappiness, which has values between 0 and 100?

      Lessee...what was it I was supposed to grep for? Swappiness? How 'bout I do a search at Google for +linux +performance +tweaks and on the first page found not ONE useful tip, unless you're a coder..., but a similar search for +windows +performance +tweaks resulted in page after page listing the tweaks I offered, and more...

      nobody but the craziest geek or compulsive sysadmin is going to want to play with the swapping settings of their kernel, having an obvious, documented setting placed in an obvious, standard and well-named place must be more simple, surely

      If you're not a COMPULSIVE sysadmin, then you're a hack collecting a paycheck you don't deserve. But, that's not the point...actually, I'm not really sure WHAT your point is...Linux has no obvious, well-documented, standard location for such tweaks. Sometimes it's in proc, sometimes a config in /etc or /usr/etc or /usr/local/etc or /opt/{program}/etc or some other place. Good luck finding it. All of the tweaks I listed are well-known (by those who know what they're doing) tweaks, and easily found by a generic search as above. The more obsure voodoo, sure, that can be a quest, but the basics (and these are all basics) are easy enough. I certainly hope you're not administering Windows machines if all this stuff is new to you...

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    68. Re:God no... by dasmegabyte · · Score: 1

      I believe there was a meme; the time had come for swappiness, and so swappiness was had!

      --
      Hey freaks: now you're ju
    69. Re:God no... by The+Spoonman · · Score: 3, Interesting

      I have been using Windows for 12 years (and Linux for 10), and this is the first time I have heard of the obscure registry hacks you just listed.

      The above hacks aren't for users, they're for administers and geeks. The average user will boot their machine, do what they have to do, and shut it back down. For those who aren't users, we like to leave our machines on for months at a time and these tweaks will help with that. If you were doing tech support, then you'd know them. If you ARE doing tech support and don't know them, please consider another field. These are the basics...IT's already filled up with enough paper MCSEs who can't spell NT unless it's in the 6-week course.

      When I just searched for '/proc linux vm swap' in Google, /proc/sys/vm/swappiness was in the fourth hit from the top. There, that wasn't so hard, was it?

      No, when you know EXACTLY what you're looking for, it never is. Now, search for +linux +performance +tweaks, and tell me if it shows up. Didn't, did it? Now, search for +windows +performance +tweaks. How many of those pages DIDN'T list the tweaks I just gave? Not many.

      I can tell you one thing. I would rather poke around the /proc filesystem than wander through the Windows registry any day.

      Because the difference is...? One's a collection of key-value pairs organized in a virtual filesystem analogy and another is a collection of key-value pairs organized on a filesystem? Or, is it because MS puts a warning that if you don't know what you're doing, editing the registry can fuck your system, but the Linux developers fail to give you the same warning?

      By the way, if you are not shutting your XP system down often, you must not be rebooting for the security patches, and that can be a problem for everyone.

      Could be, but I keep my machines fairly secure to begin with, and few of the security patches issues by MS affect well locked-down machines. They're more for user's PCs, like yours. Also, the last few security updates I've done haven't required a reboot. Unlike the latest kernel updates...

      claiming to release within hours versus the weeks they claim FOSS takes

      Or, years. How long was that latest flaw in the kernel sources that took down the Debian servers? Years? I thought the "many eyes" theory said something like that wouldn't reach production as there's so many people reviewing the code. I'll give you a clue: just 'cause the code's available doesn't mean many more people outside the development team is looking at it. Most are doing ./configure && make && su && make install and trusting it'll all be okay. It must be, right?

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    70. Re:God no... by The+Spoonman · · Score: 1

      Wow, I really appreciate that Windows swap control is much more intuitive than doing 'echo 0 > /proc/vm/swappiness' in Linux. ;P

      The registry tweaks I gave were a "bonus". The "swappiness" feature is in the initial instructions. Regardless, considering how much easier it is to find the information that such things can be changed in Windows, as compared to Linux, then, yes, Windows IS more intuitive.

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    71. Re:God no... by Anonymous Coward · · Score: 0
      A lot of installers are 16-bit. AVG Antivirus Free edition is an example. The best way to find out what's 16-bit is to install the Windows Support Tools (found on the Windows CD) and use the filever command line tool.
      for /r %I in (\*.exe) do @echo %~nxI & filever /v "%I" | findstr "OS:.*16"
      will show the prevalence of 16-bit installers.
    72. Re:God no... by The+Spoonman · · Score: 1

      I always set it to twice the physical ram

      Depends on the amount of physical ram and the usage of the machine. If I have at least 256M of RAM, I've rarely found need for my home machine to have larger than a 100M swap file. However, at the office, I've found that 1.5X is a better limit. I prefer to start small, and go from there. :) I also tweak down most things from running that I don't need. For example, extraneous services, tray applets, etc. Right now, on XP, running IE and a mail notifier only, I'm only using 76M of ram.

      but you didn't mention why

      You're right, sorry about that. I tried to document all the other ones, but missed that one. Thanks for clarifying for everyone.

      BTW, are you the same dasmegabyte that frequents my site? :)

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    73. Re:God no... by 5E-0W2 · · Score: 1

      sendfile is for stuff like webservers sending out content. These definately do want to cache, so I'm assuming sendfile will load stuff into cache too. Stuff gets faulted in and then sent directly however, without being transferred to userspace.

    74. Re:God no... by Anonymous Coward · · Score: 0
      if you touch the filesystem in a big way (including the extremely borken file search utility in XP), it will swap out all your apps

      NEVER use Windows GUI search. For speedy file searches just use

      dir /a /s /b \name_of_file
      Trust me, it's much faster.
    75. Re:God no... by MenTaLguY · · Score: 1

      Ah, excellent. The last time I did serious (GUI) Windows programming was in the flaky Win95 (OSR1) era, where GDI resources weren't always freed in my experience ... (and obviously they never were on Win16). On early Win95 it may have been that there was still a lot of 16 bit stuff going on behind the scenes; I'm not sure.

      I did think you were complaining that memory was being leaked after a crash, though ...

      Ignore me then, I guess.

      --

      DNA just wants to be free...
    76. Re:God no... by dasmegabyte · · Score: 1

      Spoony baby, how many das Megabytes do you think there are?

      (the answer, believe it or not, is three, at least when I was in college. since then I think the other two have chosen different nicknames, due to me being such a karma whore and because i bought dasmegabyte.org).

      --
      Hey freaks: now you're ju
    77. Re:God no... by greppling · · Score: 1
      I hate to tell you this but it actually sort of does this already.

      According to Andrew Morton, it does not. I don't find the link ATM, but it is easy to verify that it does not: Just do dd if=/dev/zero of=x, stop it when the file has a size of a gigabyte, and compare free swap before and after. There was no change for me at all. The trick is that kernel has a "touched only once"-logic. When this is the case for a file, the kernel decides it is unlikely the file will be accessed a second time, and thus prefers throwing it out of the cache instead of swapping something else out.

    78. Re:God no... by Anonymous Coward · · Score: 0
      It hasn't crashed since I dumped nVidia's crappy 53.03 drivers about 70 days ago.

      What exactly was wrong with them? I don't remember any driver problems back then.

    79. Re:God no... by Foolhardy · · Score: 1

      I don't know exactly but I had 2 blue screens connected to the video driver (not SO bad) while playing GTA3:VC and Unreal2 using 53.03; they are gone now with 56.64. I have a GeForce 3 Ti200. My brother has a FX5600 and some instability and black screen issues with 53.03 that are gone in 56.64. As an added bonus, application profiles are quite useful.

    80. Re:God no... by Foolhardy · · Score: 1

      Win9x... I guess I wouldn't be suprised if there were possible leaks there. I was thinking of WinNT. Yeah, there is a lot of 16 bit stuff from 3.x in 95. IIRC, kernel mode in 9x is 16 bit too. They even have a global resource pool for GDI and USER objects shared across all processes. In a 9x, open help->about in something and check 'system resources'; this is a global value. Still, I think there is some effort in tracking them. NT completely re-wrote all that stuff (all 32bit too) with a better design.

      See
      Windows 95/98/Me Limitations
      Window classes in win32
      Explination of system resources in Windows 95/98 (although they fail to mention the 10k USER and GDI handle quota per process in NT)

    81. Re:God no... by Wolfrider · · Score: 1

      --Seriously, if your web browser is taking 2 minutes to swap...

      1. Invest in an ATA/133 card, and an 80-pin IDE cable
      1a. Get a drive with DMA

      2. ' hdparm -c1 -d1 -u1 /dev/hdX '

      3. Switch browsers!
      :b

      --
      .
      == WolfriderV6 == I'm willing to admit that *I just might* be wrong... Are you??
    82. Re:God no... by Anonymous Coward · · Score: 0

      1. The word "I" (when it means "me", as opposed to, say, a variable named "i") is always capitalized in English.
      2. The first word in any English sentence is always capitalized.

    83. Re:God no... by Hast · · Score: 1

      To me it seems like your initial instruction was about changing the size of the page file. That's not the same thing as changing the swappiness.

      And personally I'd actually have to say that I find it easier to browse the /proc filesystem (since it's a FS you can use search and such just like normal) and then use "man" to find out what the things do. I bet you can find a lot of good guides too. But I don't think "tweak" is a good term to use when searching for Linux tips. It seems to be a term more frequently used with Windows. Finding a programs settings file is typically as easy as reading the man file (file references at the end) or doing "locate" for the program name.

      That said, I think that basic tuning (ie swap size) is easier on Windows. But I think that more complex stuff (going through /proc or registry) is a bit easier on Linux. The reason being that on Linux it's actually designed so that you can use /proc and similar. (It has man pages to back it up.) On Windows you are pretty much forced to rely on searching online for hints of what the parameters do.

      That said I don't really like the registry so I'm certainly not unbiased on the issue.

    84. Re:God no... by Anonymous Coward · · Score: 0

      Ironic that user petabyte only has 256MB RAM.

    85. Re:God no... by Anonymous Coward · · Score: 0

      not true. gdi (and others) kept in shared pool. not owned by a process. win95 did not change this (but did create separate address spaces for private memory).

    86. Re:God no... by Anonymous Coward · · Score: 0

      here you go...

      http://www.google.com/search?q=linux+vm+tuning&s ou rceid=mozilla-search&start=0&start=0&ie=utf-8&oe=u tf-8

      not so hard, is it?

    87. Re:God no... by Progman3K · · Score: 1

      >yet if I copy a 2GB file from one drive to another, the stupid operating system will swap out all the applications it can just to make the cache larger.

      Then I would propose that when the OS does a filesystem-to-filesystem copy like that, especially if the source image is read-only, it should not be cached.

      --
      I don't know the meaning of the word 'don't' - J
  3. How fast is swapping really these days? by jaf · · Score: 2

    Memory access vs. disk access I mean?

    Back when P90s were the norm, was RAM access about as fast as disk access is today?

    --
    -- jaf
    1. Re:How fast is swapping really these days? by Moderation+abuser · · Score: 5, Informative

      Well, disk access speed, say 5ms. RAM access speed 10ns so RAM is approx half a million times faster than disk.

      --
      Government of the people, by corporate executives, for corporate profits.
    2. Re:How fast is swapping really these days? by Anonymous Coward · · Score: 0

      you are talking latency not bandwidth, there is a huge difference.

    3. Re:How fast is swapping really these days? by Anonymous Coward · · Score: 0

      > Back when P90s were the norm, was RAM access about as fast as disk access is today?

      No.

      Any other [stupid (*)] question ?

      (*) because reading from disk imposes to wait for a physical event (the head passing over the data), which can take *dozen*of*milliseconds* to read even one byte while a 1908's 4.77 MHz could already obviously blow that score away by several orders of magnitudes.

    4. Re:How fast is swapping really these days? by julesh · · Score: 4, Insightful

      True, but in most real applications the latency of the disk is the real cost of using the system -- you don't tend to do sustained transfers from swap to CPU. Most memory accesses use a small amount from a single page and then skip to using another. Modern programs tend to have very bad locality of reference.

    5. Re:How fast is swapping really these days? by drinkypoo · · Score: 2, Informative

      Hard drives have seek time and maximum bandwidth. Memory has latency and maximum bandwidth. PC100 SDRAM (for example) has about 10ns latency. As you say, hard drives have much longer seek times than SDRAM has latency; usually between 9 and 20 ms. Hard drives typically transfer between 10 and 30 MB/sec; PC100 SDRAM which is 64 bits (8 bytes) wide has 100 MHz x 8 Bytes = 800 MB/s transfer (peak theoretical.) According to SiSoftware Sandra 2004 Pro, a Via KT133 chipset machine with a fairly fast AMD processor develops 760MB/sec peak transfer. (For comparison, my Athlon XP 2500+ system with dual channel DDR333 and a bunch of crap running in the background cranks out 2309 MB/s on top of whatever memory access is already occurring. It uses an nForce2 chipset.)

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    6. Re:How fast is swapping really these days? by Anonymous Coward · · Score: 0

      I haven't looked at the VM code lately, but I really doubt that the page is read direclty from disk into the CPU register (it just won't fit). As to the locality of reference comment, do you ahve any articles, etc. to back up that statement. It seems strange that the size of the L1 and L2 chache would make such a big difference in performance if what you are saying is true.

    7. Re:How fast is swapping really these days? by happyfrogcow · · Score: 2, Informative

      Locality of reference... that's why we should all be using profiling tools. I'd like to take this opportunity to promote Valgrind. Ddon't fear the kde URL, it runs in text mode and the requirements page has no mention of kde libs or even X Windows.

      It has awesome memory checking, cache profiling and heap profiling.

      I'm just a satisfied user, i have no relationship with the Valgrind developers.

    8. Re:How fast is swapping really these days? by Anonymous Coward · · Score: 0

      Right, but when you're talking about a difference on the order of magnitude of 10^4 in disk vs. memory speeds, the little extra time that it takes to read it to memory and then to the processor doesn't matter. The point is just that disk is slower, a lot slower. Whether it's 500,000 times slower than RAM or 500,100 times slower than RAM isn't really significant.

    9. Re:How fast is swapping really these days? by fish_in_the_c · · Score: 1

      disk access and ram access have always and will always be orders of magnitude apart from one another. milliseconds vs nanoseconds. see : http://www.buycomputermemory.com/measuring-ram-spe ed.html for more info on memory speed. and http://www.storagereview.com/guide2000/ref/hdd/per f/perf/spec/posAccess.html really the reason we use disks is because they are a cheaper yet slower memory for the computer. There have from time to time been systems built with memories that don't erase when the power goes down. If disks were as fast as chips .. why use chips at all.

      --
      âoeTolerance applies only to persons, but never to truth. Intolerance applies only to truth, but never to persons.
    10. Re:How fast is swapping really these days? by Anonymous Coward · · Score: 0

      thanks for the grounding perspective.....

      i thought things were too good these days..

    11. Re:How fast is swapping really these days? by 0x0d0a · · Score: 2, Interesting

      And I'd like to point out that valgrind has patent-related legal problems which has (frusteratingly) kept Red Hat from including it in their distribution.

    12. Re:How fast is swapping really these days? by happyfrogcow · · Score: 1

      That's interesting... I searched around and all I found were more references that say "valgrind is a virtual mine field of patent issues" or something along those lines. However I have not seen anything about what patents are being infrindged and in what part of valgrind.

  4. This reminds me of an old convo I had ... by DikSeaCup · · Score: 5, Interesting
    I had this conversation with a fellow sysadmin, about the time that RAM was fairly cheap and we had a budget.

    She had just procured a new Sun machine with 2 GB of RAM. Mind you, disk space hadn't grown all that significantly and you could still get machines with 9 GB drives.

    The original practice was to make swap 2xRAM. So when the student she had putting the machine came to her and said, "What do I make swap?" she responded "Twice the RAM."

    He said, "Are you sure? That's like almost half the boot drive."

    She thought about it for a second and said, "Oh, yeah. I guess just make it the same as the RAM."

    So this begs the questions: What do you make your swap now? When does your rule of thumb change? And remember when you could run a "fast" linux box on a P100 with 64MB of RAM and 128MB of swap?

    1. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      What do you make your swap now?

      10x the ram, actually, though on linux each swap partition can only be 2GByte, I think.

    2. Re:This reminds me of an old convo I had ... by Mwongozi · · Score: 0, Offtopic

      So this begs the questions

      No it doesn't.

    3. Re:This reminds me of an old convo I had ... by B5_geek · · Score: 1

      I have 1.5Gb of ram in my main box, and I set my swap sixe to 2Gb on all my drives. (hard limit so it won't grow)

      I then run a defrag program that moves the swap file to the inner tracks of the HD's.

      --
      "The price good men pay for indifference to public affairs is to be ruled by evil men." ~Plato (427-347 BC)
    4. Re:This reminds me of an old convo I had ... by cexshun · · Score: 1

      My normal practice is more of solid values. If ram =512 then swap =128. I only have 512MB DDR in my linux box with 128MB of swap. The ONLY time I get into swap space is when I run winex games. And my swap has still never gone above 60% full. Although with the new info from this article, I'm going to mess with my swappiness file and see what benefit tuning can give me. Although just having units from 0 to 100 are kinda vague values. I think the 2x ram rule is completely outdated.

    5. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0
      No it doesn't.

      Yes it does.

    6. Re:This reminds me of an old convo I had ... by troon · · Score: 1

      And remember when you could run a "fast" linux box on a P100 with 64MB of RAM and 128MB of swap?

      Hey - that's my web server you're talking about! Admittedly it has a gargantuan 96MB now, albeit with only 80MB of (RAID-1) swap, but it also does lots of other jobs.

      --
      Ydco co ,df C erb-y go. a Ekrpat t.fxrapev
    7. Re:This reminds me of an old convo I had ... by drinkypoo · · Score: 4, Interesting
      The reason the original practice in Sun shops was to have swap be twice the RAM is that SunOS4 swaps real ram to swap space on a 1:1 basis such that the first n bytes (where n is the number of bytes of physical memory) correspond to the first n bytes of the swap file.

      When SunOS5 rolled around, this was no longer necessary, and your swap is additive, so you only need as much swap as, well, you actually need.

      On my linux firewall system with 256MB real RAM, I have 512MB swap space. On my Windows system with 1GB real RAM, I have 768MB of swap space. This number is actually a hold-over from when I only had 512MB of RAM, I could probably decrease it to just about nothing now.

      Amusingly enough my system has ~480MB of real RAM free, and is using 701MB of my paging file. Go windows! Like I need 480MB free all the time. Still, it is nice not to have to swap something out if I start a big application - but Windows is awful about returning from swap.

      Some other more or less useless data points: My Indy (running gentoo) with 128MB has 256MB swap, which has been enough. I probably could have gotten away with 128MB but believe it or not my primary concern is whether I'll be able to compile some of the biggest C++ programs without the larger amount of swap. Certainly 128MB will not do it, even when you are booted from the gentoo installer CD and there's nothing much running.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    8. Re:This reminds me of an old convo I had ... by 13Echo · · Score: 5, Interesting

      I don't normally make my swaps more than 512 MB on my Linux machines. In fact, when I had 1204 MB of RAM on my last machine, it only ever touched the swap once (when I was compiling Mozilla). The machine was so responsive with 1024 MB of RAM, it virtually never needed to use the swap with that much RAM.

      Now that I have a newer machine, and RAM prices have increased (had to replace SDRAM with DDR), I only have 512 MB in my home machine. It seems to be nearly as responsive, practically never needing to touch the swap. I've only ever seen it use a few MB of the swapfile. When partitioning my Linux drives, I almost always have more than one drive in the machine. HDA1 normally gets the root partition. HDB1 is normally my swap, at the front 512 MB of the drive, followed by home on HDB2. This system makes everything snappy.

      Even on my work machine, which is only a p3 450 with 256 MB of RAM, things operate quite well under Gnome 2. I have two drives in that machine as well, and the swap is on a seperate drive from the root partition. Programs can load from one drive while simultaneously swapping (if necessary) to a second drive. Even with Gnome 2 running, in addition to my browser and several other apps, only a few KB of space is being used on the swap.

      I can't see most desktop Linux users needing more than 512 MB of swapfile space, assuming that they have at least 256 MB of RAM. The general rule of thumb, though, is to put the swap partition at the front of the drive for the best performance, in the event that it does need to get used.

      I've really been impressed with Linux's memory management, even in the 2.2/2.4 series kernels. I've heard that 2.6 even makes some improvements as well. When I used Windows 2000, on the other hand, it INSISTED on using the swap even with a gig of RAM, even after I tweaked it for the best performance. I even used a RAID0 array, and Linux is still faster and more efficient at managing memory WITHOUT the RAID array. I was surprised that the array wasn't even really needed on Linux for fantastic disk access speeds with my 3 year old 7200 RPM drives.

      Of course, the rules will be different for server application. More swap is probably a necessary thing. It's possible, however, that users of Linux (on the desktop) may not even need a swapfile with more than 512 MB of RAM.

    9. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      My thumb rule is:

      create a swap partition which can hold at least the systems memory + some kernel space

      simply spoken: If the system ever crashes you can be sure there is enough swap to create a core file including the whole system memory's content.
      My last Ultra's never crashed...

    10. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      Yes it does

      No it doesn't

    11. Re:This reminds me of an old convo I had ... by tootlemonde · · Score: 0, Offtopic

      Yes it does.

      Nope. Still doesn't

      The article cited says: Many people unaware of the technical meaning of "to beg the question" in logic use it in one of two looser senses.

      Stated in one of the two looser senses, this statement begs the question of why people who are unaware of the technical meaning would use an odd phrase like "beg the question".

      In idiomatic English, one would say "raises the question" and avoid the implication of ignorance masquerading as erudition.

    12. Re:This reminds me of an old convo I had ... by Jon_E · · Score: 1

      use dumpadm (S8 and higher) to point system core somewhere else - for most well-written apps you shouldn't need much swap at all.

      Funny though - I've worked on SunOS and Linux since the early 90's - and comparing Linux/x86 to Solaris/sparc to me is often like comparing Harry Potter to Tolkein - at least it's a similar genre .. there's a reason why Solaris still holds more market share in the enterprise than AIX and HPUX combined

      --
      "the primary stupidity is that of arrogance"

    13. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      Read the whole thing, dude: The second, "to invite the obvious question, (with an inanimate subject) to raise the question", is now the most commonly heard use of the phrase, although we have found no mention of it prior to The Oxford Guide to English Usage, 1st edition (1983), and it is not yet in most dictionaries.

    14. Re:This reminds me of an old convo I had ... by supabeast! · · Score: 2, Interesting

      In the last two years I have had a lot of conversations about this with people, mostly because I often run Sun boxes with > 4GB of RAM. I have heard a lot of varying opinions ranging from 1.5x RAM to just don't bother with swap if you have a lot of RAM. I usually just deal with it by dedicating an entire 36 gig disk to swap in servers and use a much smaller swap partition on workstations.

    15. Re:This reminds me of an old convo I had ... by IceFox · · Score: 1

      Some other more or less useless data points: My Indy (running gentoo) with 128MB has 256MB swap, which has been enough. I probably could have gotten away with 128MB but believe it or not my primary concern is whether I'll be able to compile some of the biggest C++ programs without the larger amount of swap. Certainly 128MB will not do it, even when you are booted from the gentoo installer CD and there's nothing much running. Just an interesting tidbit here. Using knoppixDistcc on a box it rarely goes above 64MB so you should be fine with 128 if you used it in such a way (distcc on that box). -Benjamin Meyer

      --
      Do you changes clothes while making the "chee-chee-cha-cha-choh" transformation sound?
    16. Re:This reminds me of an old convo I had ... by drinkypoo · · Score: 1
      I have a vm(ware) with gentoo in it which I use for testing of stuff I am afraid might summon satan all over my system, and I use it for distcc. It has 256MB real plus 256MB swap, since I use it for other purposes.

      I am planning to add more Indys to my stack and cluster 'em. A friend of mine has some R4600PC indys he's not using, and plans to give me a few of 'em, soon as I make a four hour drive to go pick them up.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    17. Re:This reminds me of an old convo I had ... by hackstraw · · Score: 1
      I've _never_ gone with the swapsize = 2x RAM methodology. If you need that much memory, then buy it. I've admined systems that were databases (oracle and mysql), web servers, web proxy servers, file servers, email servers, etc. Swap on servers is good. Daemons that are resident for the whole time the machine is up offten have "dead" code in them like initialization code and whatnot, and this dead code gets paged out. Also, having a bunch of swap on a machine can actually kinda DOS the box if some app has a nasty memory leak. In that case its OK for the bad app just to get slapped with an OOM (out of memory).

      In my experience, paging swap in and out on a workstation sucks. Back when I had a p100 with less than 128megs of ram, I would come into work every morning and unlock the screensaver and wait for all of the apps to come out of swap and into memory. It took a while, and was kinda amusing. It was as if the computer was waking up in the morning, taking a stretch, and getting ready for the day.

      Also, swapping on a scsi disk is much different than swapping on an ide disk. scsi disks have much less interrupt overhead than ide, and you definitely feel it less on a scsi system. Also, linux is pretty cool about allowing you to have swap partitions on multiple drives, and you can set up your fstab to adjust the priority between them. By setting them the same, you can load balance the swapping between the disks. Dunno if other systems have a feature like this.

      And remember when you could run a "fast" linux box on a P100 with 64MB of RAM and 128MB of swap?

      Actually here is the top of top from my email machine:
      10:27am up 184 days, 23:47, 1 user, load average: 0.00, 0.00, 0.00
      36 processes: 35 sleeping, 1 running, 0 zombie, 0 stopped
      CPU states: 0.5% user, 0.7% system, 0.0% nice, 98.6% idle
      Mem: 62984K av, 54400K used, 8584K free, 9248K shrd, 3628K buff
      Swap: 197528K av, 7224K used, 190304K free 38144K cached
      Its a p200. The low uptime is due to flakey power.
    18. Re:This reminds me of an old convo I had ... by prefect42 · · Score: 1

      But in fairness, what guarantees can you have that it will be that app that gets the OOM?

      --

      jh

    19. Re:This reminds me of an old convo I had ... by nolife · · Score: 1

      No links but a headless P100/64MB ram and two old as dirt Seagate SCSI drives is my Squid/DNS/DHCP/syslog/various crons and polling box for my home network.

      --
      Bad boys rape our young girls but Violet gives willingly.
    20. Re:This reminds me of an old convo I had ... by Vann_v2 · · Score: 2, Funny

      English has been doing fine for a while now without you defending her. Go home, eat a sandwich, and let English take care of herself. Thanks.

    21. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      I have 1.5Gb of ram in my main box, and I set my swap sixe to 2Gb on all my drives. (hard limit so it won't grow)

      Watch your capitalization... that should be 1.5GB. A small "b" means bits, a big "B" means bytes. A bit of a difference...

      - Cowering anonymously

    22. Re:This reminds me of an old convo I had ... by Chaostrophy · · Score: 1

      Just remeber that swap is also /tmp on a sun box.

      Anyone know a reason not to do this on Linux? Always seemed like a good idea to have /tmp on a pageable ram disk (thus on a file system that does not need to care about recovery).

      --
      Plato seems wrong to me today
    23. Re:This reminds me of an old convo I had ... by tootlemonde · · Score: 1

      The second, "to invite the obvious question, (with an inanimate subject) to raise the question", is now the most commonly heard use of the phrase

      First, common use does not equal correct use.

      Second, it is common because it is an example of a common tendency to use technical terms in common speech to sound more knowledgeable than one actually is.

      Third, because there are two common misuses of the phrase ("to evade the question, to duck the issue" and the one cited above), no one can be sure in which sense the phrase is being used.

      Fourth, no one who knew the meaning of the phrase in its original, technical sense would use it in either of the two common ways.

    24. Re:This reminds me of an old convo I had ... by drinkypoo · · Score: 2, Insightful

      Linux does (can) do this: see tmpfs.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    25. Re:This reminds me of an old convo I had ... by u38cg · · Score: 1

      I've got 256MB, and I usually don't run more anything more demanding than XMMS and Mozilla side-by-side; I never touch swap. The only thing that ever hits swap is OpenOffice; after leaving it overnight, getting OOo back into main memory is like the Blackboard Nails Symphony (extended version).

      --
      [FUCK BETA]
    26. Re:This reminds me of an old convo I had ... by aminorex · · Score: 1

      The rules of thumb are constantly changing. The
      biggest reason for that is that the latency of disk
      access (relative to the latency of memory access)
      keeps increasing. Disks used to be able to keep up
      with CPUs, so to speak. Swapping to disk was once
      a principal motivator for virtual memory. Now the
      principal motivator is the limitations of 32 bit
      addressing, with separate protection domains a close
      second.

      Swapping/paging are obsolete.

      --
      -I like my women like I like my tea: green-
    27. Re:This reminds me of an old convo I had ... by TheLink · · Score: 5, Interesting

      Well, here's my thoughts on swap.

      First you should worry about how your O/S does "memory overcommit".

      Many O/Ses overcommit mem. How they handle the case when it turns out there really isn't any mem left (including swap) is what you'd want to know. Some O/Ses (and versions of O/S) effectively kill -9 random processes till there's enough RAM to run. Some applications intentionally allocate large amounts of mem and usually don't every use them. So they usually won't work if you have overcommit turned off (and not enough RAM+swap).

      If you having tons of swap just to avoid your O/S poor handling of mem overcommit, you may end up in a death spiral of swapping. Running processes page by page off your HDD isn't fun to watch (it's so 50s or was that 60s :) ).

      My HDD transfers at max 40-50MB/sec, random seek transfer maybe about 11MB/sec.

      At worst case how long does it take to swap out and swap in the largest process you'd ever have, given the speed of the HDD? Can you wait that long? Can the app wait that long? Will the machine be dead for practical purposes?

      So if you can wait 20 secs, maybe 512MB is ok, assuming the pig process only uses half or so of your swap (plus whatever physical RAM you have).

      But with a small swap, you may run out of mem and hit the memory overcommit scenario.

      I'd still keep swap - just so that when my machine runs out of mem starts slowing down, rather than slamming full speed into a hard wall.

      --
    28. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      NT (& 2K & XP) likes to have 1:1 RAM:PageFile also. You can get away with not doing it, but it is supposedly non-optimal for the memory manager.

    29. Re:This reminds me of an old convo I had ... by SuiteSisterMary · · Score: 1
      In my experience, paging swap in and out on a workstation sucks. Back when I had a p100 with less than 128megs of ram, I would come into work every morning and unlock the screensaver and wait for all of the apps to come out of swap and into memory. It took a while, and was kinda amusing. It was as if the computer was waking up in the morning, taking a stretch, and getting ready for the day.

      Sounds like we need a predictive swap manager. If it notices that every monday-friday at 8:30 the user comes in and it needs to bring the email program, IDE, and so on out of swap, it goes ahead and brings it out of swap. If it notices that you've always got several browser instances running, it makes sure to keep the browser resident, no matter what. And so on.

      --
      Vintage computer games and RPG books available. Email me if you're interested.
    30. Re:This reminds me of an old convo I had ... by Crispy+Critters · · Score: 2, Interesting
      "And remember when you could run a "fast" linux box on a P100 with 64MB of RAM and 128MB of swap?"

      Yes, that would be the day before I "upgraded" from Red Hat Linux 6.2 to RHL 9. (P200 64MB, swap partition on a separate HD) I use fvwm and I don't expect mozilla to be fast, but it really sucks when it takes several seconds to get the menu to pop up on an xterm. I have a pathetic fantasy that I will upgrade to a 2.6 kernel and my system will work as well as it did 5 years ago (and that I will get an X server that supports my video card as well as xfree86 3.3 did).

      Are there any current distros that use the 2.2 kernel?

    31. Re:This reminds me of an old convo I had ... by brer_rabbit · · Score: 1
      When partitioning my Linux drives, I almost always have more than one drive in the machine. HDA1 normally gets the root partition. HDB1 is normally my swap, at the front 512 MB of the drive, followed by home on HDB2. This system makes everything snappy.

      Instead of having a single 512 MB swap, you could try setting up two 256 MB swaps, one on each drive. Provided you give them the same priority, Linux is supposed to automagically use them in a RAID-0 type manner. No RAID tools necessary. For example, here's the swap from my fstab:

      /dev/sda7 none swap sw,pri=1 0 0
      /dev/sdb7 none swap sw,pri=1 0 0
    32. Re:This reminds me of an old convo I had ... by GiMP · · Score: 1

      Hardware or software raid? If software (which I doubt on that hardware), you should use the striping support built into the linux kernel instead by equaling the priorities on the swap partitions.

    33. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      Are there any current distros that use the 2.2 kernel?

      Sure, 2.2 is default kernel on Debian Woody (stable).

      Oh, you said "current"...

    34. Re:This reminds me of an old convo I had ... by Jerf · · Score: 1

      I usually just deal with it by dedicating an entire 36 gig disk to swap in servers and use a much smaller swap partition on workstations.

      You need to ask yourself, is there anything that server does that I'm willing to wait for thirty-six gigabytes of disk space to fill up, rather then just have it throw an "out of memory error" immediately?

      I don't care how fast your drive is, 36GB takes a long time to fill up.

      Lately, with all the RAM we have, I've been seriously toying with a "no-swap" policy. I'm not quite ready to take the plunge at 512MB of ram (dip into swap about once a month on average; gentoo emerge + mozilla + Open Office + a few other things and you do get there eventually), but once I have a gig I think I'm going to stop swapping.

      Why? Because I can not think of a circumstance where I'd rather see the machine bog down for potentially hours, trying to use even a gig of swap, rather then just immediately throw an "out-of-memory" error. Nowadays, if the computer is reaching for that much swap it's most likely an errant task in an endless alloc loop anyhow!

      Now, there are exceptions, but I think they are even rarer then most people think. For instance, if you're running a database server, you might need the swap... but again, are there any circumstances where you absolutely need that query to run... but don't mind waiting literally millions of times longer for it to run, probably causing a cascade failure anyhow (as lack of memory impacts more and more queries until the system can't catch up)?

      It's not a popular opinion yet, but I think the era of "swap" is coming to an end, obsoleted by hard drives that are, relatively speaking, thousands of times slower then they used to be (relative to the processor times), and memories thousands of times bigger. The set of situations swap makes sense in is shrinking rapidly, and will soon be gone.

    35. Re:This reminds me of an old convo I had ... by otis+wildflower · · Score: 1

      Just remeber that swap is also /tmp on a sun box.

      Actually, this is horrible.

      Have you ever filled up /tmp on a Sun and had the system crash (or go unresponsive, or lose sshd)?

      When building a server, I typically use swapfiles and create a /tmp filesystem. The convenience of tmpfs is heavily trumped by the remote possibility of a colossal system fuckup by runaway procs, downloads, etc hosing swap.

      (ever wonder why Sun's got /usr/tmp, /var/tmp, etc?)

    36. Re:This reminds me of an old convo I had ... by pyrrhonist · · Score: 1
      Just remeber that swap is also /tmp on a sun box.

      Only if you make it that way. I typically make a partition for it on development machines, because compiles of ACE/TAO typically use up massive amounts of swap space. Just beware that if /tmp is on its own partition, it won't get cleaned up on reboot, so you might want to make a script for this. Likewise, for long running systems, you may want to create a cron job to clean up old files in /tmp once in a while - regardless of where /tmp is.

      --
      Show me on the doll where his noodly appendage touched you.
    37. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      Correct usage IS common usage. Where do you think correct usage comes from? Why do you think languages evolve over time? Hello? Read ANY book on language or linguistics....

    38. Re:This reminds me of an old convo I had ... by 13Echo · · Score: 1

      Now that's a cool trick! Is there a day we don't learn something new on Linux? ;)

    39. Re:This reminds me of an old convo I had ... by tootlemonde · · Score: 1

      Read ANY book on language or linguistics

      Like Fowler's A Dictionary of Modern English Usage or Stunk and White's Elements of Style, for instance? They'll tell you that "ain't", "not never" and other common constructs are ungrammatical and therefore unacceptable.

      As Strunk wrote in the first edition of Elements of Style: "It is an old observation that the best writers sometimes disregard the rules of rhetoric. When they do so, however, the reader will usually find in the sentence some compensating merit, attained at the cost of the violation. Unless he is certain of doing as well, he will probably do best to follow the rules. After he has learned, by their guidance, to write plain English adequate for everyday uses, let him look, for the secrets of style, to the study of the masters of literature."

    40. Re:This reminds me of an old convo I had ... by dmadole · · Score: 1

      there's a reason why Solaris still holds more market share in the enterprise than AIX and HPUX combined

      Say what you will about research firms, I know, but have you seen the March 2004 Garner report that talks about server operating system futures?

      In a March 2004 report, Gartner predicted that, based on current market share trends, the server operating system shakeout would continue and that only three growth operating systems would exist - AIX, Linux and Windows - through 2008 (0.8 probability). Additionally, by year-end 2008, Gartner predicts that AIX will increase market share and approach or pass Solaris as the No. 1 UNIX operating system (0.8 probability).

      Quoted from Linux Journal.

      I work with AIX systems every day and have worked with Solaris plenty, and the reality is that they are pretty much equally capable technically, and IBM's got a better and more stable business plan, and better a hardware technology growth path.

    41. Re:This reminds me of an old convo I had ... by Anonymous Coward · · Score: 0

      There is one difference with Linux and tmpfs, you can have more space on your tmpfs mount than actual ram. The kernel will start using swap once it is out of real memory. This is real useful is you plan to use only a few percent of the mounted capacity except for odd conditions. I have put mush more data than ram onto a tmpfs partition, data had to go to swap and it works fine.

    42. Re:This reminds me of an old convo I had ... by /dev/trash · · Score: 1

      Debian?

    43. Re:This reminds me of an old convo I had ... by Chaostrophy · · Score: 1

      Now why doesn't linux do this by default for /tmp? Or I guess why doesn't a distribution do this? I seem to recal there is some weirdness on boot that you have to work around.

      --
      Plato seems wrong to me today
    44. Re:This reminds me of an old convo I had ... by Chaostrophy · · Score: 1

      On linux, you can cap the size of the tmpfs file system, so that ram+swap-(/tmp max size)= a sane number.

      It is a trade off, but it can really speed some operations up.

      --
      Plato seems wrong to me today
    45. Re:This reminds me of an old convo I had ... by drinkypoo · · Score: 1

      Because even the least consequences of filling up your memory are bad, and the worst consequences of filling up /tmp are usually not very severe.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    46. Re:This reminds me of an old convo I had ... by Hast · · Score: 1

      Knoppix does it, for obvious reasons. I quite like it on machines with lots of memory. (I have one with 1GB, and I've never filled that.)

  5. Problem by FreeLinux · · Score: 4, Interesting

    Personally, I just try to keep my memory usage below the physical memory in my machine, but I guess that's not always possible..."

    No it isn't possible. With today's RAM prices I almost always have more physical RAM than the system requires. But, due to aggressive VM swapping there are still hundreds of megs swapped out to disk when there is no need at all. This means that those applications, when their time does finally come, are slow because they must be retrieved from disk first. It's really annoying sometimes. Yet, even with excess RAM turning off swap is disasterous.

    1. Re:Problem by Trifthen · · Score: 5, Interesting

      No, turning off swap is not disastrous. We've turned it off on our production web server cluster that routinely serves 60Mb sustained traffic. We've turned it off because we have 2GB of ram in these machines, and Linux insisted on preferring buffers and cache over our running applications. Fuck that, we said. With over 1GB Of buffers and cache, we had RAM to spare; bye-bye swap.

      --
      Read: Rabbit Rue - Free serial nove
    2. Re:Problem by Anonymous Coward · · Score: 0

      I run WinXP (Home) on a laptop with 768MB or
      RAM, and Swap turned off. I haven't noticed
      any problems at all, except that some system
      monitoring utilities don't run properly.
      (they just die upon trying to start up).

      FYI: typical list of simultaneously running
      programs: Wordperfect 10, Firefox, explorer,
      Acrobat reader, Winamp, Xearth. (and sometimes
      a long Winrar job, or DivX player with a
      movie I watch when I take a break)

    3. Re:Problem by mcx101 · · Score: 1

      Yet, even with excess RAM turning off swap is disasterous.

      I find that swap partitions in Linux and FreeBSD are just a nuisance once you've got enough RAM for your apps. Swap files are preferable because you can change the size and number of the files after installation. Swap partitions are just wasting valuable space on your HDD.

      I have 1Gb of RAM on my laptop and Linux, FreeBSD, Windows 98 SE and Windows XP all run fine without any swap partitions or files on my quadruple boot.

      The virtual memory algorithms in Linux, *BSD and NT all prefer you to have 1.5 times the virtual memory as you have physical memory. When you have 1Gb of RAM that's a hell of a lot of space to waste, especially in a multiboot situation.

      At any rate it has little affect on the total memory available in practice to Windows 98. I used to play around a lot with DJGPP which is a port of gcc to DOS DPMI (DOS Protected Mode Interface). I worked out that the maximum theoretical amount of memory you could have with such a DPMI memory manager was 512Mb, which some people had reportedly achieved using OS/2's DOS emulator. So I used to think Microsoft were pretty smart to be able to support 1Gb on my laptop on Windows 98 until I saw the BSODs with the "Out of Memory" exceptions when wordpad was running!

      --
      My operat~1 system unders~1 long filena~1 , does yours?
    4. Re:Problem by drinkypoo · · Score: 1

      Turning off swap is only disastrous on windows (and older versions of Unix) which last I checked (I have not checked very recently) would allow you to entirely turn off the paging files, but will not boot if they are not present, whether you have enough memory to contain everything or not.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    5. Re:Problem by Anonymous Coward · · Score: 0

      I'm really wondering what kind of movie you can watch on a break?

    6. Re:Problem by gr8_phk · · Score: 1
      I thought the point was to swap things out when more RAM was needed than available. If big-app is using all the memory and I start something else, big-app goes to disk. Why swap if not needed? That would be like windows programs that load at startup - everything loads at startup so it will be faster when you want to use it, but that causes my startup time to be like 2 minutes...

      Don't swap until it's necessary seems the right thing to do. If IO isn't busy, you could send older data to disk, but you'd need a way to mark the RAM AND DISK both as valid until the RAM changes. If you need more RAM then just invalidate the RAM copy. Does the MMU support this? Sounds like a patentable idea to me....except that I just posted it to /.

    7. Re:Problem by DenniRuz · · Score: 1

      It's possible-- We have Apache 2.0.48 servers running a custom handler and a chunky mod_perl app with 4 Gigs of ram and we never ever swap-- I add a 1 gig swap partition to the systems but as far as I can tell it's never been accessed on any of the systems..

    8. Re:Problem by Chaostrophy · · Score: 1

      That 512MB is an OS/2 limit.

      --
      Plato seems wrong to me today
    9. Re:Problem by mcx101 · · Score: 1

      That 512MB is an OS/2 limit.

      Perhaps so, but it is most certainly the limit you can get from DPMI.

      --
      My operat~1 system unders~1 long filena~1 , does yours?
    10. Re:Problem by YetAnotherDave · · Score: 1

      I've always left swap on server systems, in case of some spike in load that requires paging, but in regular use it's pretty much unused. On my laptop, I never enable swap, cuz the delay of paging stuff from a slow-ass laptop HD is too painful. With 384MB RAM on a system running slackware/xfce, I never need to page anyway...

    11. Re:Problem by Jebediah21 · · Score: 1
      For some reason I messed with mount points and never had my swap enabled. I ran for about a month with 1 GB or RAM and no swap without a problem before even noticing. Think I hit 90 days of uptime before something didn't release my graphics display correctly and I rebooted. Linux is ok without swap... I really can't tell any difference with huge files in the GIMP now that I've enabled swap.

      Here's where it stands currently:
      $ free
      total used free shared buffers cached
      Mem: 1033864 1017300 16564 0 84620 668504
      -/+ buffers/cache: 264176 769688
      Swap: 4899816 64500 4835316
      --

      Everytime you look at porn a devil gets their horns.
  6. Memory by nuggz · · Score: 1

    Personally, I just try to keep my memory usage below the physical memory in my machine, but I guess that's not always possible..."

    No, it isn't really. Unless you don't use your computer.
    In some cases it makes sense to use your physical memory as disk cache rather than for unused applications.
    Swap out that sshd, and give the database server more memory. Swap out that screensaver and email client, give quake more.

  7. 2Gb of RAM, 300Mb of apps running. by Moderation+abuser · · Score: 1

    So, what... I want my apps paged out to disk so that I can wait for them to be loaded back in when I switch over from Mozilla to Open Office?

    --
    Government of the people, by corporate executives, for corporate profits.
    1. Re:2Gb of RAM, 300Mb of apps running. by roror · · Score: 1

      Yes. To avoid a crawling Mozilla or a crawling OO when you are using them.

  8. The big issue by MrIrwin · · Score: 4, Interesting
    The main cuase of memory usage on Linux is the use of many different shared libraries and not bloated apps.

    I think developers could do more at a library level. For example.....dare I suggest using common sub libraries within libraries, that is people like KDE and GTK get thier heads together and say "are thier functions we include in our libraies that could just as well be linked to an underlying library?"

    --

    And if you thought that was boring you obviously havn't read my Journal ;-)

    1. Re:The big issue by turgid · · Score: 2, Informative
      dare I suggest using common sub libraries within libraries, that is people like KDE and GTK get thier heads together and say "are thier functions we include in our libraies that could just as well be linked to an underlying library?"

      Well, you see, KDE is written in C++. GTK is C. C++ stuff does not play well with different version of the same compiler let alone different compilers or even different languages.

      In theory you're only "supposed" to use either GNOME or KDE and therefore only have one set of libraries installed. In practice you often want to use applications from both systems, and end up installing them both.
      The problem is political and religious as well as technical.

    2. Re:The big issue by alex_tibbles · · Score: 3, Informative

      In fact, one big problem is the way that the loader performs relocations on C++ libraries. Google it. It's why KDE apps take a few seconds to load (and used to be even worse). IIRC the main problem is that many objects (function, variable etc.) need to be copied into the address space of each application using it, so that the sharing never happens in practise.

    3. Re:The big issue by IceFox · · Score: 1

      What about Java and Motif and XForms and Qt2 and Qt3 and gtk1 and gtk2 and mono and the dozens of other widget toolkits outthere that all load into ram? What about the SuperSweetNextGen toolkit that everyone will love that is coming out in three years? Get over it. Consolidation will never ever happen. The best that could occur is that they will look and feel the same to the user which although easier then what you suggest will still take a bit of work. On windows and osx they have tons of toolkits, but they all look (close to) the same. This is what Linux needs to do, not bicker about what one is better.

      -Benjamin Meyer

      --
      Do you changes clothes while making the "chee-chee-cha-cha-choh" transformation sound?
    4. Re:The big issue by spitzak · · Score: 1

      Trying to do that is why installing programs is such a nightmare. If there was some mega-library containing all of Gnome it would probably be a lot easier to install those programs. And the code is so cross-linked that everything gets swapped in anyway.

      I would prefer to see much more static linking and larger monolithic shared libraries that don't themselves call much other than libc. Then add checksums to the read-only code pages so Linux can map identical pages to the same memory and swap locations. Fiddle with the static linkers so pages from the same library are much more likely to be identical, and aggressively change things so unused code is not linked (for instance unused C++ virtual functions). I believe this would result in much less memory usage than relying on shared libraries, and get rid of a lot of DLL hell.

    5. Re:The big issue by 10101001+10101001 · · Score: 2, Insightful

      You're right that having duplicate functions in different shared libraries means opposing apps real use of ram is larger than if they both used the same shared library or their shared libraries used a common lower library, but I think you're overlooking another point. Whenever there's a page of a library or a process' code that is going to be swapped out, it can simply be dumped. That means unoften used sections of different shared libraries aren't actually in memory. Also, because the libraries are already on the HD there's no swapout that occurs (though obviously swapin can occur). So the wasted bloat of most libraries matters little. And the often used stuff, which it does take up more ram than if it were unified is still a very miniscule section of ram usage (even at 8MB for qt and 2MB for gtk+ (plus another 1MB for glib and gdk) which cover all gtk+ and qt apps, you're using a amazingly small percentage of any modern system's ram (less than 9% of 128MB); add all the shared libs and you're still not using more than around 32MB which while large provides a massive amount of services for all sorts of apps which would otherwise be much larger). So, unification is good, but it's not nearly the worry that you seem to believe it is.

      --
      Eurohacker European paranoia, gun rights, and h
  9. It doesn't work that way by Pharmboy · · Score: 4, Informative

    Personally, I just try to keep my memory usage below the physical memory in my machine, but I guess that's not always possible..."

    I keep my memory usage much below the total ram on the servers, but in real life, the machine still swaps. This is because even tho the machine NEVER needs more ram than is available at any given time, over a period of days, it will use more than the available ram. It caches out the old data that was used 12 hours ago.

    Unless you reboot every day (as in a client machine) you will use swap on just about any machine. Using swap is not bad. Using swap for a currently running application is not so good. This isn't a bug, its a feature. Reading data from swap after it has been accessed is still faster than reading new data from the drives, especially if its a network drive.

    --
    Tequila: It's not just for breakfast anymore!
    1. Re:It doesn't work that way by endx7 · · Score: 1

      Using swap is not bad.

      No it isn't, but constantly swapping a lot things in and out is, and you'll notice a considerable slow down of your machine.

      And that's when you need to consider buying more ram.

    2. Re:It doesn't work that way by Bensmum · · Score: 1

      Only if you are using an OS that is dumb enough to prefer disk cache to applications (linux 2.4>, windows, etc). Some OS's don't swap out processes to make more disk cache that I don't want or need and provides me with no benefit.

      Using swap is bad, period. Swap is slow. I would rather keep my disk cache at 10MB of recently used stuff and have *all* my programs running in physical memory than have 128MB of disk cache full of crap that will not be accessed again while its still in the cache, and have the apps I am not currently using, but want to switch back to in 5 minutes in swap.

    3. Re:It doesn't work that way by Anonymous Coward · · Score: 0

      This is because even tho the machine NEVER needs more ram than is available at any given time, over a period of days, it will use more than the available ram.

      This is known as a memory leak. If any program gradually uses more and more memory, then chances are something is wrong. There are very few programs that have any reason to maintain large amounts of data in memory for long periods of time.

      I've run swapless with 768MB of RAM for over a year. I've run the system for weeks at a time and during such periods played games and compiled numerous apps (it's a Gentoo system), sometimes simultaneously in fact. I've never had a problem.

    4. Re:It doesn't work that way by Pharmboy · · Score: 1

      This is known as a memory leak.

      No, this is called a server swapping out previously (but not recently) accessed data. If I have 1.5 gigs of ram, and 4 gigs of content, over time, it will read and cache to swap the contents of the website, even tho the server is never *ACTIVELY* using more than 1/3 of the RAM. No leak, no using swap for current apps, just cacheing out the previously read static web content to swap. This is normal and expected. It is also still faster than a fresh read from the disks (although only slightly) as I stated.

      It is totally amazing at the replies received, it appears many do not understand how swapping and caching on a server works at all. It is not the same as a workstation thrashing because it needs more active RAM.

      --
      Tequila: It's not just for breakfast anymore!
  10. What's wrong with many resident pages? by YetAnotherName · · Score: 4, Informative

    You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine...

    Why not? BloatyApp, if it's that bloaty is probably an object oriented program with template instantiation (or is by Micro$oft); these programs are notoriously huge, but also have notoriously poor locality of reference. The user will get better perceived response if you can keep more of BloatyApp resident.

    If there's space in memory, I don't see the point of pre-emptively ejecting as many LRU pages of BloatyApp. (Of course, I haven't RTFA, but this is /. so you're not supposed to!)

    1. Re:What's wrong with many resident pages? by Anonymous Coward · · Score: 0

      (or is by Micro$oft); these programs are notoriously huge

      Well.. You never have used MS Office, right? It loads in a second or less and instantaneously if you used it earlier. Not sure about bloat, but it is faster and quicker than _ANY_ other office program for Linux.

    2. Re:What's wrong with many resident pages? by Anonymous Coward · · Score: 0

      ... because most of it is loaded on boot time of windows. he..

    3. Re:What's wrong with many resident pages? by Anonymous Coward · · Score: 0

      If you mean shared libraries? Some are, most aren't. Easy to complain, unfortunately.

    4. Re:What's wrong with many resident pages? by mattgreen · · Score: 1

      Ah, nothing like the typical OO FUD that gets moderated up. I assume straight C is the only way to write applications? Have some statistics to back up your claims?

    5. Re:What's wrong with many resident pages? by YetAnotherName · · Score: 1

      Ah, nothing like the typical OO FUD that gets moderated up. I assume straight C is the only way to write applications?

      I sense bitterness.

      Believe me, my goal's not to spread FUD; I do OO for a living, and love it. My producitivty with an object oriented language is more than three times as that with C.

      As for backing up my claims, I'll try to find some papers published during the early 90's that describe the effect.

    6. Re:What's wrong with many resident pages? by mattgreen · · Score: 1

      More like I hate the typical /. meme's that maintain the "I learned C first and it is the only way to write n-tier web apps," that seem to shoot straight up in moderation.

      I can understand the bloat brought on by OO, such as the proliferation of function pointers, increased use of dynamic memory, and of course, the executable image size hit of template instantiation. However in my limited experience I find that an OO-design doesn't have to be bloated or slow...especially not for the abstraction benefits.

  11. Bloaty apps? Are you kidding me? by Trifthen · · Score: 4, Insightful

    Ah yes. It's all the fault of bloaty apps. Apps like database daemons and high-traffic httpd daemons. We've turned swapping off on our servers because we were sick of seeing almost a GB of cache/buffer memory, while it was swapping 500MB of shit to disk. Want a bloaty app? How about the linux Kernel? I love the thing, but Jesus Tapdancing Christ it would rather swap our starting DB process to disk, than free up the fucking buffers and cache. Is there something wrong with wanting it to give precedence to not swapping?

    --
    Read: Rabbit Rue - Free serial nove
  12. Swapless since 1997 by redelm · · Score: 3, Insightful
    Ever since I've had a 32 MB machine (1997), I've not bothered to even set up a swap partition. On the rare occasions when I need swap, I'll create a swapfile. Sure it's slower, but swap is already hugely slow.

    With read-only & demand code-page loading and copy-on-write even bloatware really doesn't eat memory. And bloatware has to be frequently restarted to recover the memory it leaks.

    Sure, there are some jobs that needs swap -- lots of seldom used memory pages.

    But not mine. I prefer to save myself the complexity and performance headaches.

  13. Re:Bloaty apps? Are you kidding me? by Anonymous Coward · · Score: 2, Insightful

    Yeah there is nothing I love more than coming to an idle X console session on box I haven't touched in a while and watching it grind itself into oblivion because everything has been paged out.

  14. VM you say? by freeze128 · · Score: 2, Insightful

    At what point does VM stop meaning Virtual Machine and start meaning Virtual Memory.

    Or is it just the Virtual "M"?

    1. Re:VM you say? by jepaton · · Score: 1

      Computing wouldn't be the same without multiple definitions of the same TLAs (Two Letter Acronym).

    2. Re:VM you say? by julesh · · Score: 1

      VM meant virtual memory a long time before it meant virtual machine.

      Its the change in meaning of UML that I can't get my head around these days...

    3. Re:VM you say? by Kardamon · · Score: 1

      I remember IBM had a system called "VM/VS", meaning "Virtual Memory/Virtual Storage" in the System/370 since the 60s. And DEC's VMS was "Virtual Memory [Operating] System".

      --
      -- Qu'est-ce que la propriété intellectuelle? It is thought control.
    4. Re:VM you say? by diamondsw · · Score: 1

      See, there's this thing called context...

      --
      I don't know what kind of crack I was on, but I suspect it was decaf.
    5. Re:VM you say? by ch-chuck · · Score: 1

      Uh, IBM's VM was Virtual Machine ;)

      --
      try { do() || do_not(); } catch (JediException err) { yoda(err); }
  15. swapoff /dev/hda2 by datastalker · · Score: 1

    Unless I'm using something that is very memory intensive (ie, VMware), I just turn my swap partition off. It allows me the freedom to run Evolution/XMMS/etc. quite quickly when I'm not also using VMware, and still run VMware at a good speed just by turning the swap partition back on when I need it.

  16. they missed one of the biggest points! by whateverdude · · Score: 1

    what about disk corruption? you swap your memory
    to disk, its gets mis-written, and you read it back in and now your memory is corrupted!

    1. Re:they missed one of the biggest points! by cloudmaster · · Score: 2, Insightful

      Disk corruption is handled seperately. If you don't trust your drive controller, then you should spend some time fixing up the disk writing susbsytem. Disk writes should be guaranteed if they say they're succesful, except in the case of a power failure. At that point, swap integrity doesn't matter anyway. :)

    2. Re:they missed one of the biggest points! by Anonymous Coward · · Score: 0

      Well, i have no memory of that happ(%$nning ...

    3. Re:they missed one of the biggest points! by jdunn14 · · Score: 1

      If you have *any* problems with a swap partition corrupting your data it is time for you to replace that disk. Besides one could easily check a checksum on the re-read data. And before anyone panics about the time it takes to checksum the data, you're pulling it off the disk. That's half a million times slower than memory? One more pass over the data in memory is not going to have such a horrible impact. Still, I'd personally say toss the dieing disk. They're cheap now.

    4. Re:they missed one of the biggest points! by 42forty-two42 · · Score: 1

      Don't disk drives do a CRC in hardware automatically? I thought that was how bad sectors were detected and reallocated, by how many reads were needed to get a good CRC.

    5. Re:they missed one of the biggest points! by julesh · · Score: 1

      That's half a million times slower than memory?

      That half million times is only true if you're accessing a single word from the page. It'll come down to about (500,000 / (PAGE_SIZE/MEM_ACCESS_SIZE)), or about 1000 for IA32 processors [*1], if you're accessing the entire page, as you'd need to do to perform a checksum. Still, it is just a drop in the ocean...

      *1 - using 4K pages and 64 bit memory accesses. What size page does Linux use for swapping? larger pages would be more efficient...

    6. Re:they missed one of the biggest points! by Anonymous Coward · · Score: 0

      That's why in a production enviroment you mirror your swap space.

    7. Re:they missed one of the biggest points! by ggeens · · Score: 2, Interesting

      One time, I had a disk corruption in the swap partition. When I booted the machine, everything went well, until I started opening applications. The machine swapped out more and more data, until it reached the first bad sector in the swap. It crashed quite spectacular.

      Once I figured out what happened, I replaced the disk.

      That was in the days of the 2.0 kernel. My machine had 16 MB RAM IIRC.

      --
      WWTTD?
    8. Re:they missed one of the biggest points! by Alioth · · Score: 1

      I had a remote server (running 2.4.x kernel) which started getting disk corruption in swap. Applications would crash and do strange things. I turned off the swap and the problem went away - the machine itself never crashed.

      I used a swapfile instead after that.

    9. Re:they missed one of the biggest points! by Anonymous Coward · · Score: 0

      mkswap -c will find and not use bad blocks.

  17. How much swap? by milgr · · Score: 1

    About 2 years ago I discussed this issue with an OS guru. He was of the mindset that you should always have Swap space = 10xmemory.

    I find that Linux just isn't that good at paging. I never use a significant portion of my 2GB swap partition, and memory contention is still high sometimes. Hmm... Maybe I do need to adjust the swapability number.

    --
    Where law ends, tyranny begins -- William Pitt
  18. Other reasons by Halo1 · · Score: 5, Interesting

    Another reason to gradually and pro-actively swap things out, is that when another program later needs a lot of memory, your system doesn't come to a grinding halt because suddenly a lot of stuff has to be swapped out at once (followed by zeroing all that memory, since you don't want to have one program leaking data to another).

    At least, that's the rationale I've read behind OS X's strategy of swapping things out long before all physical memory is used (and of keeping a pool of zeroed memory pages ready to fulfill most requests). Note that this does not require superfluous swap-ins if your reuse strategy is balanced properly, as the fact that something is swapped out doesn't mean that the memory which contained that data will be cleared/reused immediately (i.e., if it's needed again shortly afterwards, that page can be reactivated without having to go to disk).

    Under most desktop OS'es, programs can even give some hints to the system regarding their usage of a memory region using e.g. the madvise() system call.

    --
    Donate free food here
    1. Re:Other reasons by Just+Some+Guy · · Score: 2, Insightful
      At least, that's the rationale I've read behind OS X's strategy of swapping things out long before all physical memory is used (and of keeping a pool of zeroed memory pages ready to fulfill most requests).

      That's what FreeBSD's been doing for years, and for a long time kernel hackers spoke in awe of the much-vaunted FreeBSD VMM. Now that Linux has implemented a similar strategy, everyone's freaking out like it's some new ego trip that noone's ever tried before.

      The "new" system is what other OSes have been doing for years, and it makes sense. Sometimes it's better to learn why such big changes are made than to gripe on Slashdot that things aren't the way they used to be.

      --
      Dewey, what part of this looks like authorities should be involved?
  19. La, La, La by malia8888 · · Score: 0
    Andrew Morton humorously replied, "I'm gonna stick my fingers in my ears and sing 'la la la' until people tell me 'I set swappiness to zero and it didn't do what I wanted it to do'."

    Gotta love this guy. In articles people usually try to impress you with their brilliance. This man is a kick in the pants! I love Andrew Morton's style.

    --
    Harpo Tunnel Syndrome--my wrist feels funny.
  20. Windows already has this by novakane007 · · Score: 2, Funny

    Under the performance tab you can use the slider to tune the machine for 'foreground' or 'background' apps.

    --

    WURD!!
  21. RTFA - swappiness is tweakable by 42forty-two42 · · Score: 1

    echo 0 > /proc/sys/vm/swappiness

    1. Re:RTFA - swappiness is tweakable by whateverdude · · Score: 1

      isn't that feature only in 2.6 though?

    2. Re:RTFA - swappiness is tweakable by 42forty-two42 · · Score: 1

      I don't know, but 2.6 has been stable enough for me that I don't care :)

    3. Re:RTFA - swappiness is tweakable by Anonymous Coward · · Score: 0
      echo 0 > /proc/sys/vm/swappiness

      /proc/sys/vm/vm_mapped_ratio in 2.4.x

  22. Return of the Sticky Bit by Anonymous Coward · · Score: 2, Interesting
    In the good old days, "chmod +t prog" told the kernel to leave prog in the swap partition even after it had exited. It was a way of making humongous programs like vi :-) more responsive on startup.

    In modern Unices (including Linux) last I heard, the sticky bit is ignored since everything is simply demand paged.

    Could not sticky bit be revived with some similar meaning? As in, "don't be too keen on paging these out?"

  23. Situational advice? by Anonymous Coward · · Score: 0

    So, for standard desktop usage (i.e. XMMS + Mozilla + Vim in KDE), will most users with normal systems (say, 256mb RAM) experience better performance with a swap drive, or with swap deactivated, as some posters here advocate?

  24. Re:Bloaty apps? Are you kidding me? by Moderation+abuser · · Score: 1

    You could always just tune the cache down to bugger all. It's one of the kernel parameters.

    --
    Government of the people, by corporate executives, for corporate profits.
  25. Re:Bloaty apps? Are you kidding me? by Trifthen · · Score: 1

    Which kernel and what parameter? We've tried sysctl settings up the wazzu, but nothing seemed to actually change how it handled swapping.

    --
    Read: Rabbit Rue - Free serial nove
  26. My vote.... by tsmithnj · · Score: 4, Informative

    is to do something like AIX does, where I can use "vmtune" to customize the percentages of memory I devote (hard or soft limit) to filesystem pages or computational pages. This way I can tune for my Bloatware, tune for file copying a la XP, or tune for my DBMS, whatever suits me.... The developers could take it one step further and provide a simple, understandable (as opposed to AIX's) interface for configuration......

  27. Paging vs Swapping by Jon_E · · Score: 1

    We do understand that paging is different than swapping, and that Solaris has changed the memory allocators and algorithms multiple times across releases right?

    That said, you might want to look into a recent Solaris Internals book or course, and also look into the history of things like priority_paging and page coloring ..

  28. Re:Bloaty apps? Are you kidding me? by Anonymous Coward · · Score: 1, Insightful

    /proc/sys/vm/swappiness

  29. Please set up a proper default by dorfsmay · · Score: 0, Redundant

    Unlike say latest versions of AIX where the OS gives higher priority to the cache than to apps, and you have to go deep in the tuning manual to read that the default probably doesn't suit many situation, please adjust maxperm etc...

  30. The amount doesn't matters, it's the stickinness by buserror · · Score: 3, Interesting

    I dont mind the kernel swapping out "old" stuff to grow a huge disk cache. Really, thats OK, it makes things faster for disk hungry processes allright.

    However, what I mind is the fact that the pages that are swapped out STAY there!
    Why not aging the disk cache the same way the RAM pages are aged ? On an idle machine, the disk cache would gradualy decay and be replaced by the pages back from the swap, and the machine would be all responsive again.

    It means that if the user leaves for lunch and a cron wants to eat all the disk, with some luck, when the user gets back, his machine is as responsive as it was when he left.

    I have a laptop with 192Mb of ram, I always hate when 2/3 of the ram is "free" while it takes 10 seconds for the kmail window to move to the front. Even if the machine has been idle for hours.

    I even regularly do a "swapoff -a;swapon" to claim back the cache!

  31. The kernel's page cache is the key... by aksansai · · Score: 5, Insightful
    Many people don't realize how smart modern page caches are designed to speed their system. Linux, MacOS X, Win2K+, etc. all boast aggressive page caches that make loading applications from disk more efficient.

    Without a swap file, the kernel has no place to stick memory segments that are rarely used. They stay in resident memory la-la land until the process is terminated. Those segments add up over time and erode the memory available to the page cache.

    Page caches are wonderful. When you load an application (like Firefox), you're not just getting the web browser. You're firing up a large chain of shared objects/DLLs that support the widgets, I/O, and components of the application. All of these components must be read into memory anyhow for program operation, so the kernel tends to just leave it in there for future use (the page cache).

    When you shutdown Firefox, you're also releasing the necessity of those libraries (provided nothing else is using them). Those libraries also remove themselves from memory. If you load another application (like Thunderbird) that uses the same type of libraries, the kernel will not have to go to disk in order to fetch those libraries. It will instead opt for the page cache contents.

    Turning off the swap file in the historic era of VM infancy was the best way to remove the hard drive bottleneck from system. The operating systems of yester-year did not have good page cache schemes that took advantage of all that unused memory. It is a little different now.

    Applications are so modularized that they are broken up into a billions of smaller libraries so that code can be shared. This increases memory efficiency by keeping a shared library resident for multiple processes. These libraries are frequently accessed, more often than many people realized. Getting THOSE into memory is better than making sure my 500+ Linux applications stay resident.
    $ cat /proc/meminfo
    total: used: free: shared: buffers: cached:
    Mem: 1055653888 1036296192 19357696 0 70488064 892309504
    Swap: 542367744 235892736 306475008
    Notice that on a web server with 1GB of RAM the Linux kernel is still putting things out to swap. These processes that stay asleep for long periods of time do not need to waste the memory that page cache is currently using (892309504 bytes or 753.7MB). What would be stored in that 753.7MB of memory? The database that drives the website (instead of having to seek the disk). The entire web page hierarchy used to display pages on the web site. All the scripts that are used to display dynamic content on the web site (etc. etc.)

    Now, if we subtracted from the page cache the amount of memory that was stored in the swap file, we would have over 200MB less that we could keep cached in memory. That could be an entire database that the kernel would then waste needless CPU cycles to fetch from disk.

    The only advantage to turning off a swap file on these modern machines would be for a machine that runs only a select few applications, and not having a lot of processes in the background doing things.
    --
    Ayup
    1. Re:The kernel's page cache is the key... by CKW · · Score: 2, Interesting

      > Without a swap file, the kernel has no place to
      > stick memory segments that are rarely used.

      Anyone who runs Mozilla on Windows 2000 knows that if you minimize Mozilla for a half day, despite you having 756 MB RAM and not using more than 3-400 MB of it at any given time, bringing Mozilla back to the foreground takes anywhere from 2-6 seconds (depending on the speed of your disk), which is just idiotic on a 2 GHz home machine with that much RAM.

      There is no reason what-so-ever that the OS should be swapping out a userland application when there's tons of RAM. Sure as hell not to make room to disk cache all these freaking multimedia files I'm moving around, I need them in the disk cache like I need a hole in my head. I can put up with a tenth of a second delay in starting to play my mp3, and using disk cache on a 100MB simpsons episode is just dumb. But I refuse to wait for a 30MB process to swap back in.

      I've heard before that "you can NOT turn swap off on Windows 2000", but to hell with it, I think I'll try it when I get home tonight. I've got 756 MB of RAM, if the system crashes when I "hit the wall" so what, I don't think I will hit the wall. Any comments? Will Win2000 let me turn them all to zero min/max size? Anyone tried that before and know what the real actual implications are?

      Hmmm, here's another idea, does anyone have a little FireFox extension whose job is to excercise the browser itself to prevent it from being swapped out?

    2. Re:The kernel's page cache is the key... by Anonymous Coward · · Score: 0

      Exactly. I hope for a system (which would be easier to make once we are 64-bit processor with wide mapping) where there would be no difference between disk and memory, single (file/)memory namespace (with say "named pointers" for files) and NO (thats right) file operations, which means also no save/load on application level. Only intelligent swapping/backing up the memory namespace on the disk.

    3. Re:The kernel's page cache is the key... by doj8 · · Score: 1

      Uh... I don't know that.

      I have 768 MB RAM, a 1.8 GHz Xeon, 7200 rpm IDE H/D. It takes about 1/4 second to come back as far as I can tell. Definitely way less than a second. Don't generalize your problem to everyone - unless you know everyone and have used their systems.

      (At which point you are omniscient, so why are you reading Slashdot - you would already know everything. :-)

      --
      -- Dan Jenkins, Rastech Inc.
    4. Re:The kernel's page cache is the key... by trashme · · Score: 1
      Page caches are wonderful. When you load an application (like Firefox), you're not just getting the web browser. You're firing up a large chain of shared objects/DLLs that support the widgets, I/O, and components of the application. All of these components must be read into memory anyhow for program operation, so the kernel tends to just leave it in there for future use (the page cache).
      That's very useful. Unless you are like me and you launch mozilla once when you log in and just leave it running in its own workspace. I do the same with evolution, and xchat, and gaim, and xmms... A page cache that speeds the launching of applications really doesn't help me. Its more important for me that the applications respond quickly when I go back to using them.
    5. Re:The kernel's page cache is the key... by Gadzinka · · Score: 1

      Only, when you copy several GB of files between partitions, suddenly all your apps are swapped out and you have to wait >10sec to type url into firefox address bar.

      I understand the page-cache, sometimes I even find it great, but it is kind of stupid when VM swaps out working httpd in order to read into the cache some large file. Only to clean the cache seconds later and swap-in the deamon back.

      Robert

      PS I get hit by ``swap all apps out when you copy the couple GB file'' constantly -- I've got 0.5G ram, and reagularly master DVDs.

      --
      Bastard Operator From 193.219.28.162
    6. Re:The kernel's page cache is the key... by Anonymous Coward · · Score: 0

      > There is no reason what-so-ever that the OS should be swapping out a userland application

      Mozilla is swapping itself out, not the OS. There's a hack to work around the issue in newer builds:

      http://bugzilla.mozilla.org/show_bug.cgi?id=7683 1

      From the sound of it, this is a x-platform Mozilla problem, not a Windows OS issue.

    7. Re:The kernel's page cache is the key... by bluefoxlucid · · Score: 1
      That's very useful. Unless you are like me and you launch mozilla once when you log in and just leave it running in its own workspace.

      Actually, because libraries are mmap()ed into ram, the OS doesn't consider them "loaded"; when they get old, they get freed from ram. Of course, the magic of VM is that you can map any virtual page for an application to any physical page; so that ram is freed and unmapped, but when the application needs it again, the data is faulted in from disk and mapped back to that area of ram.

      You might notice that you can't write to shared objects while they're loaded. This is because they never get swapped; when they get old, they get unmapped and freed from ram. The FILE stays mmap()ed, so when the program faults into the library, the data is loaded back from the file. So, shared libraries are part of your disk cache, not your ram usage.

      Keep this in mind while you're cursing the disk cache.

    8. Re:The kernel's page cache is the key... by sydneyfong · · Score: 1

      Did I hear Windows 2000? MS has the habit of doing right things the wrong way. An example of a badly implemented idea does NOT necessarily make the whole idea bad. (mod me down or flame me, but I think the Windows registry is an example of such).

      The grandparent post (and all others supporting the idea) have a point: Why on earth would you need the inactive getty's in memory? The problem of the Windows implementation is that the algorithm that determines which to swap out and which not is flawed. I have a server for testing and misc. purposes, and users (including me) frequently leave their vnc sessions unattended for days -- Moz, GNOME/KDE and all that stuff. I'd be all for removing the cruft from RAM until days later when the user comes back.

      Of course, people like to label things. MS = bad. Windows = crash. Proactive swapping = bad. Registry = bad. etc... But come on, you're using a badly implemented Windows VM system as an argument against a Linux implementation?! IMHO, at least for Linux you can be assured that if the new VM turns out worse than the current one, either it would be kicked out of the main trunk, or you can find an alternate source tree with the old VM. So what's the problem? At least they're willing to try to improve their system for the benefit of all. Experimenting with new things and failing some is inevitable if you want a better system in the long run.

      I thought Slashdotters knew better. I guess I must be new here ;-p

      </rant>

      --
      Don't quote me on this.
    9. Re:The kernel's page cache is the key... by CKW · · Score: 1

      > MS has the habit of doing right things the wrong way

      No argument there, the parent of my post made a general statement and mentioned all modern OSs including Win2K, and I was responding to that, albeit using Windows 2000 as the example.

      I'm very impressed with how Linux avoids using disk cache except where really necessary (and impressed to hear that it's very user/admin configurable), although I haven't used it as a desktop system yet, just a bit of testing once where I had to work hard to force VM usage to go above zero.

      I think 0x0d0a's on to something with the idea of a learning/intelligent/configurable/adaptive VM.

      > Why on earth would you need the inactive getty's in memory?

      I wasn't arguing against all aspects of VM activity these days (as I'm not an architect with specialization in those areas).

      But clearly some current VMs aren't doing a good job in figuring out that it doesn't need to load some mountains of crap in disk caches instead of continuing to hold a user application in RAM, or how to react or behave when a person has loads and loads of RAM and only 300 MB worth of user processes. There are other responses where other people note that even though they only have 300 MB of processes and 768 MB of RAM, they are having user applications swapped to disk.

      The parent to my post stated "smart modern page caches are designed to speed their system. Linux, MacOS X, Win2K+, etc. all boast aggressive page caches that make loading applications from disk more efficient" - and clearly those smart modern page caches are doing the wrong thing in a lot of cases. I don't need 500 MB of RAM used as a disk cache for multimedia files.

  32. What algorithm are they going to use by dorfsmay · · Score: 3, Interesting
    Hopefully they'll use something modern like ARC that tries to keep in cache stuff that have been read at least twice, NOT LRU !!

    AIX uses LRU today, so when you do a backup, the system tries to keep all filesystems in cache (well that what was read last !!), and will happily swap your apps out to disk in order to do so (with default tuning parameter).

    I fondly remember the days when I was running Linux with no swap, none whatsoever...

    1. Re:What algorithm are they going to use by FireHawk77028 · · Score: 1

      The problem with Least Recently Use or LRU, is that the least recently used may be the next to be used. As far as I know, the basis of most the swap algorithms is a random selection followed by a few simple test to guess if the page is going to be used soon. On average "random" performs better than LRU. If you don't believe me, read the algorithm and try some by hand.

    2. Re:What algorithm are they going to use by Anonymous Coward · · Score: 0

      So was I, until I decided to play freeciv.

  33. Dumb Swapping is Computer Abuse by stuffduff · · Score: 5, Interesting
    Programmers have put a lot of time and effort into the VM swapping algorithm; mostly with the intention of being prepared to have a lot of memory ready and waiting for the next thing it will be asked to do. Unfortunately that's not so much of an issue with cheap ram and disk storage and faster and faster front side buses. What we really need is more intelligent swapping, which can only come about when the VM gets a set of API hooks (would make for a great 'shared object') that would enable the system administrator (and maybe someday the end user) to assist an intelligent VM manager to establish priorities and consistently respect those priorities.

    Unfortunately the current crop of best guess VM managers end up denying the end user the experience of their computer's peak performance. Coupled with the horrible state of application bloat, modern 'state of the art' hardware and software combine to give us less and less in terms of overall performance. Software developers throw more code at the cpu to add functionality with little or no concern for performance. And hardware manufacturers add more and more 'special instructions' and 'pipelining' which the majority of software is completely unable to access. If anything it's more like a bunch of dysfunctional co-dependents than an industry that is cogent as to what really needs to be going on. If the folks dealing with processors and the application software could take a page from the gamers (look at the high levels of integration between game engines and video cards) for example, and more effort put into consolidating functionality in dlls and shared libraries; we would be amazed at how truly fast these machines could perform.

    --
    "Can there be a Klein bottle that is an efficient and effective beer pitcher?"
  34. Copy vs Swap? by SpinyNorman · · Score: 1

    I don't know if Linux does this at all, but it seems that one useful VM strategy would be to copy to disk rather than swap to disk. That way you can continue to run bloaty app without swapping it back in, but interactivity is still good since you can resuse memory immediately without needing to swap stuff out at the point the demand occurs. Of course it'd need to be tunable and/or smart (no point copying highly volatile areas of memory for a start).

    1. Re:Copy vs Swap? by xyzzy_jp · · Score: 1

      MVS does this (At least when I last played with it pre-1996). It is called logical swap. Swap out address spaces in the background and only swap them back if there page frames were stolen.

      --
      To err is computer, to really screw things up you need a human.
    2. Re:Copy vs Swap? by xpl_the_myst · · Score: 1
      That's a great idea. It takes care of the case when new applications have to come in and wait for some old ones to get swapped out to disk. This is the ideal compromise for people not interested in disk caches but wanting some free space around in their memory.

      The worst part of /. is, posts like this get little or no discussion. Whereas, someone who just goes ahead to blast Win2K for aggressive disk caching gets +5. AFAIK, Linux is pretty aggressive at disk buffering too. And to posts who think that they should be able to get a Mozilla window back up in a sec after leaving it alone for 3 hours.

      --
      This sig is empty.
    3. Re:Copy vs Swap? by argent · · Score: 1

      This is what Tru64 does, and I believe OS/X and any modern BSD does. Conceptually, it's fairly simple... when you put a block in the free pool, you don't just forget about it... you keep track of where it came from, and then before swapping a block back in you check the free pool to see if it's still there.

  35. Not amused by MrLaminar · · Score: 4, Interesting

    Actually, I haven't been very impressed by the whole swapping thing under Linux lately. I'm running 2.4.22 with a 400MB swapfile.

    Some apps _can_ make the system unresponsive enough to ignore keystrokes, which is *very* annoying. At other times, xmms will stop playing while the disk goes crazy... Switching from emacs to Firefox after 10 minutes usually takes an extra 5 seconds to redraw the window and load all the stuff again.

    Running GNOME2 on this laptop is also quite noisy on the disk. It swaps all the time...

    1. Re:Not amused by Anonymous Coward · · Score: 0

      Just FYI, this article's about 2.6, not 2.4.

    2. Re:Not amused by 0x0d0a · · Score: 1

      2.6 is nicer for desktop use than 2.4.

      It reduces starvation in the name of throughput and application startup time.

    3. Re:Not amused by MrLaminar · · Score: 1

      I still haven't got 2.6.4-ck2 to boot on my Thinkpad with framebuffer and other crucial stuff though, so I'll pass...

    4. Re:Not amused by Anonymous Coward · · Score: 0

      Stop complaining and hack the source of whatever program you absolutely must have in memory and add the following at the very beginning:

      #include ....

      mlockall(MCL_CURRENT | MCL_FUTURE);

      Doing so will tell the O.S. to never swap. This is a POSIX call, so it will work on a variety of operating systems as well.

      Of course the program executing this system call has to run as root or the system call will fail.

  36. Andrew Morton's patches reflect this by bangular · · Score: 1

    You probably want to try Andrew Morton's kernel patches. I've got some servers running his kernel patches and it's nearly impossible to make the damn things swap. Machines with uptimes of 4 months and more, and top shows swap file usage at 0 kilobytes. His kernel patches generally give quite a performence gain. I don't know how they would react under an environment of older machines though.

  37. Swapping on servers vs. Desktops... by Jonny+Royale · · Score: 2, Interesting
    'My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful.

    This point is useful, but only if free RAM is at a premium. For the most part, on servers, there will be sufficient RAM to support the on board applications, and the amount of free RAM remaining will be able to handle the variable load of a standard workday, if the server has been sized properly ahead of time.

    On desktops, however, where the number and type of apps can vary much more widely, the need for free RAM is much higher. However, pushing all apps off to swap space as a default to keep as much RAM as possible free isn't necessarily an effective solution, since the OS will spend much more time performing swap operations that it necessarily should.

    Perhaps a better solution might be an application where certian portions could be swapped off earlier, as they are less used, or not even loaded at all, while maintaining the core of the application in RAM, with "hooks" to the swapped out areas, to let the OS know that swap procedures are required. If the app could tell the os "I probably won't need functions c.d & e, so go ahead and put them in the swap file", it might lead to a good balance of swapping and performance.
  38. Just out of curiosity... by puntloos · · Score: 1

    Am I way off in lala-land if I humbly suggest that perhaps an application-dependent swap strategy should be implemented?
    Perhaps Im describing a 'per application/library swappiness setting'

    So people can specify things like:
    -I want the webbrowsers main components to live in main memory forever, or at least only swapped out if a starting app really really needs it
    -I want 'tar' and any of its data to have less (not 0, less) priority.
    -This app I only run occasionally still has personal priority for me
    -This game (on linux? eh..) has number one priority and is allowed to choose its own swapping desires..

    1. Re:Just out of curiosity... by Anonymous Coward · · Score: 0

      Hmmm... kind of like process priority, but for swapiness, and with more granularity than the old sticky bit? I like it, at least as a user-level concept. You could have a "reswap" command, kind of like the renice command now.

      But it would not be quite as simple as that, when dealing with shared libraries and other shared resources, but I suppose the "swapiness" could be incorporated as a bias to the already-existing scoring systems for each page. Hmmm... on the other hand, I can see situations where that might go pathological because of dependencies you were not aware of (e.g., rarely-used app1 that uses shared library A gets "reswapped" really low, while often-used app2 gets "reswapped" really high, but the effect of app1 drags its swap behaviour down).

      I suppose it is no worse than re-prioritizing processes in sub-optimal ways.

  39. Swappiness vs. buffering by chthon · · Score: 1

    It seems that the original thread was not about swapping in or out, but about the amount of cache that is used by the kernel.

    I just have the same problem. I have 2G RAM, and I run my KDE desktop, some standard server programs and some UML instances.

    When I create UML instances (eg. 8G image) then my memory gets full and is not easily reclaimed.

    I agree with the philosophy of the buffers and the cache, to speed up IO operations for recently accessed files, but I do not agree with the time that they are in memory.

    I do not know if the VM subsystem knows about the three kinds of memory in use, but I think it should, and I also think that it should first of all free up buffers and cache memory before starting to swap out applications.

    For me this just means that if you look at memory usage with any application, that after some time you should see the amount of memory used as filesystem cache gradually decrease over time (ie. when not written to, the system should just mark those pages as free).

  40. Re:Bloaty apps? Are you kidding me? by Just+Some+Guy · · Score: 2, Interesting
    We've turned swapping off on our servers because we were sick of seeing almost a GB of cache/buffer memory, while it was swapping 500MB of shit to disk.

    Your server apparently believed that it was accessing that cache and buffer more often than that half gig of random pages. Do you have real reason to believe that it was wrong, or does that just "seem" bad?

    In other words, do you have actual numbers to demonstrate that your kernel was making poor decisions, or are you only fairly sure that it was?

    --
    Dewey, what part of this looks like authorities should be involved?
  41. OS X's strategy may not be the best by Cysgod · · Score: 1
    dynamic_pager has NO UPPER BOUND on how much disk it will eat. One nice thing about swap partitions is that you can at least set a hard limit. Once you get a certain distance into swap, disk contention ramps up very, very quickly and you wind up disk-bound for all activities and performance suffers badly as a result.

    You can mitigate it with the ulimits to some degree, but it would also be useful to have more fine-grained control of swap usage. "Swapiness" indeed.

    How about max-swap-bytes-per-process or max-cache-demand-swap-bytes?

    I've seen several OS X applications run away into swap in my time. The whole machine is rendered pretty much unusable until it either exhausts the disk or its address space. For interactivities sake, I think it could be suggested that they are not taking the right approach or there is more work to be done and the status quo severely hurts the user experience.

    A separate issue is that OS X does (or at least did in historical versions) bad bad things when it ran out of disk. And dynamic_pager's behavior tended to have the result of eating the whole disk if anything went wrong, leading to even larger problems. Serious bad mojo time.

  42. TLA by Anonymous Coward · · Score: 1, Funny

    No, no, a TLA is a Three Letter Acronym!

  43. Stupid Windows Kernal Swapping by trezor · · Score: 4, Insightful

    Whatever swapping scheme is used in Windows, I do not know, and I don't care what it's called either.

    What I can't despice, is the fact that I got >300MB free physical memory, and 20MB of the kernel is still swapped. Result? Do this, do that (any minor thing) and you have to wait for it to swap in.

    In the end, I have never ever seen a Windows-system without a partially swapped kernel, even with tons of free RAM available.

    This is just plain stupid, or is there some sort of "smart" explanation for this?

    I, for once, would hate having to turn off virtual memory, just to have the system kernel loaded at all times.... And GOD BE DAMNED if Linux takes the stame stupid design-decision.

    --
    Not Buzzword 2.0 compliant. Please speak english.
    1. Re:Stupid Windows Kernal Swapping by The+Spoonman · · Score: 1

      I have never ever seen a Windows-system without a partially swapped kernel

      Read my other comment, do what I wrote and you'll see one each time you sit down at your machine. :) Also, see my follow-up comment to my post about the caveat on 16-bit installers.

      --
      Which is more painful? Going to work or gouging your eye out with a spoon? Find out!
      http://www.workorspoon.com
    2. Re:Stupid Windows Kernal Swapping by Anonymous Coward · · Score: 0

      HKLM/System/CurrentControlSet/Control/Session Manager/Memory Management/DisableExecutivePaging = 1

      Also, the Mozilla long-swap issue has something to do with how Moz manages its resources. See Bugzilla 76831.

    3. Re:Stupid Windows Kernal Swapping by Dun+Malg · · Score: 2, Informative
      In the end, I have never ever seen a Windows-system without a partially swapped kernel, even with tons of free RAM available. This is just plain stupid, or is there some sort of "smart" explanation for this?

      When you have a bunch of lazy, slacker, multi-megabyte services running in the background, waiting for that once-in-a-blue-moon event that requires their help (yes, I'm talking about YOU spoolsv.exe, you 3.98MB hog!), you might as well shove them into the swap file. Windows can end up with an unGODLY amount of oversized crap just sitting aorund waiting for something to happen. Take a look at the "processes" tab on the task manager-- it's insane! I figure the NT kernel is about the same: a bunch of modular pieces, two thirds of which are used maybe once at startup and then paged out. I guess I understand why they did it-- if I had a 57MB kernel image lolling around memory, I'd look for ways to swap out some too.

      --
      If a job's not worth doing, it's not worth doing right.
    4. Re:Stupid Windows Kernal Swapping by mr_jrt · · Score: 2, Informative

      If you have an NT-based system then try this article and see if it helps. Works great for me on XP :)

      --
      Boo.
    5. Re:Stupid Windows Kernal Swapping by ZeekWatson · · Score: 1
      ... (yes, I'm talking about YOU spoolsv.exe, you 3.98MB hog!), you might as well shove them into the swap file.

      Code is never put into the swap file. There is no reason as it already exists in the .EXEcutable image.

      When the program resumes execution, if the code page isn't already in RAM it just reloads it from the .exe (or .dll etc) file. A bit simplified, but the point is that "swapping out" is expensive and there is no reason to swap out code.

    6. Re:Stupid Windows Kernal Swapping by Anonymous Coward · · Score: 0
      When you have a bunch of lazy, slacker, multi-megabyte services running in the background, waiting for that once-in-a-blue-moon event that requires their help (yes, I'm talking about YOU spoolsv.exe, you 3.98MB hog!), you might as well shove them into the swap file.

      So set Print Spooler to manual startup already! That way it only goes into memory when it's needed.

  44. Re:The amount doesn't matters, it's the stickinnes by Just+Some+Guy · · Score: 3, Interesting
    I have a laptop with 192Mb of ram, I always hate when 2/3 of the ram is "free" while it takes 10 seconds for the kmail window to move to the front. Even if the machine has been idle for hours.

    I know what you mean, but in this case, it seems like your machine is making a reasonable guess: you haven't used Kmail in hours, so the odds of you wanting to resume using it at any particular instant is pretty low. On the other hand, reading from a drive is quite a bit faster than writing, so the penalty for incorrectly swapping out old pages when the system is idle is significantly less than incorrectly not swapping out old pages before users launch giant processes that want to allocate a lot of RAM very quickly.

    --
    Dewey, what part of this looks like authorities should be involved?
  45. Swapping back in. by AlecC · · Score: 4, Insightful
    I ffel that there should be some tunable propensity for applications to swap back in. Generally speaking, disk cache is most effective over a pretty short timescale - seconds or a few minutes. It is vey effective with a multi-pass compiler to cache the output of one pass so it can be read in by the next. But this sort of thing has a relatively narrow window.

    So way you want to do is:
    • Apps which haven't been used for a time get swapped out.
    • Cached blocks decay with time, decaying faster if the system idles a lot (presumably the big jobs have stopped), slower if the system is very busy (more likely there is something to re-use cache)
    • As cache blocks decay out, BloatyApp is gradually sucked back in. In Gui Environments, the Window Manager flags the pressure to return as proportional to (say) the number of pixels of visible screen it occupies. Of course, having swapped out once, if it never restarts, you can throw it out second time if you need your cache back.

    So if the guy goes to leaving a big make running, it gradually pushed the big apps out while it runs. But if the big make completes, the apps start crawling slowly back in. If it hasn't finished when he comes back from lunch, he probably wants it to carry on running the make: since the CPU is at 100% load, he is probably not surprised it is sluggish.
    --
    Consciousness is an illusion caused by an excess of self consciousness.
  46. no swap here by BinLadenMyHero · · Score: 2, Interesting

    I have only 256MB of memory in my Linux box, and I use no swap at all.
    I run Mozilla, Gimp, Quake3Arena, etc, without a problem. I use Gkrellm to monitor the system, and I see the memory meter rarely goes above the middle.
    But I don't run KDE nor Gnome, just Fluxbox.

    The old rule of swap size = 2 times memory size is stupid. You just have to consider how much memory the sistem is likely to require at max load, and also how much swap it makes sense to have. For example, it's insane to have 1GB swap on a 128MB machine, cause if it's to use all that swap, sure it will be trashing and slow as hell. Or slower.

  47. Why swapping is _good_ (another article) by chrysalis · · Score: 2, Insightful

    http://00f.net/item/14/
    describe why swapping is _good_.

    --
    {{.sig}}
  48. OS Cludges and hacks. by Anonymous Coward · · Score: 0

    Remember boys and girls, that stuff like virutal memory, swap files and disk caches are workarounds and hacks for limited hardware resources whether it be size contraints or limits on data throughput.

    When these limits no longer apply then it's time to rethink our needs for these hacks and THEY are hacks.

  49. The Law Of Microsoft Windows by tomblackwell · · Score: 1

    The fact that lots of people do something doesn't make it right.

  50. From what I've read by Wedge1212 · · Score: 2, Interesting

    I've heard on a windows box you want to set your max page file size to 1.5x RAM. So if you're running 512MB of RAM you want your page file to be 768. From what i've noticed with linux or what most distros seem to use for defaults is 1x RAM. I notice my linux box hitting the swap file more than my windows system. However the windows box is always using the page file, even under idle situations when its been doing nothing all night. All be it very low. its stil using it. When i switch over to my linux system...no swap is being used until i open up an ap. Is this consistant with what everyone is saying?

    --
    See Sig! See Sig Zig! Zig Sig Zig!!!!!
    1. Re:From what I've read by shaitand · · Score: 1

      hmm I have 512mb of ram on my desktop and unless I open several memory hogs my system doesn't swap period, at all, ever.

    2. Re:From what I've read by Anonymous Coward · · Score: 0

      Albeit!

  51. Re:Bloaty apps? Are you kidding me? by gkelman · · Score: 2, Insightful

    Yeah there is nothing I love more than coming to an idle X console session on box I haven't touched in a while and watching it grind itself into oblivion because everything has been paged out.

    What's wrong with that? The machine shouldn't sit and be ready for every possibility. If you've not logged in in X hours, it shouldn't expect you to suddenly log in. It grinds for a minute or so, and then it's fast again cos it's got what you want to use in RAM. Which is the whole point of swap, stuff you're not using gets paged out.

  52. Re:Get over it by Anonymous Coward · · Score: 0

    Why would it leave it in swap after it exited? It's just as fast to read the program from its usual place on disk as to read it from swap.

    I think I'm right in saying that programs don't get swapped out as such anyway (probably for that reason) and all the gets swapped out is the memory allocated by it, and the sticky bit meant "don't swap out this programs data"

  53. Turning off swap rocks by squarooticus · · Score: 3, Interesting

    Best performance improvement I ever got with the 2.4 series kernels was shutting off swap. My machine immediately became more responsive. From that point forward, I wouldn't come back to the machine after an hour away and encounter a jerky X mouse cursor because the instant I turned off the screensaver the kernel had to page all 128MB of my applications back into the 512MB RAM because it decided buffer cache was more important than code.

    The 2.4 VM changes causing this behavior were awful, and it's too bad that I have to sacrifice a large (disk-based) physical address space, but I'm not going to put up with my applications being paged out when I have 4x as much RAM as code I'm running. Just allowing the system admin to put a limit on the size of the buffer cache would probably solve most of my problems, but instead I have to turn off swap. Too bad.

    --
    [ home ]
  54. Hmph! What's the big deal? by Vee+Schade · · Score: 2, Interesting

    As I write this, my process stack (ps) lists 181 processes and KDE's window list contains 50 entries, many of which are Konqueror and Konsole each with multiple tabs open. Among the "bloatier" apps currently running are OpenOffice, Acroread, VMWare Workstation (though, a VM is not currently running), Tomcat 5/JWSDP 1.3, Umbrello (KDE's UML modeller), jEdit, and 2 database systems (Firebird and IBM U2). This, incidentally, represents a typical "snapshot" of my two workstations (both AMD XP 2200+, w/1GB), at most times. Despite all of this, my current memory usage is 990MB w/ 180MB in buffers/cache, and only 320MB in swap (which is mostly holding my WinXPPro dormant VM!).

    The bottom line: "swapping" got you down? By some more RAM! Prices may be on the rise, but it's still likely cheaper than your time. :-p

    --
    "LinuX - Dropping the c u r t a i n on Windoze." -- Vee Schade, vschade at mindless dot com
  55. Keep two copies by kasperd · · Score: 2, Insightful
    Swapping out data before you need the free RAM would be a great idea if you kept two copies. One copy on disk and one copy in RAM. In fact it would be fine if the system swapped out 90% or more of the process memory this way. There will now be three different cases to think about.
    1. The process needs to read the page - no problem, one copy is in RAM just read it, and keep both copies.
    2. The process needs to write the page - no problem, you can modify the copy in RAM and discard the copy on disk. Notice that discarding the copy on disk doesn't require any disk access, as the list of swap allocations will typically be in RAM (it is much smaller than the swapspace).
    3. You actually need memory - no problem, discard a not recently used RAM page, you still have a copy on disk.
    The only problem is, that you need to make the page readonly, so you can trap the write and discard the on disk copy. In other words don't do this for pages that are frequently changed. But usually you don't have many pages that are frequently changed, and you certainly don't want to swap out those you have. And should you occationally happen to swap out one, it is not really a major problem. It will cost you a pagefault, but no disk I/O. And a pagefault is compared to a disk I/O. A system that behaves like I have described here would use a lot more space than Linux typically does, but still it should be faster. I wonder why this isn't done more often, it is not like the idea hasn't been known for years.

    Another problem that many have noticed, and that isn't easy to deal with, is heavy diskaccess causing the cache to grow and stuff getting swapped out. Yes even some Linux versions suffer from this problem. A Red Hat 9 system I had running for months was really slow in the morning, because all the programs had been swapped out while cron jobs where running during the night. But you never know when it is a good idea to swap the stuff out and when it is not. When the disk access is going on, the process page might not have been used for hours. But still you might want it to be kept in RAM. File pages that have been accessed just once shouldn't be kept in cache for long time. But of course you shouldn't remove them unless the memory was needed for something else. Removing the pages too early is also bad, because you wouldn't notice, that this was really a page that was going to be accessed frequently. Some people are fanatic, and don't want process pages to ever get swapped out to make room for cache. That isn't a good idea either. You can really have process pages that may not be needed even once, do you want such a page to be kept in ram for months just in case? And notice how disabling swap is not going to solve the problem. You still have to think about memory mapped files, that in many ways must be treated like anonymous mappings.
    --

    Do you care about the security of your wireless mouse?
    1. Re:Keep two copies by rabtech · · Score: 1

      This is similar to one of the techniques the NT kernel uses for memory management.

      The memory manager looks for pages that haven't been used recently and writes them out to disk. It then marks them as existing in the "backing store."

      If there is a demand for free pages, those memory pages can be taken immediately.

      If an app comes along and touches those pages again, then they are reclassified as in recent use.

      This is a gross oversimplification, but it gets the point across.

      --
      Natural != (nontoxic || beneficial)
  56. Two copies ARE kept by Anonymous Coward · · Score: 1, Informative

    In fact, this is already done that way since the 2.0 days IIRC (it may be 2.2).
    And also the other way round - if a page is paged in (into ram), it is not immediately deleted from swap, so if that page is NOT MODIFIED it doesn't need paged out again if memory is required.

  57. The answer is . . . "It depends" by kmankmankman2001 · · Score: 4, Interesting

    The universal IT answer of "It depends" applies here as well. Yes, having Mr. Bloaty App glob onto scads of memory that are then not referenced for long periods of time can have a negative impact on other apps if the system becomes memory constrained. And, Yes, if the memory manager swaps a bunch of unreferenced memory out to disk and Mr. User has to wait a long time for Mr. Bloaty App to become responsive because it was his memory that got swapped out, that's a problem, too. The ideal is to be able to address this (haha, bad pun) at the application level and not simply at a global level. This has been the standard on the mainframe (MVS, OS/390, z/OS) operating systems for a long time, where there is a very sophisticated virtual memory manager. If there are, say, a 100 apps and 2 of them are very sensitive to response time, most of them aren't, and 10 are just dead dogs you couldn't care less about how nice is it to be able to actually tell the system that? The 2 "loved ones" then receive preferential storage treatment at the expense of the other, "less loved ones" and the dead dogs are always first on the pecking order of who to steal storage from. The memory manager then is acting to maintain the responsiveness of the applications (the reasons we run OS's in the first place) to meet the needs and expectations of the user(s) (the reasons we run the Apps). Without that ability, arguing over "more swappy" vs. "less swappy" when it's only applied at a global, default, level is not especially productive except within the context of attempting to establish, perhaps, where the best general-use default happy setting is - for the general-use default system we all use (is that you? I know it's not me).

    --
    "The bigger the lie, the more they believe." - Det. Bunk
    1. Re:The answer is . . . "It depends" by Anonymous Coward · · Score: 0

      So, a renice for memory-bound processes.
      Not a bad idea.

  58. Swapping before necessary can be good by ChaosDiscord · · Score: 4, Insightful
    Personally, I just try to keep my memory usage below the physical memory in my machine, but I guess that's not always possible...

    I've seen a number of posts echoing this point, overlooking one of the key reasons for swapping. It's not just because you're out of memeory for applications, it's because sometimes there are better things to be doing with your memory. Mainstream operating systems use otherwise unused memory to cache disk access, dramatically speading things up. If you've got an process that hasn't been run for a a while it may actually be more efficient to swap it to disk. This frees up memory to cache data that may be being hit quite frequently. inetd hasn't been needed for a while? Swap it out so that your disk cache is larger, benefitting your heavily used web server.

    To be fair, when to make that trade off is very tricky and will never work perfectly 100% of the time. Inevitably you'll occasionally be burned by a bad decision. But there are real benefits. The real question is not how to turn it off, the question is how to improve it and perhaps how to allow users to tune it for their needs.

  59. XP paging registry settings by ScrappyLaptop · · Score: 2, Informative
    Most of what you are looking for is here:

    "DisablePagingExecutive"=dword:00000001

    "LargeSystemCache"=dword:00000001

    The combo will keep your kernel in RAM (DisablePagingExecutive)and enforce a minimum reserve (4MB) amount of memory for it (LargeSystemCache), although that amount can grow dynamically. The LargeSystemCache may cause "Delayed Write Failed" errors, if it does, reboot in SafeMode and undo the damage.

    More goodies here, many adjustments that can affect how your sytem divides between swap, cache and currently-running-apps:

    HKLM/System/CurrentControlSet/Control/Session Manager/Memory Management

    "ClearPageFileAtShutdown" "DisablePagingExecutive" "IoPageLockLimit" "LargeSystemCache" "NonPagedPoolQuota" "NonPagedPoolSize" "PagedPoolQuota" "PagedPoolSize" "PagingFiles" "SecondLevelDataCache" "SystemPages" "PhysicalAddressExtension" "WriteWatch"

    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Se ssion Manager\Memory Management\PrefetchParameters

    "VideoInitTime" "AppLaunchMaxNumPages" "AppLaunchMaxNumSections" "AppLaunchTimerPeriod" "BootMaxNumPages" "BootMaxNumSections" "BootTimerPeriod" "MaxNumActiveTraces" "MaxNumSavedTraces" "RootDirPath" "HostingAppList" "EnablePrefetcher"

  60. Your lower bound is easy.. by multipartmixed · · Score: 1

    ..that machine should have at least 2GB swap (same as RAM) for a very simple reason: /var/crash/`hostname`/*.

    When your kernel panics, it [basically] copies memory to your swap partition; on boot, it stuffs it back in /var/crash in a format useful for debugging.

    --

    Do daemons dream of electric sleep()?
  61. A suggestive for intelligent adaptive Linux VM by 0x0d0a · · Score: 1

    I've heard before that "you can NOT turn swap off on Windows 2000", but to hell with it, I think I'll try it when I get home tonight. I've got 756 MB of RAM, if the system crashes when I "hit the wall" so what, I don't think I will hit the wall. Any comments? Will Win2000 let me turn them all to zero min/max size? Anyone tried that before and know what the real actual implications are?

    I've tried this on NT 4. The system gets very pissy about booting, and a lot of stuff doesn't start.

    It *is* an interesting case that many programs are unlikely to be useful in predicting future disk accesses, but that the OS cannot use such data.

    Take updatedb on my system. When updatedb runs, masses of cached directory data chew up memory on my system. This happens once a day. Now, I'm very unlikely to actually use that data -- in general, updatedb is a poor predictor. However, Linux can't figure out that updatedb shouldn't be trusted for prediction.

    It might be an interesting project for an enterprising CS student with an interest in Linux to try producing a "learning" VM system -- logging which program is responsible for each page getting cached in memory, and then determining whether that page is actually used before being replaced. Store such a profile on disk ("/var/vmlog/bin/ls" or something), and you have a bright adaptive VM system.

    Such a system doesn't even have to log all the data, only a randomly selected small percentage, so that it slowly gets smarter.

    Such data would also provide valuable tuning data for folks who might want to tweak the VM subsystem (or, in the case of the end user, determine whether to buy more memory...)

    If you *really* want to get elaborate, you could even learn to use different eviction algorithms with different programs...

  62. Re:Bloaty apps? Are you kidding me? by ttyv0 · · Score: 1

    Would you rather have a user process wait for all pages to be brought into memory, or would you rather
    have your kernel wait until a page is brought into the cache from the disk?

    Kernel preemtiveness can't solve everything. If your system call has to read a page from disk, it might have to wait until the page is brought in from disk. During this time the kernel could be locked.

    Your application, on the other hand, will be put onto wait queue until data is available, allowing other applications to run.

    Of course, it's a known fact that DB people generaly do not like kernel people :) -- primarily because of page caching. All of these nice read aheads are abslutely useless for DB system. But, do not despair! 2.6 kernel has a much improved read ahead algorithm.

  63. Re:God no... Redhat9 / enterprise 3 do that 2 by Anonymous Coward · · Score: 0

    That seems to be EXACTLY the stupid behavior that you see with Redhat 9 and Redhat Enterprise version 3. The disk buffers start taking up a huge chunk of memory and there's no memory left for other things which ought to get it instead (databases, email, etc). It's absolutely infuriating to be trying to tune a redhat9/enterprise3 system's memory usage and have no control over how much is consumed by the disk buffers.

    I don't care how smart you think the OS is about deciding when disk buffers are more important that application memory - there are always going to be times (many of them) when the OS can't make a good decision.

    Reasonable OSes (HP-UX) at least have a way to limit the maximum amount of memory used for disk buffers. It's been in their performance tuning guides for many years now too.

    Redhat 7.2 did NOT have this problem - the same hardware running rh7.2 will never swap whereas it thrashes under rh9 because of the memory given to disk buffers.

    It's amazing it's taking so long for redhat to realize that, and that the problem has made it into redhat enterprise version 3 is really disappointing.

  64. Thou shalt not turn of thy swap partition by Anonymous Coward · · Score: 0

    Once, i turned of the swap space in my computer. (Actually, I forgot to turn it on after some experiments). It did work great. Except in some rare circumstances, when it needed memory so badly. It would then reap the biggest application running, which was always the X server. Morale: just set swapiness to 0, but make sure you have plenty of ram+swapspace.

  65. For me, this issue is moot by WhiteWolf666 · · Score: 1

    I thought---Damn... This is true

    My machine would be SO much more responsive if it didn't swap.

    cat /proc/sys/vm/swappiness
    60

    hmm...lets bump that down to 0
    echo 0 > swappiness

    lets check the swap we are using....
    top
    Swap: 0k total, 0k unused, 0k free

    DoH! My machine botched a software suspend, and my swap is screwed.

    Oh well....Most 'Swapping' is perceptual. Pick a moderate swappiness value, and your system WILL actually be faster. The 1/4 second or so you loose upon bring OpenOffice back from the disk is more than made up for by all the cache you regain.

    IMHO, the only disk 'thrashing' that is annoying has little to do with swap, and much more to do with webbrowser cache to disks, etc. . .

    --
    WhiteWolf666 an exBush supporter. All you new-school,compassionate,save the children Republicans can rot in hell
  66. adaptive algorithms by mugnyte · · Score: 2, Interesting

    Can someone please describe any adaptive algorithms that could be used. Specifically, I'm thinking of:

    - dirty marking unreferenced pages when swaped. if these mem pages are not used after the swap out, no need to swap them in again. i'm prety sure this already occurs

    - for process using high swap demands, increase their weighted priority for pages, with a window-averaged for swaps. so then, my database process could hog under load while my less-used apps may swap because they're used less often. could be taylored differently for code versus data segs.

    - page-impage comparisons to avoid holding duplicate code segment pages in memory. this plays with the concept of shared libs a bit, but could avoid duplicate pages, especially if this information is saved in a precalc'd hash table that is stored.

    just ideas.

  67. Swap vs. disk/file cache by Peaker · · Score: 2, Interesting

    Is a difficult dilemma, but that's because an overly complicated scheme is used.

    There is a simpler and more powerful scheme that unifies swapping and disk caches, while allowing applications to persist between reboots, all with better performance than current systems!

    EROS implements such a system. Generally it is referred to as "Orthogonal persistence", and functionally it behaves as though the computer is "always on", and returns to the exact state it was in after a reboot. The thing is, with orthogonal persistence, the structure on the disk is not a file system, but just the application data.

    Since applications no longer work with the disk explicitly (open/read/write) but only with one type of memory (persistent memory), the OS manages all of the disk I/O, and it allows it to eliminate almost completely the largest delay in disk-work - the seek time in all writes. Since all application memory is just mapped to disk transparently, all RAM is just considered a "disk cache", and the kernel does not have to make nasty tradeoffs between disk caches (of explicit open/read/write calls) and virtual memory.

    Of course there is still a problem if large work-areas of unimportant applications "swap out" smaller areas of important applications. I suggest solving that by prioritizing pages to the memory manager. In a system like *nix it is not a problem. In more secure systems however (EROS, for instance), it may create additional covert channels between applications so it was avoided.

  68. Re:Bloaty apps? Are you kidding me? by Crispy+Critters · · Score: 1

    ~: ls /proc/sys/vm/swappiness
    ls: /proc/sys/vm/swappiness: No such file or directory
    What kernels support this?

  69. Valgrind and software patents by 0x0d0a · · Score: 1

    I don't know the specifics either -- I ran into this when trying to track down why valgrind suddenly wasn't packaged by any of the big third party Fedora RPM packagers.

    If this *does* get resolved so that valgrind can go into Fedora Core 2, I have to say that that would be *awesom*.

  70. What's the default value? by menscher · · Score: 1
    With people recommending 100 for servers, and 0 for desktops, it makes me wonder: what's the default value of this parameter? (I can't check myself because I don't have any 2.6 boxen yet.) Would a slight change help? I really don't get why everyone is taking the all-or-nothing approach.

    Also, someone mentioned an autoswappiness patch. Does that "solve" the issue?

    1. Re:What's the default value? by AlastairMurray · · Score: 0

      Default = 60 (from cat /proc/sys/vm/swappiness)

  71. Swapping out unneeded stuff on bootup by avij · · Score: 2, Interesting

    My approach has been to start all the needed services and then run this small perl script (which I named memhog.pl) to create a process that hogs quite a bit of memory:

    #!/usr/bin/perl -w
    use strict;

    my $a = "xxxxxxxxxx" x (131 *1024*1024);


    This is just a quick hack, you may want to adjust the size to suit your memory size. The server from where this script was copied has 2GB of memory. Essentially I want to page out all the stuff that doesn't get used after starting the server and the related server processes. Of course, given enough time the server would swap out those pages anyway, but this method just does it quicker. After the script has been run, the server will gradually swap in those pages it really needs. OK, doing this may be pointless but I don't care ;)

    --

    Follow your Euro bills at EBT
  72. my swap is already turned off by xpyr · · Score: 1

    I got xp and 1.5 GB of ram and xp works great soon as I turned off the swap file. I was told that "some" apps needed it, bullshit. The only one I can think of is adobe photoshop and it only gives u a slight warning when you run it, then just hit continue and it continues loading. Therefore it doesn't "need" it. Although my ram usage is usually at 700+ megs its fine by me. Now my swap is no longer a bottleneck since I don't got one :) Shows you how much ram windows actually uses. It's cut in half because half of it goes into the swap usually if u have it turned on.

  73. Disable PagingExecutive by MarcQuadra · · Score: 1

    There's a registry key that purports to reduce the swapping of the 'executive' components of the kernel. I think it's in: HKLM/system/control/ccurcset/sessionmanager/memory
    (abbreviated for sanity)

    There will always be SOME of the kernel paged out, because I guess some stuff loads into the kernel at boot and can't be 'jettissoned' I think my w2k box dropped from 32MB/kernel paged to about 20MB after I disabled PagingExecutive.

    It's a good idea for laptops or high memory systems.

    --
    "Sometimes, I think Trent just needs a cup of hot chocolate and a blankie." -Tori Amos on Nine Inch Nails
  74. I use a swapfile, you insensitive clod! by MarcQuadra · · Score: 1

    Well after three years of compulsively staring at top output while I do evil shit to my boxes i've decided to move to swapfiles instead of partitions.

    The MOST swap I've ever tapped was 16M, I run all my boxes with 512MB-or-more RAM, so there's really no need to have a sizeable swap.

    Right now I have three boxes running with 768MB RAM, and each has a 64MB swapfile, and with over a week uptime on all of them I'm using...

    3MB on the file/print server
    0MB on the workstation
    0MB on my friend's machine

    The best part about a swapfile is that the size isn't set in stone, if I want to move up or down I just:

    # swapoff -a
    # dd bs=1m if=/dev/zero of=/swap.img count=
    # mkswap /swap.img
    # swapon -a

    --
    "Sometimes, I think Trent just needs a cup of hot chocolate and a blankie." -Tori Amos on Nine Inch Nails
  75. None by zarr · · Score: 1

    I realize the start of this thread was about server machines, but I'll still talk about my desktops :)

    I use a laptop at home. It has 500MB of ram, runs linux (2.4), kde, opera, eclipse, openoffice. xmms, gaim plus whatever. This box have no swap space. I've been using it for about 6 months and I've never had any problems with too little mem. Of course, after playing OGGs for a couple of hours, whatever memory isn't used by apps are used by cache. I don't see that as a problem. I would have really hated if my apps were swapped out in this situation.

    At work I have a kickass machine with 2GB physical and 4GB swap. It runs mostly the same apps as my home machine pluss some really memory hungry server software (out own product). I can't remember ever having noticed any swap activity. I'm running the ksysguard applet all the time so I have a pretty good idea of its memory usage. My previuos machine was a windows box with with 500MB. It was swapping *all the f***ing time*. Leave eclipse alone for a a couple of minutes, and you had to wait for ages while it copied all 100MB of it back into memory...

    My point is that you don't really need any swap partition at all on a desktop box. "But what if you use it all?", you may ask. "So what?" is my answer. With a swap partition you also have a hard limit on how mush mem you can use. It just get a lot more painful to use it all, with all that swaping. If you have been adviced to have a 1:1 size between your physical mem and swap partition, you might aswell just buy twice the amount of ram, and be a twice as happy geek :)

  76. Depends on what kind of server! by MarcQuadra · · Score: 1

    I have a headless file/print/shell/kerberos/distcc server and it boots all services in under 40MB RAM, it's got 768MB under the hood and uses 40, that leaves a LOT for buffers and cache. I've got no use for swap on it, so I made a token 64MB swapfile (not a partition) and it's almost never been touched.

    Servers often don't need much RAM, adding or disabling swap on my server wouldn't make ANY difference at all.

    --
    "Sometimes, I think Trent just needs a cup of hot chocolate and a blankie." -Tori Amos on Nine Inch Nails
  77. /proc? by shish · · Score: 1
    Why not just put the numbers in /proc (or /sys), and let the user try them out?

    Give a pseudofile for what gets RAM priority (root's apps, disk cache, user apps, whatever else), one for how aggressively to free RAM, how long to wait before a page counts as old, and let people customise.

    --
    I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
  78. Re:Bloaty apps? Are you kidding me? by Anonymous Coward · · Score: 0

    It was added somewhere in 2.5.x

    (this from other /. posts, grain of salt and all)

  79. No swap involved by Handyman · · Score: 2, Informative

    The funny thing about the whole thread is this: it eventually turned out that the guy who originally complained about swapping didn't have any actual swapping going on at all. What is usually happening is that pages from an *executable* are being dropped, and people incorrectly refer to this as "swapping". In Linux, pages from an executable aren't "swapped out" but are simply dropped and read back from the original executable as needed. The trouble is that once you then access some of those pages again -- say, when you're exercising the repaint code from some bloatware app for the first time in a while, because it's been in the background for a while -- they have to be faulted in one by one, and that takes a lot of time per page.

  80. Best of Both World by uslinux.net · · Score: 1

    What seems like it would be a *better* method would be to do both. Keep the running apps in core, but as spare I/O cycles permit, write them out to disk. When you then load a large app, the other app is already swapped out. So long as the swap was very low priority when the system *had* enough RAM, about the only downside would be writing to disk all the time. In fact, you could even prefetch the app back as chunks of memory became available.

  81. Re:why did they publish these photos? by Anonymous Coward · · Score: 0

    Because the soldiers are sold by Bush for the oil companies.

    The soldiers did want $$$ for theirs jobs.

  82. Why Java has this problem. by mcc · · Score: 1

    As far as my understanding goes, the reason Java has this problem is becuase it uses a mark-and-sweep garbage collector. What this means is that every time the garbage collector runs, it has to "touch" every single object in the system-- that is, the way it works is, it basically looks at every single object accessable in the system and marks it as "YEP, STILL ALIVE!". And essentially, any objects that don't have an "alive" marking afterward can be considered inaccessable and therefore reclaimable space. That's just how it works, and this necessarily requires it to access the memory of every object in the Java system, hence entirely reordering whatever your virtual memory/processor cache thought it was doing just previously. There isn't a lot that can be done about this.

    The generational garbage collector used in newer Java virtual machines will probably help with this problem greatly. Generational garbage collectors assume that anything that survives for a couple of collections is probably going to be around for a very long time, so if something survives a collection or two, further collections (unless space REALLY starts getting low) just ignore it and assume it to be still-live without actually checking to see if it is. This can significantly reduce the amount of memory that has to be touched, and so it would probably decrease the number of memory pages the virtual machine needs swapped in on each GC run.

    1. Re:Why Java has this problem. by Progman3K · · Score: 1

      >Java has this problem is becuase it uses a mark-and-sweep garbage collector.

      Yeah, I can see where the former is a problem, which is why I like c++ better; you can structure memory-use any way you want.

      >The generational garbage collector used in newer Java virtual machines will probably help

      Surely, and I wonder if at that point people will start writing their own allocation schemes in Java... I wonder what form that could take.

      All the same, I like Java because it has nice consistency across its types and is well-suited to aiding in the learning of computer science.

      --
      I don't know the meaning of the word 'don't' - J
  83. MOD PARENT UP - informative by 42forty-two42 · · Score: 1

    no text

  84. These guys are on crack... by shaitand · · Score: 2, Insightful

    Sorry but this is not a complex equation and I think these guys are getting wrapped up in too many details and missing the big picture.

    The harddrive is really, really, really, really fscking slow. In comparison Ram is really really really fast. As a result, you want to interact with the hard drive as little as you possibly can, and interact with ram instead as much as you possibly can (the only thing which beats that is interacting with only the cpu registers and avoiding ram and harddrive altogether).

    As is, linux doesn't even begin touching the disk until there is only enough ram left to turn on VM. Now this has a negative impact when that limit is reached because there is overhead turning it on.. this impact is negligable and tweakable since you can wait and see if you hitting the limit, add more memory, see again and reevaluate until you simply aren't swapping. This is a good thing.

    One of the worst things windows does is swap constantly. In fact beyond a certain point (read enough ram to run an XP desktop) the system swaps MORE if you have more ram. You boot the system with all uneeded services turned off and no startup processes and all the eyecandy turned off. And you've got 4gb of ram in the system, guess what, it's already using VM.

    Maybe VM management itself could be tweaked more, but it certainly shouldn't be used unless it absolutely has to (and if you don't have enough ram and it has to all the time then it's not like you suffer that performance hit more than once).

    The only exception to this I've found is a linux desktop running kde or gnome with about 256mb of ram, at that point the numbers seem to work out just about right(or wrong I should say) and the system is constantly turning VM on and off, encountering the performance hit again and again and again, with pretty much every operation you perform.

  85. Gee ... two I/Os to swap, One I/O to reclaim cache by Totally_Lost · · Score: 2, Interesting

    Swapping out any semi-active process, especially an interactive one, is utter foolishness which should be subject to termination grounds (unless of course you work for a big iron computer company that needs to boost revenue by purposefully slowing systems down). Any time you decide to clear memory and page a task out ... you are creating two I/O's ... one out, one back in ... and doing it with shit poor locality since the swap area is probably at the other end of the disk from any other active I/O .... just discarding entries in the file cache only requires a single I/O to recover it. .... so tell me ... who is the idiot that believes two I/O's to kill the performance of an interactive process is better?

  86. Swapped kernel is 16bit, OS/2 and POSIX API suppor by ZeekWatson · · Score: 1
    In the end, I have never ever seen a Windows-system without a partially swapped kernel, even with tons of free RAM available.

    Not a problem actually, that permanantly swapped kernel "Nonpaged" is support for 16 bit APIs, OS/2, POSIX and other stuff that you will never ever use.

    And it isn't really swapped either, as it isn't data. Swapped pages are data only, code pages are overwritten and just paged in again when needed.

  87. Sticky Bit!!! by cgleba · · Score: 3, Interesting

    Here's a solution to the whole debate -- make the sticky bit have meaning under Linux like it does on other UNIXen -- if the sticky bit is set on the execuatble, do not swap it. If it is not set, the executable is free to be swapped. This solves the entire debate (for instance, if you don't want the 'interactive' mozilla process swapped, set the sticky bit on the executable).

    1. Re:Sticky Bit!!! by slimey_limey · · Score: 0

      I always wondered about why we have a sticky bit and don't use it. Especially good for interactive apps, X, etc. Could you use it on, say, files, to prefer keeping them in the disk cache, as well? That would be good in some cases.

  88. swapping and interactivity by nothings · · Score: 2, Interesting
    I think the big problem with swapping is how it interferes with interaction. So the problem is when something gets swapped out (or possibly paged in the first time, if the OS is lazily loading the executable) that's the front-line of interaction. Say, the data needed for showing an infrequently used menu.

    We either need some way of expressing this in code in a way that's exposed to the OS so it can avoid paging it out (and don't say 'well, just lock the pages containing it', think about how GUIs code & data are arranged--i.e. OO), or, perhaps instead of LRU, paging should pay attention to when a page was last used relative to an interaction--if you use some menu to bring up a dialog that triggers a long, memory-intensive process, that menu may have been used longer-ago than stuff happening as a result, but it's going to be used again first--LRU is the wrong model. (Also consider the interactive parts of other apps that you have open windows for.) Maybe it should still get swapped out, but swapped back in when some memory is freed up--'this thing was used very soon after an interaction, so it should be in memory if possible'. I don't know if any OSes attempt to page-in from swap before something is requested. Aren't some processors these days trying to prefetch memory requests based on patterns of memory access (not just prefetching code memory)? Same sort of idea.

    Tuning for interaction isn't new to OSes; the VMS operating system's process scheduler treated 'interactive' apps differently from 'batch' apps (where, if I remember correctly, an app was interactive if it paused for I/O before using up its timeslice). I dunno if Unixen or Windows do things like that.

  89. No "N*RAM" rule is logical. by argent · · Score: 1

    The logical way to allocate swap is to figure out how much virtual memory you need (1GB, 512M, 2G, whatever) then allocate enough swap that SWAP+RAM is at least that big.

    Think of RAM as a cache for swap and you won't go too far wrong. More RAM is better, but if your system is stable with 160M RAM and 320M SWAP there's no point in allocating another 1G of swap when you add a 512M DIMM unless you at the same time increase the workload on the machine.

  90. Swapping by GenomeX · · Score: 1

    I totally agree that users should have more control over how and when things get swapped. For instance a mozilla process tree, I'd be searching stuff on the net, then go back to coding, which can go on for hours, then I quickly need to check something in the mozilla window, and it would be damn slow to reload everything from swap. This is related to swapping stuff that's been idle for x time. The sticky bit idea, or something similar would be nice...