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

97

35

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

Posted 2014-09-11T08:34:47.017

Reputation: 4 237

57Having 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 – 2014-09-11T14:47:51.630

14

In makes some sense to do this on Linux in some cases where the ram disk hosting the swap file is actually compressed. See: http://en.wikipedia.org/wiki/Zram. However I don't think Windows has such a feature available to it.

– Matt H – 2014-09-11T21:10:57.733

2The answer is yes but there are plenty of nonbelievers. – user541686 – 2014-09-12T06:18:39.940

14@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 – 2014-09-12T22:07:44.707

2I 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- – 2014-09-13T02:24:02.793

1memory 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. – lesmana – 2014-09-13T09:53:07.830

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. – Neolisk – 2014-09-14T11:34:06.127

1Why aren't you installing the game on the ramdrive and running it from there? – Sun – 2014-09-18T05:19:02.453

1

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

– Dan W – 2015-02-07T01:05:14.140

@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. – usr – 2015-02-07T09:02:19.037

1I guess it only takes to try it out to find out if it works for you or not. – user1306322 – 2015-02-07T09:08:15.510

1@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. – Dan W – 2015-02-07T15:20:11.197

@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. – usr – 2015-02-07T15:27:48.387

@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. – Dan W – 2015-02-07T15:30:08.690

@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. – usr – 2015-02-07T15:33:21.100

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 – 2015-11-30T00:00:27.953

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 – 2015-11-30T00:01:33.330

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. – Sam Watkins – 2015-11-30T00:08:04.793

possible duplicate: Windows Swap (Page File): Enable or Disable?

– Ƭᴇcʜιᴇ007 – 2016-05-04T16:14:47.783

Answers

134

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.

David Schwartz

Posted 2014-09-11T08:34:47.017

Reputation: 58 310

1

Wasn't me, but read this: http://www.overclock.net/t/1193401/why-it-is-bad-to-store-the-page-file-on-a-ram-disk

(specifically, the part about the commit limit, and the email comment from Mark Russinovich, who is an expert on the topic).

– spudone – 2014-09-11T17:28:22.490

3David 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 – Mattisdada – 2014-09-12T04:37:15.133

@spudone: Where did David mention a RAM disk? – Groo – 2014-09-12T10:19:53.887

@Groo Last paragraph: "There's no point in trying to put a paging file in RAM. ..." – None – 2014-09-12T10:21:21.447

@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). – Groo – 2014-09-12T10:25:49.570

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. – viraptor – 2014-09-12T15:11:28.340

1@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. – David Schwartz – 2014-09-12T15:51:22.473

9I 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 – 2014-09-12T16:27:31.717

6I 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.) – Dan is Fiddling by Firelight – 2014-09-12T21:06:02.157

2@DanNeely: +1. One of the Warhammer games does it too. :) – Neolisk – 2014-09-14T11:35:29.447

3This 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. – Jason Wheeler – 2015-02-20T08:36:15.690

2@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.) – David Schwartz – 2015-02-20T08:53:09.330

1@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? – Jason Wheeler – 2015-02-20T20:50:27.433

2@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. – David Schwartz – 2015-02-20T23:05:51.370

1@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 – 2015-02-21T11:22:18.177

9@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 – 2015-02-21T11:27:32.050

@Bigwheels I don't come to that conclusion. Read my answer again. – David Schwartz – 2015-02-22T02:21:23.447

3@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. – David Schwartz – 2015-06-03T18:51:23.710

2@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. – Jason Wheeler – 2015-06-04T15:34:46.957

2@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.) – David Schwartz – 2015-06-04T16:47:01.643

1@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 – 2015-07-10T23:23:53.897

3The 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? – Fred Hamilton – 2015-07-10T23:28:02.633

2@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. – David Schwartz – 2015-07-12T10:43:46.997

1@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 – 2015-07-12T14:37:27.707

2I 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. – Fred Hamilton – 2015-07-12T14:43:09.733

3@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. – David Schwartz – 2015-07-13T00:27:32.987

2I 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 – 2015-07-13T04:49:46.353

2I 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 – 2015-07-13T05:00:02.283

5I 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. – Fred Hamilton – 2015-07-13T05:08:39.560

2@FredHamilton So your complaint is with what I didn't say? – David Schwartz – 2015-07-13T18:46:53.507

5I 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. – Fred Hamilton – 2015-07-13T20:04:59.113

And what about having a very slow HDD? It could cause a bottleneck in the entire system – BamsBamx – 2016-02-17T16:51:18.283

2@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. – David Schwartz – 2016-02-17T18:18:56.140

@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: https://tweakhound.com/2011/10/10/the-windows-7-pagefile-and-running-without-one/ 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 – 2017-06-20T00:40:09.300

1...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. – Jamie Hanrahan – 2017-06-20T00:43:36.403

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). – Sergey.quixoticaxis.Ivanov – 2018-03-12T01:19:15.717

@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. – David Schwartz – 2018-03-12T06:04:40.153

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. – Nick Sotiros – 2018-03-12T06:55:18.553

1@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. – David Schwartz – 2018-03-12T08:46:47.277

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 – 2018-03-12T09:45:29.457

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 – 2018-03-12T09:46:05.463

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. – Sergey.quixoticaxis.Ivanov – 2018-03-12T09:58:22.347

@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. – David Schwartz – 2018-03-12T16:30:56.290

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. – Sergey.quixoticaxis.Ivanov – 2018-03-12T17:38:21.970

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. – David Schwartz – 2018-03-13T04:41:50.947

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? – Sergey.quixoticaxis.Ivanov – 2018-03-16T23:56:00.427

@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. – David Schwartz – 2018-03-17T20:26:45.127

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. – Sergey.quixoticaxis.Ivanov – 2018-03-17T23:45:42.373

@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? – David Schwartz – 2018-03-18T01:03:17.543

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 (https://www.tweakhound.com/2011/10/10/the-windows-7-pagefile-and-running-without-one/). 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 – 2018-03-18T01:55:20.613

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 – 2018-03-18T11:28:20.343

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. – Sergey.quixoticaxis.Ivanov – 2018-03-18T11:31:53.363

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. – Gabriel L. Oliveira – 2018-06-29T15:56:54.023

"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. :) – Cherry – 2019-01-18T16:49:18.267

32

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

Posted 2014-09-11T08:34:47.017

Reputation: 6 417

1"One thing to consider (and you mentioned it already) - you need to have enough RAM to accommodate all the programs you are executing" just to give an example of this: my netbook has only 2GB and swap disabled (linux, but that doesn't matter too much). The only thing I can't do at all is video editing. – Chris H – 2014-09-11T12:37:57.267

@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) – Art Gertner – 2014-09-11T12:43:00.087

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. – Chris H – 2014-09-11T12:51:35.160

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 – 2014-09-11T13:19:28.450

9This 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. – David Schwartz – 2014-09-11T15:38:16.607

17@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. – Art Gertner – 2014-09-11T16:00:57.273

11

@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 – 2014-09-11T16:27:01.497

1I 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. – Zan Lynx – 2014-09-12T01:15:11.567

4The 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. – Anaksunaman – 2014-09-12T05:49:04.553

1@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 – 2014-09-12T15:48:47.737

@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 – 2014-09-12T15:49:11.897

1

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

– Dan W – 2015-02-07T15:26:09.760

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 – 2015-07-31T23:37:19.597

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 – Royi Namir – 2016-08-05T18:39:16.830

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

Posted 2014-09-11T08:34:47.017

Reputation: 4 199

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? – user1306322 – 2014-09-11T09:02:33.283

2Correct. 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 – 2014-09-11T09:05:23.577

2Swapfiles 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. – None – 2014-09-11T13:44:58.650

6@Mast That's a gross oversimplification. Swapfiles are also there to permit efficient use of RAM. – David Schwartz – 2014-09-11T16:34:20.193

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. – None – 2014-09-11T20:45:43.757

8

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

Posted 2014-09-11T08:34:47.017

Reputation: 181

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 – 2014-09-12T08:36:58.063

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. – Jamie Hanrahan – 2018-04-03T20:34:26.087

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.

harrymc

Posted 2014-09-11T08:34:47.017

Reputation: 306 093

4

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.

user127379

Posted 2014-09-11T08:34:47.017

Reputation: 179

2From 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 – 2016-07-06T00:32:27.553

4

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:

http://www.overclock.net/t/1193401/why-it-is-bad-to-store-the-page-file-on-a-ram-disk/290#post_23508589

Dan W

Posted 2014-09-11T08:34:47.017

Reputation: 420

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 – user1306322 – 2015-02-07T18:54:05.407

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 – 2015-07-31T22:51:39.630

@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". – Dan W – 2018-03-31T01:04:16.460

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 – 2018-03-31T19:18:48.857

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 – 2018-03-31T19:22:30.820

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 – 2018-04-01T00:33:15.800

3

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

Posted 2014-09-11T08:34:47.017

Reputation: 1 591

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

Posted 2014-09-11T08:34:47.017

Reputation: 251

2

If you have enough memory, the answer would be yes you can turn off swap. Swap was create 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

Posted 2014-09-11T08:34:47.017

Reputation: 268

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

Posted 2014-09-11T08:34:47.017

Reputation: 161

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. – Jamie Hanrahan – 2015-09-04T10:14:51.850

1

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.

Robert Fischer

Posted 2014-09-11T08:34:47.017

Reputation: 37

Comments are not for extended discussion; this conversation has been moved to chat.

– DavidPostill – 2017-07-10T09:42:59.553