Should I disable swap file if I have lots of RAM or should I move it to a virtual RAM drive?

120,574

Solution 1

No matter how much RAM you have, you want the system to be able to use it efficiently. Having no paging file at all forces the operating system to use RAM inefficiently for two reasons. First, it can't make pages discardable, even if they haven't been either accessed or modified in a very long time, which forces the disk cache to be smaller. Second, it has to reserve physical RAM to back allocations that are very unlikely to ever require it (for example, a private, modifiable file mapping), leading to a case where you can have plenty of free physical RAM and yet allocations are refused to avoid overcommitting.

Consider, for example, if a program makes a writable, private memory mapping of a 4GB file. The OS has to reserve 4GB of RAM for this mapping, because the program could conceivably modify every byte and there's no place but RAM to store it. So immediately, 4GB of RAM is basically wasted (it can be used to cache clean disk pages, but that's about it).

You need to have a page file if you want to get the most out of your RAM, even if it's never used. It acts as an insurance policy that allows the operating system to actually use the RAM it has, rather than having to reserve it for possibilities that are extraordinarily unlikely.

The people who designed your operating system's behavior are not fools. Having a paging file gives the operating system more choices, and it won't make bad ones.

There's no point in trying to put a paging file in RAM. And if you have lots of RAM, the paging file is very unlikely to be used (it just needs to be there) so it doesn't particularly matter how fast the device it is on is.

Solution 2

You are entirely correct in your assumption.

Memory management algorithms are very complex and by any means not perfect. So swapping occurs even when there is plenty of spare RAM. On some systems, like Linux, you can control swappiness, on others you can't. By swapping out data when there is still plenty of RAM, system in its own way prepares for the situation when it might run out of RAM.

So disabling swapping functionality might give you the improvement in performance because you will only be using RAM which is faster as you already said.

One thing to consider (and you mentioned it already) - you need to have enough RAM to accommodate all the programs you are executing, otherwise you are risking to run out of memory. In this case the performance will drop, some processes may be terminated by OS and system may experience crash/freeze. (read more about it here)

On some machines, especially ones that keep swap file on HDD not SSD, the effect from disabling swapping is very noticeable. On others it is not so obvious. But even if you don't get obvious improvement, think of it in another way, by disabling swapping you will save yourself some disk space on your SSD.

By disabling swapping, you will also prevent memory algorithms from doing unnecessary operation - moving data from RAM to swap and vice versa - in case of SSD this will prevent excessive wear. And in any case this will improve the performance by eliminating unnecessary operations.

Also, read:

Solution 3

Can you safely disable the pagefile?

If you run out of free memory, including virtual memory, the system cannot continue to guarantee deterministic execution, and ends itself. Before that happens, the operation system will do various other things such as killing programs that use too much memory. What I want to say is, memory is always finite, and every OS can deal with this. Therefore limiting total available memory to 64 GB won't harm Windows - many systems can't go beyond 8 GB even with a pagefile, because with 1 or 2 GB RAM the pagefile is usually a lot smaller than 6 or 7 GB. It should be noted that as long as you have an excessive amount of unused RAM, the overhead of the OS maintaining a pagefile will not be measurable.

Does it make sense to put the pagefile on a ramdisk?

To increase the available memory, most if not all advanced operating systems use some kind of swap file where they take some memory that's in RAM and hasn't been accessed for a while, write the memory to the harddisk (swapfile aka pagefile), and delete the memory from the RAM so that more fast memory is available. The swapfile is used to extend the maximum size of the memory beyond the size of the available RAM.

Therefore, using a ramdisk (which reduces available memory by the size of the ramdisk) to host the swapfile (which increases available memory by the size of the swapfile) will work, but it won't make a lot of sense. It will not offer more memory than disabling the pagefile, yet it will still require the system to run paging algorithms.

Solution 4

To reiterate what others have said, moving swap to a straight RAM disk is rather pointless (in the most common case, see below). It achieves that at certain point, when the system is starved for free memory, some data is moved from RAM to RAM in a rather inefficient way.

Having swap on HDD/SSD achieves that the OS can clear out some completely unused RAM pages and use the freed space for e.g. file cache or other system buffers. You might not realize that the system allocates less of these RAM buffers because you have no available virtual memory without a page file; so in effect you might be stunting your performance by disabling swap.

However, a compressed RAM disk as swap drive, a "ZSWAP" drive, can be beneficial in edge cases (where you might need just a few additional MB RAM to avoid swapping to HDD) by improving space efficiency of a segment of RAM to a certain extent.

Solution 5

If you don't have a page-file, then in case of a BSOD (crash) Windows won't be able to write the crash dump file. This means that you won't be able to analyze the problem by using the appropriate tools.

Having the page file in RAM is next to useless, since it may be lost in the crash.

For more information, see the Microsoft article Understanding Crash Dump Files.

Share:
120,574

Related videos on Youtube

user1306322
Author by

user1306322

I've come to learn things and teach stuff. And I'm all outta stuff. And don't take anything I say personally, because… I don't give it to you personally! Feel free to improve my posts by editing or commenting. helpful links: http://xbox.create.msdn.com/en-US/education/tutorial/2dgame/getting_started http://jsbeautifier.org/ (also acceptable for C#) http://regex101.com/ I strongly recommend you include in your question all additional details that might help us answer your question properly and completely.

Updated on September 18, 2022

Comments

  • user1306322
    user1306322 over 1 year

    Imagine I have tons of RAM. Let's say 64GB. That's a lot for even gaming PCs. Now the default location of a pagefile in Windows is on the main OS drive, be it HDD or SSD, which are faster in general, but still not as fast as RAM.

    Something tells me that disabling the pagefile on the hard drive or creating a virtual RAM drive and letting the pagefile be there could make Windows move all its virtual memory to RAM, and so increase the system's performance, but I'm not very knowledgeable in that area, so that might not be true at all.

    I tried both, but I couldn't analyze the results to reach a definite conclusion with my knowledge level in memory things.

    Would this work? If not, why?

    • usr
      usr over 9 years
      Having a paging file on a RAM disk never accomplishes anything. You take away a certain amount of available memory and add a certain amount of virtual memory. Null-sum. Just have no paging file.
    • hookenz
      hookenz over 9 years
      In makes some sense to do this on Linux in some cases where the ram disk hosting the swap file is actually compressed. See: en.wikipedia.org/wiki/Zram. However I don't think Windows has such a feature available to it.
    • user541686
      user541686 over 9 years
      The answer is yes but there are plenty of nonbelievers.
    • Rob Moir
      Rob Moir over 9 years
      @user367257 creating a ram disk to store your page file on is like lending your friend £10 so that he has enough money to allow you to borrow £10 from him. It might be technically possible but all you've accomplished is to needlessly complicate a journey to nowhere.
    • Ry-
      Ry- over 9 years
      I would (and do) only turn it off for an SSD, since you only get so many writes (even if it’s a lot now), with 6GB. It works well.
    • Lesmana
      Lesmana over 9 years
      memory management and pagefile/swapfile management have changed radically over kernel versions and will continue to change radically. please state in your answers clearly for what kernel version your answer is valid.
    • Victor Zakharov
      Victor Zakharov over 9 years
      I am running with swap disabled on my home PC, never had an issue. 16GB of RAM. This can accommodate host + VMWare guest running development environment (VS2010 + SQL server 2014). OS is Windows 7.
    • Sun
      Sun over 9 years
      Why aren't you installing the game on the ramdrive and running it from there?
    • Twinbee
      Twinbee over 9 years
      @usr: Whilst in theory you're correct, in practice, you're not taking into account design misjudgments from the Windows kernel programmers. See all the users who would beg to differ.
    • usr
      usr over 9 years
      @begtodiffer it is true that Windows misjudges paging decisions all the time. But with out page file at all, instead of one on a RAM disk, there is nothing to misjudge.
    • user1306322
      user1306322 over 9 years
      I guess it only takes to try it out to find out if it works for you or not.
    • Twinbee
      Twinbee over 9 years
      @usr: I was just responding to the point of "never accomplishes anything", as all those users experienced a performance increase when putting the pagefile into the Ramdisk. It shouldn't happen, but it does.
    • usr
      usr over 9 years
      @DanW those users should have disabled the file and would have gotten even better results. Putting the paging file on a RAM disk is always inferior to having no paging file at all.
    • Twinbee
      Twinbee over 9 years
      @usr: Again, whilst you're right in theory (and I agree with the spirit of that), there are a few reasons to not disable it completely. The most notable being that some applications (particularly older ones) require the pagefile to run.
    • usr
      usr over 9 years
      @DanW I have never heard about that. That would rquire the app to explicitly check whether the paging file is on and stop working if it is not. Few reasons an app would care about the paging file. Assuming, though, that such apps exist: set the file size to 1MB.
    • Sam Watkins
      Sam Watkins over 8 years
      IDK, but virtual memory / swapping / delayed loading certainly massively decreases responsiveness compared to older systems (such as Acorn Archimedes, or even old 8-bit Micros) which did not do this. It's a sorry state of affairs when a modern wordprocessor is less responsive for many operations (when first loading, or swapped out) than an 8-bit 2Mhz machine. Personally I would rather have "out of memory" error any day of the week than swapping to disk and the resultant massively degraded performance. This would encourage programmers not to waste RAM.
    • Sam Watkins
      Sam Watkins over 8 years
      Paging virtual memory is like overconfidence, "Yeah, I can handle this job by myself, no worries!" whereas in fact the computer would take a month of swapping to finish the job and doesn't even know it. If a job works well with serial access it should be using files in the first place. If a job requires rapid random access on a large chunk of RAM (e.g. for an in-memory hash, or for executable code), in no way is it acceptable to be swapping that RAM in and out from disk during the operation. The computer pretends it has infinite RAM, but this is a lie and not a helpful one.
    • Sam Watkins
      Sam Watkins over 8 years
      Even for jobs that seem to require more memory than is available, swapping whole pages in and out is rarely the most efficient way to utilize the memory. Better if the programmer designs the job to use RAM and files efficiently as needed in the first place.
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 about 8 years
  • user1306322
    user1306322 over 9 years
    But in case the pagefile is on a virtual RAM drive, the time used to copy some megabytes from RAM to virtual hard drive or back from it will be reduced. And if the pagefile is disabled completely, there should be no time wasted on that at all. Is this correct?
  • Peter
    Peter over 9 years
    Correct. Copying bytes from RAM to a pagefile that is on a ramdisk is the fastest possible pagefile. But not copying at all is smarter.
  • Art Gertner
    Art Gertner over 9 years
    @ChrisH, valid point. This proves that amount of RAM highly depends on user requirements. For someone 2 GB will do just fine, someone will need 64GB. (I personally run my system with 3GB RAM and no swap and never had any problems)
  • Chris H
    Chris H over 9 years
    It would be stretching a point to call me even a casual gamer, but even so my desktop is rather different 4GB RAM + swap on a dedicated HDD (but swappiness adjusted). I had originally planned to put a rarely-used swap partition on the netbook's SD card (an 8GB SD card costs peanuts compared to an SSD) but there were driver issues.
  • TylerH
    TylerH over 9 years
    @ChrisH You also probably wouldn't be able to load a sql database into a word processor, since those run entirely in RAM :-)
  • Admin
    Admin over 9 years
    Swapfiles are there to compensate for a lack of RAM. If there's plenty of RAM, there's no need to compensate. Your OS will still use the swapfile though, so it's quicker to turn it off in that case.
  • David Schwartz
    David Schwartz over 9 years
    This answer is incorrect and contains lots of misinformation. But the simple way to see why it's wrong is this -- the people who designed your operating system's memory behavior are probably some of the smartest people in the world. Why would they design a system such that giving it more options (the option to swap if, and only if, it thinks that's best) would make its performance worse? Only an idiot would design a system like that.
  • Art Gertner
    Art Gertner over 9 years
    @DavidSchwartz, I don't see how the fact that people who developed memory management algorithms are smart, makes any difference to original subject. OP has asked whether disabling swapping can improve performance and I have explained that it can, under certain conditions and can lead to problems under other conditions. Answering your question of why (?) - I can say, because algorithms are not perfect and it is up for the user to fine tune them. This is why there is a swappiness parameter in Linux and this is why disabling swapping is at all possible.
  • David Schwartz
    David Schwartz over 9 years
    @smc There's nothing unusual about the OP's use case. The notion that operating systems are not properly tuned for bog standard use cases is complete nonsense. (See my answer for more on why you don't want to do this.)
  • David Schwartz
    David Schwartz over 9 years
    @Mast That's a gross oversimplification. Swapfiles are also there to permit efficient use of RAM.
  • spudone
    spudone over 9 years
    Wasn't me, but read this: overclock.net/t/1193401/… (specifically, the part about the commit limit, and the email comment from Mark Russinovich, who is an expert on the topic).
  • Admin
    Admin over 9 years
    @DavidSchwartz Perhaps, but that's the explanation that explained it to me the best. In most cases, a small amount of swapfile is always benificiary over no swapfile. However, I don't have the resources to back that up.
  • Zan Lynx
    Zan Lynx over 9 years
    I agree that disabling swap can be a good idea. Anyone who's used Linux and had Evolution email run away with 3.5 GB of RAM would rather have Evo die than sit and wait for the laptop to stop swapping.
  • Mattisdada
    Mattisdada over 9 years
    David Schwartz is absolutely correct, if you are really concerned about the possibility of paging to disk slowing down your system, you can buy a 64GB SSD for pretty much nothing ($40AUD) and use that as the paging/swap disk. Also reserving the RAM for the possibility of needing more of it later has other performance implications. In Windows (and other OSs) it will put commonly used items into the memory cache, that can be instantly destroyed when required, but when needed can be accessed quicker than reading from disk
  • Anaksunaman
    Anaksunaman over 9 years
    The assumption that a given algorithm will always make a desirable decision for the user is flat-out untrue. They make decisions based on a set parameters the programmers have decided are important. This might well be at direct odds with what a user needs to have happen.
  • James_pic
    James_pic over 9 years
    +1 for mentioning ZSWAP. It's commonly used in some mobile platforms, as well as being used in OS X 10.9 (albeit in addition to swap).
  • Norio Akagi
    Norio Akagi over 9 years
    @spudone: Where did David mention a RAM disk?
  • Admin
    Admin over 9 years
    @Groo Last paragraph: "There's no point in trying to put a paging file in RAM. ..."
  • Norio Akagi
    Norio Akagi over 9 years
    @Eliah: yes, but that is correct: there is no point in doing that. Which is the same thing written by Russinovich in that link by spudone: "putting the pagefile on a RAM disk is ridiculous". That's why I don't understand how the comment is relevant at all (being what seems to be a possible explanation to David's question about the downvote).
  • viraptor
    viraptor over 9 years
    Does windows really always preallocate writable private mmapped files? On linux I don't think anyone would do that with huge files - MAP_NORESERVE and MAP_POPULATE are options that give you some control over the reservations and early population of pages. But also allow you to virtually mmap files bigger than physical memory+swap. Sure, you can run into situations where you SIGSEGV on access, but that's a known tradeoff.
  • David Schwartz
    David Schwartz over 9 years
    @ZanLynx I'm not saying it's never a good idea to disable swap if you have some kind of unusual use case. But there's nothing at all unusual about the OP's use case. "There once existed some reason it made sense to tweak this knob" does not mean "you should tweak this knob".
  • David Schwartz
    David Schwartz over 9 years
    @Anaksunaman Yes, but this is the 100% typical use case. The notion that modern operating systems need VM tuning to handle 100% typical use cases is nonsense.
  • David Schwartz
    David Schwartz over 9 years
    @viraptor If that was correct (and I'm not 100% certain how Windows behaves in this case) it would make my argument even stronger -- not having a paging file could cause applications to needlessly crash, again, because the OS couldn't use the RAM it had efficiently.
  • spudone
    spudone over 9 years
    I was contradicting the downvote. But to your last comment: I run 2 different machines w/o swap. It's perfectly fine if you know exactly how the machine is going to be used.
  • Dan Is Fiddling By Firelight
    Dan Is Fiddling By Firelight over 9 years
    I suspect page file in a ramdrive started out as a cargo cult "workaround" for the fact that some software will refuse to start if it detects there isn't a page file. (I've been told Adobe's graphics/video tools do this.)
  • Victor Zakharov
    Victor Zakharov over 9 years
    @DanNeely: +1. One of the Warhammer games does it too. :)
  • Twinbee
    Twinbee over 9 years
    @DavidSchwartz: You may be putting the Microsoft devs on a pedestal. I know having the pagefile inside RAM makes no sense theoretically, but it turns out plenty have found that a performance increase is indeed witnessed.
  • user1306322
    user1306322 over 9 years
    Thanks for compiling this list. It should help bring forward some evidence that theory and practice differ in this matter. Virtual memory − A paging file is an area on the hard disk that Windows uses as if it were RAM. Yeah, as if :p
  • Jason Wheeler
    Jason Wheeler about 9 years
    This should not be the accepted answer. The conclusion is incorrect since the answer doesn't take into account the OP's postulation that he has "tons of RAM", which I take to mean that he has much more RAM than he's using. In such a scenario, 1) the size of the disk cache is not affected, and 2) "wasting" RAM due to allocations that will never be read from is also a non-issue.
  • David Schwartz
    David Schwartz about 9 years
    @Bigwheels It doesn't matter how much RAM you have. That's like saying you don't have to worry about money because you have lots of checks in your checkbook. If that RAM is committed, even if unused, the system will have to refuse subsequent allocations. (Consider a program that makes an unsharable, modifiable mapping of a 1GB file. Even if no RAM is used by that mapping, if there's no paging file, 1GB of RAM will be restricted to use for only clean, discardable pages.)
  • Jason Wheeler
    Jason Wheeler about 9 years
    @David Schwartz: "if that RAM is committed, even if unused, the system will have to refuse subsequent allocations." Why? Why would the system have to refuse subsequent allocations?
  • David Schwartz
    David Schwartz about 9 years
    @Bigwheels Because the backing store is committed. It's the same reason you can't write a check just because you have enough money in your bank account. Windows will not overcommit backing store, so if it doesn't have a paging file, it can't overcommit RAM either. It doesn't matter how much RAM is free if it's committed, it can't be used to hold anything that's not discardable unless there's sufficient uncommitted backing store. An unsharable, writable file mapping commits as much backing store as the size of the mapping, even if it never actually uses any RAM.
  • Jason Wheeler
    Jason Wheeler about 9 years
    @DavidSchwartz I'm clear on that point. One process commits some amount of memory, and then no other process will be able to use the memory that's been committed, even if that RAM is never used. But that's not a problem until all of the RAM has been committed. Btw, this isn't just a problem when you don't have a page file. The page file just gives you more memory to commit before you reach the limit. To make the point even further, I could decrease my page file by 1GB and add 1GB of RAM to my system and be no better or worse off, with respect to the amount of RAM that can be committed.
  • Jason Wheeler
    Jason Wheeler about 9 years
    @DavidSchwartz The information you give is technically correct, and it's good information to know. But the conclusion that you come to that you should always have a page file regardless of how much RAM you have is not correct and I stand by my claim that this should not be the accepted answer.
  • David Schwartz
    David Schwartz about 9 years
    @Bigwheels I don't come to that conclusion. Read my answer again.
  • David Schwartz
    David Schwartz almost 9 years
    @Bigwheels "But that's not a problem until all of the RAM has been committed." No, that's not true. With no page file, every byte of RAM that's committed but not yet used is one byte of RAM that is limited to holding only clean, backed pages. This can impact performance (by forcing the early discard of clean pages that are part of the working set) long before anything is anywhere close to running out.
  • Jason Wheeler
    Jason Wheeler almost 9 years
    @DavidSchwartz Every single argument you have made against not having a pagefile is also true when you have a pagefile. With respect to your arguments, adding 1GB of RAM is equivalent to adding 1GB of pagefile. I am not sure why you insist on pushing the agenda that having no pagefile is bad, but it is a disservice to the people reading your answer.
  • David Schwartz
    David Schwartz almost 9 years
    @Bigwheels Without a pagefile, a 1GB private, modifiable mapping prevents 1GB of RAM from ever holding pages that are discardable. With a 1GB pagefile, it does not. So "Every single argument you have made against not having a pagefile is also true when you have a pagefile." is simply false. "I am not sure why you insist on pushing the agenda that having no pagefile is bad" because it is bad, for all the reasons I've explained. (And which I see no evidence that you understand.)
  • Fred Hamilton
    Fred Hamilton almost 9 years
    @DavidSchwartz I really don't understand why people are so vehemently pro-pagefile, when common sense (and actual experience) indicates it works fine. You're analogy "That's like saying you don't have to worry about money because you have lots of checks in your checkbook" is not correct. The analogy is that you were getting along fine on $50,000/year and you win $10M. You no longer have to worry about money if you keep reasonably close to the same lifestyle. If all you want to do is play World of Warcraft and surf the web, I'm certain you can do that without a pagefile on a 64GB machine.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    The only acceptable reason to say that everyone has to use a pagefile all the time regardless of the amount of RAM they have and how they use use their PC would be if the memory management system was terribly, terribly broken. Does someone running Win8 with 4GB RAM need a pagefile? Absolutely. Does someone running Win8 with 64GB RAM need a pagefile? Only if they are doing massive things that use more than the 4GB - 8GB that most users use. And of course pagefiles can cause thrashing. How can people even argue these points?
  • David Schwartz
    David Schwartz almost 9 years
    @FredHamilton Saying "pagefiles can cause thrashing" is equivalent to saying that the memory management system is terribly, terribly broken. You're essentially claiming that giving the system more choices (because that's all a pagefile does, it doesn't require the system to do anything) makes performance worse. I don't understand how you can say, "Only if they are doing massive things that use more than the 4GB - 8GB that most users use". As I've explained several times, it doesn't matter how much RAM they have free.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    @DavidSchwartz 'Saying "pagefiles can cause thrashing" is equivalent to saying that the memory management system is terribly, terribly broken.' I'd say the MMS you're describing IS terribly broken. The only universe in which a system with 4GB RAM and a 4GB pagefile is more reliable and less thrashy than a system with 64GB and no pagefile is a universe where the memory management system is terribly, terribly broken.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    I do agree that a system with a pagefile doesn't HAVE to be thrashy - I just know from experience that with every version of Windows I have used it IS more thrashy, because Windows is reading/writing the pagefile even when it's only using 10% of the available RAM. No one would be arguing with you if the system didn't use a pagefile until it was actually needed (I believe linux is a lot closer to that if not already there). That would be a great thing. But, at least with Windows, that's not how it works.
  • David Schwartz
    David Schwartz almost 9 years
    @FredHamilton No, that would be a bad thing. The worst time to start writing the pagefile is when you need it -- that's when I/O causes the most harm to the system because you need the I/O capability to read from the pagefile and to write recently-modified data. You actually want to start opportunistic writing earlier, when I/O is not precious, so that more pages are discardable later. I don't mean to be rude, but I know exactly what I'm talking about and have spent decades working on this stuff, it's very annoying to be constantly told I'm wrong by people who don't have a clue.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    I didn't say that the MMS should write the page file the instant before it runs out of RAM, I said "until it was actually needed", and my point is that it should not be needed if you've got a very large amount of RAM and you're using programs that only ASK FOR a fraction of that. Yet Windows (at least XP, the last time I ran Windows with a pagefile) would be reading/writing the pagefile enough to cause thrashing even if only 10%-20% of the RAM was being used.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    I get that MMS designers might be preparing for some sudden worst-case memory allocation request, but I don't understand why the pagefile had to be so frequently written/read during the hours/days/years of use when the running tasks asked for a small fraction of RAM. I'm not saying we don't need pagefiles, I'm just saying on a scale of zero to perfect, this particular MMS fell short enough of perfect that I (and from what I can tell many others) got significantly faster hard disk I/O with no negative consequences by disabling the pagefile.
  • Fred Hamilton
    Fred Hamilton almost 9 years
    I just don't like hearing that "pagefiles are magic so don't turn them off or you'll be sorry" when I know that under many common circumstances that you can turn them off, and safely see an improvement in performance because you are no longer increasing disk I/O by 100% or higher whenever the MMS wants to do something. All I want to hear from the people on the other side of this debate is "yes, there are circumstances where you can turn them off and reduce disk I/O which can result in thrashing". I'm not saying pagefiles are always bad, maybe you can say that they're not always necessary.
  • David Schwartz
    David Schwartz almost 9 years
    @FredHamilton So your complaint is with what I didn't say?
  • Fred Hamilton
    Fred Hamilton almost 9 years
    I realized what was riling me about all this is that one side seems to be saying "pagefiles never do anything but good" and the other side is "pagefiles are terrible" and then people get entrenched on one side or the other. The "truth" is that in some cases they're very useful and even crash-preventing and in other cases they are not needed and can actually cause performance to decrease. I'm happy with that as my final statement regardless. Live long and prosper, @David Schwartz.
  • Jamie Hanrahan
    Jamie Hanrahan almost 9 years
    this conclusion is flawed. the fact that the OS writes things to the pagefile even though it apparently has "massive amounts of RAM free" does not prove anything about "flawed design and philosophy". It means you don't have enough information to properly evaluate the OS's decisions. Just for starters, consider the case where there are many modified pages. They get written to the pagefile and moved to the standby list - now they're part of "available". Do you get it? The RAM is available BECAUSE its contents got written to the pagefile!
  • Jamie Hanrahan
    Jamie Hanrahan almost 9 years
    Anecdotal evidence from a few users who have not posted anyhing like well-described experiments, let alone test results, is not particularly compelling.
  • Jamie Hanrahan
    Jamie Hanrahan over 8 years
    You would be much better off just putting a pagefile on your SSD. Windows will not use it if it doesn't have to. Putting a pagefile on a RAMdisk is ridiculous. Yes, page faults to that "file" will be resolved faster than if they were on a real disk, but by assigning the RAM to the RAMdisk in the first place, you are increasing the number of page faults. It's like borrowing money from yourself, charging yourself interest, and throwing the "interest" away. It isn't even wrong.
  • BamsBamx
    BamsBamx about 8 years
    And what about having a very slow HDD? It could cause a bottleneck in the entire system
  • David Schwartz
    David Schwartz about 8 years
    @BamsBamx If you reach that point, you either need to get more RAM, get a faster device for swap, reduce the load on the machine, or tolerate the reduction in performance. Hardware can only do what it can do.
  • Nick
    Nick almost 8 years
    From my personal lessons learned, and something I preach to all new employees: There are only 2 rules. #1: Never Trust Microsoft. #2.. you didn't listen to rule 1, so there is no rule 2.
  • Royi Namir
    Royi Namir almost 8 years
    This question can be answered only by Same hardware , 2 computers (same config) - , one acronis image file , and run same programs and measuring time through time
  • Jamie Hanrahan
    Jamie Hanrahan almost 7 years
    @FredHamilton I believe a more correct summary is: Pagefiles are often helpful, sometimes necessary, and if they are not needed, they do no harm (in the vast majority of cases). See the extensive test reports here: tweakhound.com/2011/10/10/… But if your workload one day needs a pagefile and you don't have one, that can cause program crashes, etc. The obvious conclusion is that you should have a pagefile. Think of it like a safety net: It won't encourage the trapeze artists to fall, but if they happen to it's sure a good thing to have.
  • Jamie Hanrahan
    Jamie Hanrahan almost 7 years
    ...continuing: The fact that Windows may appear to be "using the pagefile" when a user's impression is that it "shouldn't have to" does not mean it's doing harm; it mostly means that the user doesn't have enough information to conclude "it shouldn't have to" or that "it's doing harm". The fact that the pagefile is nonempty doesn't mean it's slowing you down. By allowing the OS to page out long-ago-referenced stale stuff it allows the OS to make more RAM available for things that are being accessed more often.
  • DavidPostill
    DavidPostill almost 7 years
    Comments are not for extended discussion; this conversation has been moved to chat.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    The accepted answer is really one-sided and is given under assumption that the user 1) wants the system to be able to use RAM efficiently and 2) is using more then one application at a time. And both could be false in some scenarios. For example, when you play a video game and the engine cached 30 Gb of resources, you'd be really disappointed when the OS swapped some that were not used for a long time (even when swapping to a fast SSD).
  • David Schwartz
    David Schwartz about 6 years
    @Sergey.quixoticaxis.Ivanov You wouldn't care whether the OS swapped it out or not because it would stay in memory even after being written out unless the system had some better use for that RAM. Writing something to swap does not necessarily mean that it is discarded.
  • Nick Sotiros
    Nick Sotiros about 6 years
    So I am running Windows with 16gb of RAM and 16gb of swap. It seems that somehow this system with 64gb of RAM should be able to do what my system can do, even with no swap. It seems like at the very least it should be able to divide its RAM in half and have 32gb of free use RAM and 32gb of ramdisk swap.
  • David Schwartz
    David Schwartz about 6 years
    @NickSotiros More RAM is always going to be better than an equivalent amount of swap. But that's almost never the decision you're faced with. Of course if you have a choice of 16GB more RAM or 16GB more swap, take the RAM.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Ofc I would not care if the memory was not changed. What was the point of your comment? But in practice it can be changed even when there are tons of memory. Your arguments are all floating around "OS knows better if it has something better to do" and "OS devs are not fools" without providing detailed information.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    OS developers are not fools, but these mechanisms were tuned for the case when "RAM < size of code + size of data it will access", which is false for, for example, modern gaming PCs where often "size of RAM > side of all code + size of all data it would ever access". And disabling pagefile could be noticable.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Microsft has already been asked lots of times to actually provide some handles for tuning swapping and caching strategies like unix based OSs provide. Unfortunatelly, this is, while considered, is not implemented.
  • David Schwartz
    David Schwartz about 6 years
    @Sergey.quixoticaxis.Ivanov OSes were tuned the way you say years ago. The virtual memory systems of every major operating system you're likely to use on a PC has been tweaked extensively since then. People asking for such handles are almost always doing so out of mistaken notions of how memory management work. If the OS doesn't come sensibly tuned for these very typical use cases, it's junk. The elusive "make my very typical use case go lots faster" button does not exist or it would already come pushed.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Can you provide anything beyond words about "every major system" and "it's junk"? Anything beyond your own beliefs? Cache strategy description maybe? Or swapping strategy description from official or any sources? At least test that show your point? Also I can't see what's "very typical" about this scenario.
  • David Schwartz
    David Schwartz about 6 years
    Sure, ask a question about it and if I don't answer it, point it out to me. OS developers have been optimizing and fine-tuning virtual memory systems with precision for decades and yet people who don't understand it insist on seeking a magic "go faster" button that does not exist.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Okay. The main question: What is the exact criteria in Windows 10 that is used to determine whether the commited page can be swapped to disk and the underlying physical RAM reused? The side question: if the OS is some godlike object that operates according to ideal algorithms, what is the point of VirtualLock function?
  • David Schwartz
    David Schwartz about 6 years
    @Sergey.quixoticaxis.Ivanov The exact criteria is that such a swap will produce improved performance under the conditions the OS is measuring based on a complex set of heuristics tuned over many years of experience. The point of VirtualLock is primarily to handle cases where data cannot be swapped for security reasons or to meet the occasional timeliness requirement for a small piece of data even at the expense of worse system behavior overall. The OS comes tuned by VM experts for best overall system behavior under a wide variety of conditions.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Yet again, no sources except "I believe" and "vm experts". It's not a concrete criteria. Papers, please. From OS developers, if possible, because all papers written on the subject that I know from OS devs ofc mention the corner cases and note that the OS is not tuned for everything possible and disabling pagefile can provide performance boost in some scenarios. Also there are plenty of tests that show how disabling pagefile while obviously doing nothing to average fps, can (also obviously) increase min fps in games if you have enough RAM. And it can be easily reproduced.
  • David Schwartz
    David Schwartz about 6 years
    @Sergey.quixoticaxis.Ivanov Funny that you complain that I'm not citing sources and your response is "all papers written on the subject that I know" and then you follow up with "plenty of tests". But your main thesis is just silly -- if there was some way to make an OS better at bog standard tasks that everyone uses the OS for, it would come set that way. You're seriously arguing that experts in VM design with decades of experience left a simple switch set in the wrong position. It's a comically silly position. You think they can't tell what a game is or think people like low frame rates?
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    I think Microsoft supposes that those few people who have gaming PCs can disable pagefile if they need in a few clicks. If you're interested, here's an article, it's a bit old, but it shows some benchmarks in the end (tweakhound.com/2011/10/10/…). Unfortunately, my new PC will be traveling for one more month, but I guess I'll run dome benchmarks in the morning on my current 32Gb machine and provide you with nubers (or find some links). Not now, it's 5 am for me.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Side-note: no, it's not funny, because I didn't give a baseless answer. I've ran some tests though: i7 4790k in stock, Titan X Pascal in stock, 32GB ddr3 1333, OS, all games and pagefile resided on the same Kingston 256GB SSD. No superfetch, system rebooted after each run. All tests were run for 3 times. Time Spy benchmark: +0.2% score, +7% min fps, Fire Strike Ultra benchmark: +0.1% score, +13% min fps, Hitman:Absolution benchmark: +-0 avg fps, +13% min fps, FFXV benchmark: -2 avg fps, +15 min fps. Note please, that this is very old PC which was a thing back when games demanded 2-4 GB RAM.
  • Sergey.quixoticaxis.Ivanov
    Sergey.quixoticaxis.Ivanov about 6 years
    Modern gaming PCs with 64GB, 128GB and hopefully (I hope Intel will present a good gaming CPU, not the half-baked i7 and i9 they are pushing now) 256GB of fast RAM will most probably benefit even more from disabling pagefile in gaming scenarios.
  • Twinbee
    Twinbee about 6 years
    @JamieHanrahan: That doesn't explain why people still have issues despite rarely using more than a fraction of the RAM. Comments in that thread include: "I've never really used more than half of it", "Page file usage is about 2.7GB where RAM usage is 3.23GB out of 16GB.", "I had a dramatic performance increase using Illustrator when I created and moved my pagefile to RAMDisk".
  • Jamie Hanrahan
    Jamie Hanrahan about 6 years
    Most of those comments are due to poor information. Performance issues are unlikely to be solved by keeping stuff in RAM that isn't being accessed often. The pagefile is not the only file involved in paging; there are hundreds of others, so it is unlikely that doing something that affects only the pagefile (and takes GBs of RAM away from the rest of the system, thereby increasing the pagefault rate) will have any "dramatic" effect. Such reports are usually not sustained when properly controlled tests are done. You can find anecdotes to support just about any belief; I find them unconvincing.
  • Jamie Hanrahan
    Jamie Hanrahan about 6 years
    In particular, the claim "the pagefile is being used" demands proof. Just having GBs of stuff in the pagefile does not prove that the pagefile is being used in a way that puts it in a critical performance path. To evaluate this, isolate the pagefile on a partition by itself - or at least, one that isn't actively in use for anything else - and then you can use PerfMon on that "logical disk" to monitor its IO rates. If the pagefile is not being read often then it doesn't matter how much has been written to it!
  • Jamie Hanrahan
    Jamie Hanrahan about 6 years
    otoh, moving your OS partition (including the pagefile) to an SSD can help, because all of those other "paging files" (EXEs and DLLs, mapped data files, etc.) can now benefit from the fast seek performance of the SSD.
  • Jamie Hanrahan
    Jamie Hanrahan about 6 years
    Note that "compressed RAM disk as a swap drive" still has the issue that it doesn't do a thing for all of the "paging files" other than the actual page file.
  • Gabriel L. Oliveira
    Gabriel L. Oliveira almost 6 years
    I'd like to add my 2 cents that, on systems (specially laptops) with restricted disk space (250 GB SSD) and plenty of Ram (32 gb), it's a good idea to reduce the pagefile to a personalized size (in my case, 1 gb minimum and 4 gb max). That's because Windows 7, by default, set the pagefile to as much as available memory ram (32 gb, in this case), i.e., inutilizes almost 13% of your disk. With this personalized settings, you still have a pagefile to dump some of the kernel stuff and paginate old and unused memory, without compromising a lot of your SSD.
  • Cherry
    Cherry over 5 years
    "The people who designed your operating system's behavior are not fools" - and those people added settings for disabling page file - they are definitelly optimized memory managment for this case. :)
  • Nicolas Melay
    Nicolas Melay almost 3 years
    Oh, so that's how they came up with this other ruleset! "#1: Never trust Nick..."
  • user4779
    user4779 almost 3 years
    I fundamentally disagree with this answer and agree with Fred in these comments. You keep referring to "stale stuff" that can be paged out. For people like me who have a lot of processes open but the ram to support it, I want instant alt-tab switching to old processes without any delay. Using a paging file, even with 90% of free RAM available, doesn't allow that. Windows will cache processes that aren't used for a long time, even if it's not necessary. For many people like me, this is an unacceptable and unnecessary performance cost that is merely coded into Windows for no good reason.
  • dns
    dns almost 3 years
    @DavidSchwartz If you have 5000 EXABYTES of RAM, you'll still definitely need Pagefile because the "experts" said so. ;-)
  • David Schwartz
    David Schwartz almost 3 years
    @user4779 It will write them to cache but it will not remove them from RAM. This allows the system to go faster if there's memory pressure because it eliminates the need to write them first when the system encounters memory pressure and I/O is precious. Under memory pressure, everything you do will slow down no matter what you do. There's no magic way to fix memory pressure when the working set exceeds RAM. As I said, the people who designed your operating system's behavior are not fools. If you really think they are, use a different OS.
  • Community
    Community about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • DarkDiamond
    DarkDiamond about 2 years
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review