112

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?

19
  • 62
    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.
    – usr
    Sep 11, 2014 at 14:47
  • 15
    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.
    – hookenz
    Sep 11, 2014 at 21:10
  • 2
    The answer is yes but there are plenty of nonbelievers.
    – user541686
    Sep 12, 2014 at 6:18
  • 16
    @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.
    – Rob Moir
    Sep 12, 2014 at 22:07
  • 2
    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.
    – Ry-
    Sep 13, 2014 at 2:24

14 Answers 14

148

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.

57
  • 11
    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.
    – spudone
    Sep 12, 2014 at 16:27
  • 8
    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.) Sep 12, 2014 at 21:06
  • 15
    @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. Feb 21, 2015 at 11:27
  • 15
    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. Jul 13, 2015 at 5:08
  • 8
    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. Jul 13, 2015 at 20:04
41

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:

14
  • 2
    @ChrisH You also probably wouldn't be able to load a sql database into a word processor, since those run entirely in RAM :-)
    – TylerH
    Sep 11, 2014 at 13:19
  • 9
    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. Sep 11, 2014 at 15:38
  • 24
    @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. Sep 11, 2014 at 16:00
  • 12
    @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.) Sep 11, 2014 at 16:27
  • 6
    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. Sep 12, 2014 at 5:49
14

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.

5
  • 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? Sep 11, 2014 at 9:02
  • 2
    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.
    – Peter
    Sep 11, 2014 at 9:05
  • 2
    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.
    – user366447
    Sep 11, 2014 at 13:44
  • 6
    @Mast That's a gross oversimplification. Swapfiles are also there to permit efficient use of RAM. Sep 11, 2014 at 16:34
  • 1
    @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.
    – user366447
    Sep 11, 2014 at 20:45
9

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.

2
  • 1
    +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).
    – James_pic
    Sep 12, 2014 at 8:36
  • 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. Apr 3, 2018 at 20:34
7

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.

5

Do not disable the swap file It is not just for when you run out of memory. There is no direct performance gain in turning it off, windows only reads from it when it needs to, it writes to it all the time so it is ready whenever it is needed.

You can reduce it to about 2/3rds of memory size if you have more than around 4GB, because it stores the memory image compressed. You can put it on your slower hard drive that isn't being accessed by other heavy disk access if you don't have space on an SSD. But it is beneficial to have one somewhere.

See this answer for more info as to why. https://superuser.com/a/286476/4236

5

For Windows, from the horses mouth:

Some feel having no paging file results in better performance, but in general, having a paging file means Windows can write pages on the modified list (which represent pages that aren’t being accessed actively but have not been saved to disk) out to the paging file, thus making that memory available for more useful purposes (processes or file cache). So while there may be some workloads that perform better with no paging file, in general having one will mean more usable memory* being available to the system (never mind that Windows won’t be able to write kernel crash dumps without a paging file sized large enough to hold them).

https://blogs.technet.microsoft.com/markrussinovich/2008/11/17/pushing-the-limits-of-windows-virtual-memory/

  • usable memory - so although this recommends having virtual memory, it also suggests that you need really large amounts of RAM to be sure to benefit from having no page file/virtual memory. I have 4GB RAM 128GB SSD with no page file, but I use it for web browsing and typing word docs.
2
  • 2
    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.
    – Nick
    Jul 6, 2016 at 0:32
  • Oh, so that's how they came up with this other ruleset! "#1: Never trust Nick..." Jun 30, 2021 at 16:37
5
+100

In theory, putting the pagefile into RAM should make no sense at all, because you're just depleting what you supposedly gain, and Windows is built on the assumption that the pagefile won't be used for such purposes.

In practice however, flawed design and philosophy can make it into even the Windows kernel, and Microsoft's management of memory is not necessarily perfect. Many have found that putting the pagefile into a Ramdisk does indeed result in a performance increase, as long as you have a decent amount of memory.

I compiled a post which shows a collection of such users from a single forum's thread who have found that despite having massive amounts of RAM free, the pagefile is still being used:

https://www.overclock.net/threads/why-it-is-bad-to-store-the-page-file-on-a-ram-disk.1193401/post-23508589

6
  • 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 Feb 7, 2015 at 18:54
  • 1
    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! Jul 31, 2015 at 22:51
  • @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".
    – Twinbee
    Mar 31, 2018 at 1:04
  • 1
    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. Mar 31, 2018 at 19:18
  • 2
    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! Mar 31, 2018 at 19:22
3

If you have enough memory, the answer would be yes you can turn off swap. Swap was created to overcome the limitations of RAM and to make its use more efficient.

The question now is how much RAM is enough RAM? There is no universal answer for this and by nature systems are hungy on memory. Therefore, and unless you are running on a very specific and controlled environment don't turn off swap.

Any other kind of stunt like putting swap on RAM will just create an extra layer of complexity and spend memory that could otherwise be used directly.

3

Update for 2020 as requested by the poster

Several answers from 2014 do not apply anymore, and some were even incorrect at that time. What has changed:

  • Computers, operating systems and programs are now mostly 64-bit,
  • RAM is no longer limited (practically only by the motherboard) in size and is much cheaper,
  • SSD disks are everywhere and have become as reliable as hard disks.

The pagefile is still necessary, since all operating systems, before launching a program, take care to reserve enough swap space for totally swapping the program out in case its RAM is urgently needed. Reservation is not the same as allocating, as allocation will only occur if required.

However, with the large RAM of modern computers, swap is rarely done. Swapping is now more symptomatic of a rogue program that badly manages its memory.

As in my answer from 2014, the currently most important usage of the page-file is for containing the Windows crash dump file in case of a BSOD (crash). Without a pagefile, this information is not written out to a .dmp file when Windows is next booted up, so postmortem analysis becomes impossible.

Having the pagefile in RAM was always next to useless, since it will be lost in a crash or when the computer is turned off for hibernation.

As such, the pagefile is absolutely required and must reside on disk.

The appropriate size for the pagefile was once counseled to be double the RAM, but nowadays the same size is enough. Although RAM is now larger, with today's larger disks allocating a pagefile of this size is not a problem.

The accepted answer above gives as an example the mapping of a file to memory as taking up part of the physical RAM. This was never correct, as such a file is mapped to virtual memory, where blocks are brought into RAM only when and as they are referenced. Although the technique here is somewhat similar to swap, this does not use the pagefile.

0
2

Converting an OS that was designed at it's very core to not use swap is a lot harder than it sounds.

Modern Macs have a recovery partition - part of the main drive with a stripped-down OS that can repair or restore the main system. In the DVD-installer days they ran a custom process, the system now creates a RAMdisk for the swap partition as an installer can't be guaranteed to have working disk space available. The OS includes the needed frameworks to run the included maintenance software, which is identical to the utilities available after install. A lot less work for everyone.

Limiting the system to one application at a time means the ramdisk-swap basically never gets used, but the OS expects it to be there.

2

My system has 24GB's of RAM, for this reason, I disabled the pagefile to prevent wear on my SSD without having any issues. I recently created a RAM Disk, using 4GB's of my Memory to store Google Chrome Cache files, just to see if it would increase the performance of online Flash Player games, and general web surfing. I have see a marked increase in performance from this experiment. Since I had more space available on my RAM Disk, I enabled my pagefile and set both minimum, and maximum size to 1GB, and moved it to the RAM Disk. Although, I cannot say that there was any performance boost, my system seems to be running more stable.

1
  • 1
    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. Sep 4, 2015 at 10:14
0

Moving the pagefile to RAM is a ridiculous notion Just turn it off and by more RAM.

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).

Memory Management is handled by the CPU and whether the pagefile is on or off makes not one iota of difference to how pages are treated. It's transparent to Windows.

The page priority doesn't change, pages will be discarded just the same. Pagefiles are used by the CPU as secondary storage, not the OS. It's nothing more than level two cache fwhen level one (RAM) runs out.

A quick and very dirty example:, my machine has 16GB of RAM and no pagefile. 5 mins ago with 13GB in standby and only 2GB free, I loaded Fallout 4. The low priority pages were discarded as Fallout loaded.

Btw on a side note, the 2008 Technet Blog on Pushing Windows Memory Limits is very misleading - I would say to the point of deception. https://i.stack.imgur.com/wXkmi.png I'm dubious as too whether even Mark wrote it, but I hope not, as it would change my perspective of him.....

Fwiw there are gaping holes in the article which I'm dumfounded no one has picked on considering how often that blog has been refer

  • The pagefile and it's location are handled by Windows, the trapping of memory access to locations that have been paged out to disk would be caught by the CPU, but handed to the operating system to retrieve the page from disk and load it in.

Anyway here is one not so vague description:

Windows cannot reach higher addresses than the CPU - it's not possible.

No matter what the OS is capable of it still limited by the hardware it runs on.. because the OS is actually the CPU itself (internal registers).

OK, so pagefile is an area on the HDD which the CPU uses for extended physical address space when it can't physically or architecturally use more RAM.

On segmented x86 32bit architecture for example there are two 2GB segments of RAM.

One is allocated to the kernel. The other 2GB is for user mode. That's all the RAM the CPU can use with 32 DRAM pins, but a 32bit process has 4GB available so what to do. Well luckily the CPU can use secondary storage AKA the hard drive for storing the extra 2GB of pages. Because it has internal registers
The physical locations where virtual pages referenced by the process don't have to be stored in RAM. But they do have be stored somewhere by the CPU.

The CPU can't give all 4GB RAM to the app, but it can give it 4GB of address by using the HDD as secondary cache (which is all the HDD really is)

The pages are moved in and out of RAM through it's internal paging mechanism, but this is not the same as a pagefile. Paging always occurs....

The bottom line is really not that complicated. For the last 15 or so years many end users have been given the impression a pagefile is some integral part of the Operating System, it is not. It never has been. This misconception is partly fuelled by corporations like Intel and Microsoft.

RAM is a fast storage device, the Hard Drive is a slower storage device, so essentially RAM is level 1 cache, the Hard Drive is Level 2 (disregarding CPU cache for this analogy). Both can be accessed by the CPU.

If not enough RAM is available for the CPU to store the pages it needs to, the HDD can be used as an overflow. If there is plenty of RAM, then the PF is redundant.

Up until Core 2, Intel processors had a 32pin DRAM bus, and 32 registers meaning the CPU had access to 4GB of RAM, and 4GB of HDD space (pagefile). This is an architectural hardware limitation, not a Windows limitation.

The total available for processes was 3.5GB, because a page table takes up 512MB. Which is why 3.5GB shows up in Windows with Intel CPU's (up until Core 2). Add a GPU and even less is available.

Xeon could access a total of 32GB RAM, 64GB of Physical Space with HDD included (pagefile again). (This ^ covers PAE,-more to come with links added).

enter image description here http://www.windowsdevcenter.com/pub/a/windows/2004/04/27/pagefile.html

enter image description here

enter image description here

3rd screenshot source: System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.7

I intend to continue improving this answer and adding source material and relevant info. I'd like to achieve a balance between not enough information and too much technical information. Suggestions are welcomed. Please don't downvote just because it may not be written so well.

2
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – DavidPostill
    Jul 10, 2017 at 9:42
  • The CPU absolutely does not manage the page file. How could it without the OS sincepagefile.sys is for practical purposes just a normal file in the file system? How could the same CPU happily support Linux, OS X or Windows which all manage swapped memory in different ways on different files on different file systems?
    – PC Luddite
    Oct 8, 2022 at 13:58
0
@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. – 
Jason Wheeler
 Feb 21

Jason is exactly right. Now that we are all running 64 BIT memory servers, NO page file configurations are excellent for WEB servers, for example. And since Windows servers are EXTREMELY stable now, the risk is significantly reduced, ESPECIALLY if you are running the SDCARD/RAM scenario most high-end VM shops run: Conclusion: NO SWAPFILE servers configs, especially virtualized servers, are now a completely reasonable consideration. I mean, do you KNOW how much fast SDCARDs COST? I've been working in Windows for DECADES and I tell you I have used zero swap file servers over the years to solve many problems. Tell me the last time you had a BSOD? IMHO, we all should realize it's time to test zero swap file configs.

Please don't downvote just because it may not be written so well.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .