Slashdot Mirror


Why Use Virtual Memory In Modern Systems?

Cyberhwk writes "I have a system with Windows Vista Ultimate (64-bit) installed on it, and it has 4GB of RAM. However when I've been watching system performance, my system seems to divide the work between the physical RAM and the virtual memory, so I have 2GB of data in the virtual memory and another 2GB in the physical memory. Is there a reason why my system should even be using the virtual memory anymore? I would think the computer would run better if it based everything off of RAM instead of virtual memory. Any thoughts on this matter or could you explain why the system is acting this way?"

28 of 983 comments (clear)

  1. You mean physical memory right :-) by alain94040 · · Score: 5, Informative

    You must be confused about virtual vs. physical memory. In modern processors, there is no penalty for using virtual memory, all translation from virtual to physical address space is done internal to the processor and you won't notice the difference.

    So all the physical memory installed in your PC is used by the processor as one big pool of resources. Processes can think whatever they want and address huge memory spaces, that's all in virtual land. Virtual memory only starts impacting performance when pages are being swapped in and out, because all your processes need more resident memory than you actually have.

    Swapping means accessing the disk and freezing the requesting process until its page of memory has arrived from the disk, which takes millions of processor cycles (a lifetime from the processor's point of view). It's not so bad if you swap once, as the processor can work on other processes while waiting for the data to arrive, but if all your programs keep pushing each other out of physical memory, you get thrashing and consider yourself happy if the mouse pointer is still responsive!

    So you may want to change the title of your post to: "why use physical memory in modern systems?". I would point you to an article I wrote on that topic in 1990, but somehow I can't find a link to it on the web :-)

    fairsoftware.net - software developers share revenue from the apps they build

    1. Re:You mean physical memory right :-) by Anonymous Coward · · Score: 5, Insightful

      You must be confused about virtual vs. physical memory.

      Indeed. When I read this story my knee jerk reaction was "please be gentle." And thankfully the first +5 post on this story is informative and helpful and relatively kind.

      I fear the "turn off your computer, put it in a box and mail it back to the manufacturer" hardcore hardware experts that are going to show up in 3 ... 2 ... 1 ...

    2. Re:You mean physical memory right :-) by TypoNAM · · Score: 5, Insightful

      Actually no the author was correct in Microsoft's Windows' terms. This is the exact text used in System Properties -> Advanced tab under Virtual memory:
      "A paging file is an an area on the hard disk that Windows uses as if it were RAM."

      You might think well they said paging file not virtual memory, well click on Change button and you'll see the dialog pop up named "Virtual Memory" of which you can specify multiple paging files on multiple drives if you wanted to. Defaulted to a single paging file on the C:\ or boot drive. So blame Microsoft for the confusing use of virtual memory and paging file back and forth. I guess they mean by virtual memory as in the collection usage of paging files after the fact (for those situations where there's more than one paging file used, just like on Linux you can have more than one swap file in use).

      Anyway, I too have seen Windows 2000 and XP just love to make heavy use of the paging file even though there is clearly enough physical memory available. Some friends of mine have even disabled Windows from using a paging file completely, at first you will get a warning about it, but other than that they have reported better system performance and no draw backs noticed since then. This is on systems with at least 3GB of RAM.

      --
      This space is not for rent.
    3. Re:You mean physical memory right :-) by alain94040 · · Score: 5, Funny

      Gentle answers is what 6 years in customer support teaches you.

      That, or hating everyone ;-)

    4. Re:You mean physical memory right :-) by TypoNAM · · Score: 5, Informative

      Sorry, got to correct the path to where exactly I got that quote from:
      System Properties -> Advanced -> Performance area, click Settings -> Advanced tab (on Windows XP, as for 2000 its the default tab).

      --
      This space is not for rent.
    5. Re:You mean physical memory right :-) by houstonbofh · · Score: 5, Funny

      Gentle answers is what 6 years in customer support teaches you.

      That, or hating everyone ;-)

      That kind of attitude really pisses me off! ;-)

    6. Re:You mean physical memory right :-) by Reziac · · Score: 5, Interesting

      I've been running without a pagefile, in all versions of Windows, for about 10 years now -- on any machine with more than 512mb.

      The only drawback is that a few stupid Photoshop plugins whine and refuse to run, because if they don't see a pagefile, they believe there is "not enough memory" -- a holdover from the era when RAM was expensive and the pagefile was a busy place. Sometimes I think about making a very small pagefile just for them, but have never actually got around to doing it.

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    7. Re:You mean physical memory right :-) by hardburn · · Score: 5, Informative

      It never did change. "Virtual Memory" always meant a trick the kernel and CPU do to make programs think they are accessing a different memory address than they actually are. This trick is necessary in all multitasking operating systems.

      Once you've made the jump to mapping real memory addresses to fake ones, it's easy to map the fake addresses to a swap file on the hard drive instead of actual RAM. The confusion of the terms started when naive programmers at the UI level called that swap file "virtual memory".

      --
      Not a typewriter
    8. Re:You mean physical memory right :-) by nmb3000 · · Score: 5, Informative

      Either he/she thinks "Virtual Memory" is the same thing as paging

      Physical memory, virtual memory, address space, and paging files are some of the most misunderstood things your average computer "expert" deals with. When it comes to Windows, few can probably explain why only 3GB of 4GB physical RAM shows up on a 32-bit system. Fewer even can probably define the difference between "virtual memory" and "paging file".

      I highly recommend any Windows users or administrators read Mark Russinovich's latest blog entry Pushing the Limits of Windows: Virtual Memory . It goes over all these things and describes the difference between virtual memory, committed memory, and why it really is important to have a paging file, even on that system with 8GB of physical RAM. Should be required reading for any Windows admin.

      --
      "What do you despise? By this are you truly known." --Princess Irulan, Manual of Muad'Dib
      /)
    9. Re:You mean physical memory right :-) by qw0ntum · · Score: 5, Informative

      I know it was a joke but actually, in an oversimplified sense, yes. A main point of virtual memory in its true sense is to abstract the limitations of your amount of physical memory away from user programs, and instead present them with an effectively limitless virtual address space with which to work with. When the program says, "read from memory address 0x(some huge number)", the OS/memory management unit will translate that address request from a virtual page address to a physical frame via the page table. If there is no frame in memory that contains the data pointed to by the requested address, that's when you have a page fault. Then the operating goes to disk and fetches the data you requested.

      Your performance would be abysmally slow, and obviously probably wouldn't work at all with modern operating systems (just a theoretical point here!), but assuming a good implementation of virtual memory you should be able to run everything just fine. Of course, if you don't have enough disk space for your address space, you'll run into problems. :)

      --
      'Every story, if continued long enough, ends in death.' --Ernest Hemingway
    10. Re:You mean physical memory right :-) by mikael_j · · Score: 5, Informative

      Clearly someone has never done tech support, and I don't mean "helped friends/relatives fix something" I mean in the trenches, taking calls all day long, every day.

      Trust me on this one, there are lots of really stupid people out there, and sadly tech support is a great place to find out that being intelligent and friendly don't help when you're faced with some guy with a "fancy" last name, an e-mail address that indicates that he is a partner at a well-known law firm and serious entitlement issues ("I WANT THIS FIXED NOW YOU GOD DAMN MOTHERFUCKING HIGH SCHOOL DROPOUT LOSER PUNK DO YOU HAVE ANY IDEA HOW MUCH MONEY I'M LOSING EVERY HOUR THAT MY (residential $15/month DSL) BROADBAND ISN'T WORKING I'M GONNA FILE A FUCKING LAWSUIT I WANT A FUCKING SUPERVISOR RIGHT GOD DAMN NOW YOU SHITHEAD LAZY KNOW-NOTHIN....", well you get the point). Also, when there's an outage these are the people who make you aware of the outage before the NOC calls to tell you about it because within 30 seconds of their DSL going down there's going to be about 50 of these people waiting to yell at you for the DSLAM getting destroyed by a direct lightning strike (and yeah, I've had to deal with something like 50% of the idiots who called about that particular outage demanding to speak to a supervisor because they felt I wasn't doing my job when I explained that it would take several days to repair the building the DSLAM was housed in before a replacement DSLAM could be installed. Also, this is the kind of person who works as a lawyer while somehow being unaware of the term "force majeure").

      To sum it up: There are lots of stupid assholes out there, it's not just plain stupidity due to genetic factors, there's also the issue of people who simply choose to stay uneducated about even the most basic computer skills (while relying on their computer to do their job) like understanding the difference between "a program" and "a website" or how to find the start menu in WinXP/Vista...

      /Mikael

      --
      Greylisting is to SMTP as NAT is to IPv4
    11. Re:You mean physical memory right :-) by Siridar · · Score: 5, Insightful

      I'm fine with folks not knowing about computers. That's cool. The thing that annoys me, though, is that they're /proud/ of it. Its like its a badge of honor! Any sort of discussion about computer issues will always bring up some yahoo who says "Oh, I don't know a /thing/ about that! hur hur, in my day, all we had was pen and paper..." etc etc etc. The fact is, knowledge - basic knowledge - of computers is only going to get more important. Hiding your head under a rock isn't going to magically make it go away.

      And its not the age thing, either - I've got a friend who is in his 70's, and his knowledge of technical things is way up there - he's a pure linux guy, uses myth to serve TV content all around the house, and is a very active member in the local unix club. Some people just don't seem to want to learn the basics.

    12. Re:You mean physical memory right :-) by ChangelingJane · · Score: 5, Insightful

      Part of it too is that *everybody* has their stupid moments. The kind where, afterward, you realize just how dumb you were. Some like to pretend they've never been guilty of it, but they're often the worst offenders. (Same goes for doing asinine things while driving.)

    13. Re:You mean physical memory right :-) by mombodog · · Score: 5, Funny

      "two years in law enforcement.. You truly get to meet the scrapings of the gene pool that way "
      Hey, they gave you a gun and ammo to narrow the gene pool, what happened?

  2. Memory exists to be used by Alereon · · Score: 5, Insightful

    Memory exists to be used. If memory is not in use, you are wasting it. The reality is that your system will operate with higher performance if unused data is paged out of RAM to disk and the newly freed memory is used for additional disk caching. Vista's memory manager is actually reasonably smart and will only page data out to disk when it really won't be used, or you experience an actual low-memory condition.

    1. Re:Memory exists to be used by etymxris · · Score: 5, Interesting

      I've known this argument for many years, I just don't think it applies anymore. The extra disk cache doesn't really help much, and what ends up happening is that I come in to work in the morning, unlock my work XP PC, and I sit there for 30 seconds while everything gets slowly pulled of the disk. XP thought it would be wise to page all that stuff out to disk, after all, I wasn't using it. But why would I care about the performance of the PC when I'm not actually using it?

      At the very least, the amount of swap should be easily configurable like it is in Linux. I haven't actually used a swap partition in Linux for years, preferring instead to have 6 or 8gb of RAM, which is now cheap.

  3. The real answer is by Ethanol-fueled · · Score: 5, Funny

    Virtual memory and pagefiles still exist so that there will be persistent, recoverable storage of your browsing and search history, illegally downloaded music, and furrie porn should anybody come a-knockin after you hit the power switch.

    [/tinfoil hat]

  4. Would it help if by Xerolooper · · Score: 5, Funny

    you could create a RAM Disk and set your page file to use that.
    Then all your virtual memory is in RAM.
    I'll leave it to someone else to explain why that isn't a good idea.

    --
    "The stupid neither forgive nor forget; the naive forgive and forget; the wise forgive but do not forget." -Thomas Szasz
    1. Re:Would it help if by Changa_MC · · Score: 5, Interesting

      I know it's not a good idea now, but this was seriously a great trick under win98. Win98 Recognized my full 1GB of RAM, but seemed to want to swap things to disk rather than use over 256MB of RAM. So I just created a RAM disk using the second 512MB of RAM, and voila! Everything ran much faster. When everything is broken, bad ideas become good again.

      --
      Changa hates change.
  5. Turn it off, then! by Jeppe+Salvesen · · Score: 5, Insightful

    We who know what we are doing are free to take the risk of running our computers without a swapfile.

    Most people are not in a position where they can be sure that they will never run out of physical memory. Because of that, all operating systems for personal computers set up a swapfile by default: It's better for joe average computer owner to complain about a slow system than for him to lose his document when the system crashes because he filled up the physical memory (and there is no swap file to fall back on).

    --

    Stop the brainwash

  6. Re:Vista reserves 1 GB by El+Lobo · · Score: 5, Informative

    Absolutely not true. You can even install and run Vista on a computer with 1Gb ram and no page file. And run applications. So it doesn't reserve 1Gb for itself and thus, your myth is busted. Vista's memory manager will use as much memory it can (free memory is a waste, so it will use it rather than watch it empty). But as soon as a process needs memory it will give it back.

    --
    It's time to realise that Abble's products are the biggest abomination these days. Just say NO to the dumb iAbble way!!
  7. rephrasing his question charitably... by Trepidity · · Score: 5, Interesting

    I'd assume what he's asking is: in modern systems where the amount of physical RAM is considerably larger than what most people's programs in total use, why does the OS ever swap RAM out to disk?

    The answer is basically to free up RAM for disk cache, based on a belief (sometimes backed up by benchmarks) that for typical use patterns, the performance hit of sometimes having to swap RAM back into physical memory is outweighed by the performance gain of a large disk cache.

    Of course, OS designers are always revisiting these assumptions---it may be that for some kinds of use patterns using a smaller disk cache and swapping RAM out to disk less leads to better performance, or at least better responsiveness (if that's the goal).

    1. Re:rephrasing his question charitably... by DragonWriter · · Score: 5, Insightful

      The answer is basically to free up RAM for disk cache, based on a belief (sometimes backed up by benchmarks) that for typical use patterns, the performance hit of sometimes having to swap RAM back into physical memory is outweighed by the performance gain of a large disk cache.

      Whether or not it works (and I'm not sure how well it does), there's something odd about swapping out RAM contents to disk so that you can mirror disk contents in RAM.

  8. I prefer none. by mindstrm · · Score: 5, Insightful

    This should generate some polarized discussion.

    There are two camps of thought.

    One will insist that, no matter how much memory is currently allocated, it makes more sense to swap out that which isn't needed in order to keep more free physical ram. They will argue until they are blue in the face that the benefits of doing so are good.
    Essentially - your OS is clever and it tries pre-emptively swap things out so the memory will be available as needed.

    The other camp - and the one I subscribe to - says that as long as you have enough physical ram to do whatever you need to do - any time spent swapping is wasted time.

    I run most of my workstations (Windows) without virtual memory. Yes, on occasion, I do hit a "low on virtual memory error" - usually when something is leaky - but I prefer to get the error and have to re-start or kill something rather than have the system spend days getting progressively slower, slowly annoying me more and more, and then giving me the same error.

    This is not to say that swap is bad, or that it shouldn't be used - but I prefer the simpler approach.

  9. Virtual Memory v Paging by clarkn0va · · Score: 5, Informative

    thinks "Virtual Memory" is the same thing as paging...

    Mac Classic (OS 8 for sure) used the term "Virtual Memory" the same way Windows today uses "Page File" or unix uses "swap", so you can at least understand why some people might be confused by this.

    db

    --
    I am literally 3000 tokens away from the chaotic crossbow --Stephen
  10. Re:Vista reserves 1 GB by d3vi1 · · Score: 5, Informative

    I think he is referring to the userspace/kernelspace split in Windows NT. On 32bit Windows XP, by default, the userspace (ring3) will have at most 2 GB of the physical RAM, and the kernel space would get the rest (some of it paged and some of it not). On systems with more than 3G of RAM (a lot by 2002 standards), it was kinda pointless to reserve that much for the kernel space, so they added a boot.ini flag that changed the split to _AT_MOST_ 3GBytes for the userspace and the rest for kernel space.
    In Vista the split for 3G/1G of RAM is default. Actually on a system with 4G of RAM running in 32bit mode, you can't use all of them even if you try (in Windows XP), because right under the 4G limit you would have the PCI memory address mappings, that can be as large as 512M for a common video card with half a gig of RAM. Add to that the RAID controllers and the other hardware, and you have about 800megs of RAM unused because they can't be addressed, as their address-space is used by the installed devices.
    I think that http://support.microsoft.com/kb/823440/ and http://support.microsoft.com/kb/171793/ should describe what I'm talking about pretty clearly.

    --
    UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever ones.
  11. Can't hibernate by anomaly · · Score: 5, Interesting

    Windows makes me CRAZY about this. the OS is internally configured to use an LRU algorithm to aggressively page.

    ("Technical bastards" who question my use of paging and swap interchangeably in this post can send their flames to /dev/null \Device\Null or NUL depending on OS)

    What I found when disabling paging on an XP pro system with 2GB RAM is that the system performance is explosively faster without the disk IO.

    Even an *idle* XP pro system swaps - explaining the time it takes for the system to be responsive to your request to maximize a window you have not used in a while.

    I was thrilled to have a rocket-fast system again - until I tried to hibernate my laptop. Note that the hibernation file is unrelated to the swap/paging space.

    The machine consistently would blue screen when trying to hibernate if swap/paging was disabled. Enabling swap enabled the hibernation function again. Since reboots take *FOREVER* to reload all the crap that XP needs on an enterprise-connected system - systems mangement, anti-virus agent, software distribution tool, and the required ram-defragger which allows XP to "stand by" when you've got more than 1GB of RAM, plus IM, etc

    I reboot as infrequently as possible and consider "stand by" and "hibernate" required functions. As a result, I live with XP and paging enabled, and tolerate the blasted system "unpaging" apps that have been idle a short time.

    Poo!

    --
    But Herr Heisenberg, how does the electron know when I'm looking?
  12. Re:Only 4 GB? by sexconker · · Score: 5, Funny

    The Kessel Run is obviously a surviving salesman problem.

    The traveling salesman is selling zombie survival kits at the onset of the zombie apocalypse. He must sell $X worth of kits to afford his choppa ticket, and return to the evac zone. The evac choppa is waiting for him (or does continuous runs), so time is not an issue, and he can make long-winded sales pitches in safe houses.

    Distance traveled is an issue, because the horde is everywhere, and the best strategy is to minimize exposure and avoid detection.

    Quickness (acceleration, agility) is an issue because it helps you avoid detection, and when detected, you need to escape or hide quickly.

    Speed (top speed of your van) is an issue because you often need to make a beeline to the nearest safe house, or to the evac zone once you have met your quota.

    A surviving salesman is rated on his total distance traveled. A lower distance is indicative of a better salesman, and a better vehicle. Being able to zoom through the most dangerous areas will shorten your trip (path length) due to the increased demand and reduced supply of zombie survival kits in said areas.

    For the Millennium Falcon, the above applies with a few differences. Han Solo and Chewbaca are hiding from the Empire, not the zombie horde. Instead of selling survival kits, they're smuggling contraband. Instead of running to safe houses, they're running off to Mos Eisley or other fringe/pirate friendly planets the Empire doesn't have (complete) control over. The money gained isn't for a choppa ticket, but for the general livelihood of Han and Chewbaca.