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?

user1306322
  • 4,866

15 Answers15

149

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.

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:

Art Gertner
  • 7,429
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.

Peter
  • 4,630
10

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.

demonkoryu
  • 201
  • 1
  • 5
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.

harrymc
  • 498,455
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.
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

JamesRyan
  • 1,681
5

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

Twinbee
  • 570
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.

harrymc
  • 498,455
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.

nsn
  • 278
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.

peter
  • 251
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.

Michael
  • 229
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.sstatic.net/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.

Giacomo1968
  • 58,727
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.

0

The answer is absolutely YES. I've been running 2 machines (64 GB RAM and 32 GB RAM) for several years without any swap file whatsoever. For 99.95% of use cases, the existence of swap file will only slow down the system because all content eventually swaps out of RAM (even if you have 64 GB RAM and 48 GB of it unused - the system is so "SMART", it'll increase empty unused RAM to 56 GB - because that is EXACTLY the reason why you bought the RAM - right ? To keep it unused and empty and force loading from slower HDD/SSD!).

This way, I can come back to the computer after a week, and no content has been swapped out. Even with SSD (Smmsung 990 PRO) the delay of swapping is noticeable. But when there is no swap file, there is no delay as it's all in RAM. Who'd have thought !

For reference, this is what I keep in RAM (around 24 GB): Visual Studio 2022 Visual Studio 2019 3dsmax Spotify Edge Browser Notepad++ TotalCommander Paint Shop Pro DAW SW

I have recently put 32 GB into an old laptop that still had a 5,400 RPM drive. After 2 days, all apps got swapped out (Win 11 Pro). It was EXTREMELY noticeable that it had to be swapped back in (for 3-10 seconds after AltTab) from HDD (even Notepad++ with few text files !!!). But, the OS fulfilled the No 1 priority - 90% of RAM was unused and empty ! YES ! Good JOB, MSFT !

Obviously, the moment I turned the swap file off, even after leaving PC on for 5 days, there was no swapping when Alt-Tabbing.

The only app that keeps leaking memory is MSFT Edge. After 5-7 days it balloons to 10 GB, so you have to restart it. But, that was a much worse problem with swap file, this way, it closes and reopens instantly (not 15-30 seconds with swap file).

So, if you can live with the fact, that you actually use the RAM you bought (What an insane concept!), and it doesn't deeply offend you, it's absolutely safe to do so.

And if you do start having crashes and need Diagnostic tools (dump file), you can always temporarily reenable it, debug whatever is causing crashes, and then get back to no swap file usage.

3D Coder
  • 131
  • 1