up vote 91 down vote favorite
34

I'm running Windows 7 on a dual core, x64 AMD with 8GB RAM.

Do I even need a pagefile?

Will removing it help or hurt performance?

Would it make a difference if this is a server or a desktop?

Does Windows 7 vs. Windows 2008 make a difference with a page file?

link|flag

79% accept rate
1  
I'm a little dismayed that Joel ranked on my question... laughing at somebody for even asking this question. At least he appreciated the answer it produced! :) – Jason Jun 25 '09 at 16:21
1  
I believe he laughed that this is thought condition that is common for the "geek" experience. As Jeff pointed-out, he blogged about exactly this too. We have all at one point or another believe we have exceeded some boundary (enough hardware or enough programming experience) where something no longer applies to us, usually we are wrong, but occasionally we are right. If the programmer (user) never got smarter than the language designer then we would still be programming in FORTRAN, LISP and COBOL. – Jim McKeeth Jun 25 '09 at 22:40
Actually... I think Joel laughed at Jeff too, about it. ;) Its all in good fun... happy to have made the podcast, even if indirectly! – Jason Jun 26 '09 at 1:18
4  
Jason, it definitely is a good question. That's why I took the time to carefully answer it! – quux Jun 26 '09 at 3:18

15 Answers

up vote 177 down vote accepted

TL;DR version: Let Windows handle your memory/pagefile settings. The people at MS have spent a lot more hours thinking about these issues than most of us sysadmins.

Many people seem to assume that Windows pushes data into the pagefile on demand. EG: something wants a lot of memory, and there is not enough RAM to fill the need, so Windows begins madly writing data from RAM to disk at this last minute, so that it can free up RAM for the new demands.

This is incorrect. There's more going on under the hood. Generally speaking, Windows maintains a backing store, meaning that it wants to see everything that's in memory also on the disk somewhere. Now, when something comes along and demands a lot of memory, Windows can clear RAM very quickly, because that data is already on disk, ready to be paged back into RAM if it is called for. So it can be said that much of what's in pagefile is also in RAM; the data was preemptively placed in pagefile to speed up new memory allocation demands.

Describing the specific mechanisms involved would take many pages (see chapter 7 of Windows Internals, and note that a new edition will soon be available), but there are a few nice things to note. First, much of what's in RAM is intrinsically already on the disk - program code fetched from an executable file or a DLL for example. So this doesn't need to be written to the pagefile; Windows can simply keep track of where the bits were originally fetched from. Second, Windows keeps track of which data in RAM is most frequently used, and so clears from RAM that data which has gone longest without being accessed.

Removing pagefile entirely can cause more disk thrashing. Imagine a simple scenario where some app launches and demands 80% of existing RAM. This would force current executable code out of RAM - possibly even OS code. Now every time those other apps - or the OS itself (!!) need access to that data, the OS must page them in from backing store on disk, leading to much thrashing. Because without pagefile to serve as backing store for transient data, the only things that can be paged are executables and DLLs which had inherent backing stores to start with.

There are of course many resource/utilization scenarios. It is not impossible that you have one of the scenarios under which there would be no adverse effects from removing pagefile, but these are the minority. In most cases, removing or reducing pagefile will lead to reduced performance under peak-resource-utilization scenarios.

Some references:

dmo noted a recent Eric Lippert post which helps in the understanding of virtual memory (though is less related to the question). I'm putting it here because I suspect some people won't scroll down to other answers - but if you find it valuable, you owe dmo a vote, so scroll!

link|flag
1  
Prepare for a rush of upvotes--this was mentioned in the podcast (blog.stackoverflow.com/2009/06/podcast-59). +1 from me. – mmyers Jun 24 '09 at 18:40
18  
For Jeff and Joel: it rhymes with "ducks" – quux Jun 24 '09 at 23:48
2  
On Solaris it was/is even more involved. The swap file is mirroed in a ram disk like tmpfs so the memory is always almost full - but it is apparently provable that this is the optimal strategy. – mgb Jun 25 '09 at 19:40
2  
Thanks for the plug! – dmo Jun 26 '09 at 16:37
1  
I have long believed that, instead of allowing Windows to manage my page file size, I should set it to a fixed amount (e.g. min 2GB, max 2GB), because letting it grow and shrink can cause fragmentation problems. Is that good thinking, or should I follow your first line and let Windows handle everything? – John Fouhy Jul 29 '09 at 3:26
show 6 more comments
up vote 40 down vote

Eric Lippert recently wrote a blog entry describing how Windows manages memory. In short, the Windows memory model can be thought of as a disk store where RAM acts as a performance-enhancing cache.

link|flag
up vote 18 down vote

As I see from other answers I am the only one that disabled page file and never regreted it. Great :-)

Both at home and work I have Vista 64-bit with 8GB of RAM. Both have page file disabled. At work it's nothing unusal for me to have few instances of Visual Studio 2008, Virtual PC with XP, 2 instances of SQL Server and IE8 with a lot of tabs working together. I rarely reached 80% of memory.

I'm also using hybrid sleep every day (hibernation with sleep) without any problem.

I started experimeting with it when I had XP with 2GB of RAM and I really saw the difference. Classic example was when icons in Control Panel stopped showing itself one after one, but all at once. Also Firefox/Thunderbird startup time increased dramatically. Everything started to work immidately after I clicked on something. Unfortunately 2GB was too small for my applications usage (VS2008, VPC and SQL Server), so I enabled it back.

But right now with 8GB I never want to go back and enable page file.

For those that are saying about extreme cases take this one from my XP times.
When you are trying to load large Pivot Table in Excel from SQL query, Excel 2000 increases its memory usage pretty fast.
When you have page file disabled - you wait a little and then Excel will blow up and system will clear all memory after him.
When you have page file enabled - you wait some time and when you'll notice that something is wrong you can do almost nothing with your system. Your HDD is working like a hell and even if you somehow manage to run task manager (after few minutes of waiting) and kill excel.exe you must wait minute or so until system loads everything back from page file.
As I saw later, Excel 2003 handles the same pivot table without any problem with page file disabled - so it was not a "too large dataset problem".

So in my opinion, disabled page file even protects you sometimes from poorly written applications.

Shortly: if you are aware of your memory usage - you can safely disable it.

Edit: I just want to add that I installed Vista SP2 without any problem

link|flag
I've had my pagefile disabled, and regretted it the moment I really used my memory. So be happy you have more memory than you need. – Sam Jul 22 '09 at 9:45
3  
+1, "me too" :-). Same story - 8GB memory, Vista x64, running Visual Studio with ReSharper + SQL Server Express + IIS + 1-2 virtual machines (each with 1500MB memory) + bunch of utilities - never had a problem. – Milan Gardian Sep 29 '09 at 20:17
1  
I love it how everyone is saying "Microsoft has spent many hours thinking about this problem, so don't mess with it", yet completely ignore real world experiences. I've had the paging file disabled since XP and never regretted it. It's like the computer got an injection of awesome. – AngryHacker Oct 20 '09 at 6:36
Do your XP virtual machines also have pagefiles disabled? – maxwellb Apr 13 at 22:57
@mpbloch No, because I always set VM memory to the lowest required by it's usage. – SeeR May 10 at 18:16
show 1 more comment
up vote 14 down vote

You may want to do some measurement to understand how your own system is using memory before making pagefile adjustments. Or (if you still want to make adjustments), before and after said adjustments.

Perfmon is the tool for this; not Task Manager. A key counter is Memory - Pages Input/sec. This will specifically graph hard page faults, the ones where a read from disk is needed before a process can continue. Soft page faults (which are the majority of items graphed in the default Page Faults/sec counter; I recommend ignoring that counter!) aren't really an issue; they simply show items being read from RAM normally.

Perfmon graph

Above is an example of a system with no worries, memory-wise. Very occasionally there is a spike of hard faults - these cannot be avoided, since hard disks are always larger than RAM. But the graph is largely flat at zero. So the OS is paging-in from backing store very rarely.

If you are seeing a Memory - Pages Input/sec graph which is much spikier than this one, the right response is to either lower memory utilization (run less programs) or add RAM. Changing your pagefile settings would not change the fact that more memory is being demanded from the system than it actually has.

A handy additional counter to monitor is PhysicalDisk - Avg. Queue Length (all instances). This will show how much your changes impact disk usage itself. A well-behaved system will show this counter averaging at 4 or less per spindle.

link|flag
up vote 10 down vote

I've run my 8GB Vista x64 box without a pagefile for years, without any problems.

Problems did arise when I really used my memory!

Three weeks ago, I began editing really large image files (~2GB) in Photoshop. One editing session ate up all my memory. Problem: I was not able to save my work since PS needs more memory to save the file!

And since it was PS itself, who was eating up all the memory, I could not even free memory by closing programs (well, I did, but it was too little to be of help).

All I could do was scrap my work, enable my pagefile and redo all my work - I lost a lot of work due to this, and can not recommend disabling your pagefile.

Yes, it will work great most of the time. But the moment it breaks might be painful.

link|flag
you should save more often :D in order to minimize the damages – alexandrul Dec 10 '09 at 5:19
easy to say, when saving does take several minutes, this is a pita. – Sam Dec 21 '09 at 9:46
up vote 8 down vote

The best answer I can think of is that under a normal load you may not use up the 8GB, but it is the unexpected loads where you will run into trouble.

With a page file, the system will at least run slowly once it starting hitting the page. But if you remove the pagefile it will just die (from what I know).

Also 8GB seems like a lot now, but a few years down the line it might be considered the minimum amount of memory for a lot of software.

Either way - I would recommend keeping at least a small pagefile; but others please correct me if I am off-base.

link|flag
4  
I'd go a bit further and not cap the page file. That's not really improving things. Let windows do it...they know better. – Michael Haren Jun 24 '09 at 19:37
1  
Just tried to use Media Player Classic to load a 6GB mkv file. It ran me out of my RAM and pagefile memory. Went back to VLC pretty quick. +1 for the "you never know what you'll run into". Eventually MPC crashed and my RAM was restored, but what if you get a DLL in third party software with a memory leak? You will have a lot more mileage if you have some disk-backed memory to help you out. – maxwellb Apr 13 at 23:00
up vote 7 down vote

While the answers here covered the topic quite well, I will still recommend this read:

http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx

He talks about PF size almost at the end:

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

I really like Mark's articles.

link|flag
up vote 3 down vote

You didn't mention if it's a 64 bit edition of Windows, but i guess yes.

Pagefile serves for many things, including generating a memory dump in case of BSOD (Blue Screen of Death).

If you don't have pagefile, Windows won't be able to page out to disk if there isn't enough memory. You may think that with 8GB you won't reach that limit. But you may have bad programs leaking memory over time.

I think it won't let you go hibernate/standby without a pagefile (but i didn't try yet).

Windows 7 / 2008 / Vista doesn't change the use of page file.

I saw one explaination from Mark Russinovich (Microsoft Fellow) explaining that windows can be slower without page file than wih a page file (even with plenty of ram). But i can't find back the root cause.

Are you out of disk space ? i would keep a minimum of 1GB to be able to have kernel dump in case of BSOD.

link|flag
Do you mean this? blogs.technet.com/markrussinovich/archive/2008/11/17/… If so, his advice is lame. He says page file will increase performance because if would give more ram to other apps. True, if you don't have much ram. But if you have more than enough, page file is never faster. – Pyrolistical Jun 10 '09 at 20:18
it was in a sysinternal video with Salomon. It had something to do with kernel page pool – Mathieu Chateau Jun 10 '09 at 21:19
You can't post an "answer" when you have no idea: I have a Windows Vista 32-bit laptop with 4GB of RAM and I put it into standby all the time. Can you at least restrict yourself to supplying answers to questions you actually know answers to? – PP Jan 15 at 17:50
up vote 2 down vote

The only person that can tell you if your servers or workstations "need" a pagefile is you, with careful use of performance monitor or whatever it's called these days. What apps are you running, what use are they seeing, what's the highest possible memory use you could potentially see?

Is stability worth possibly compromising for the sake of saving a minute amount of money on smaller hard disks?

What happens when you download a very large patch, say a service pack. If the installer service decides it needs more memory than you figured to unpack the patch, what then? If your virus scanner (rightly) decides to scan this very large pack, what sort of memory use will it need while it unpacks and scans this patch file - I hope the patch archive file doesn't contain any archives itself because that would absolutely murder memory use figures.

What I can tell you is that removing your pagefile has far higher probability of hurting than helping. I can't see a reason why you wouldn't have one - I'm sure that there might be a few specialist cases where I'm wrong on that one but thats a whole other area.

link|flag
up vote 2 down vote

Your total memory available is your pagefile + actual memory.

The key question is whether your anticipated total memory usage for all apps and the operating system usage approaches 8 GB. If your average mem usage is 2 GB and your max memory usage is only 4 GB then having a page file is pointless. If your max memory usage is closer to 6-7 Gb or greater than it's a good idea to have a page file.

PS: Don't forget to allow for growth in the future!

link|flag
Don't you mean total memory potentially available? Most paging systems keep snapshot page copies. – Xepoch Nov 30 '09 at 5:20
up vote 1 down vote

This is antidotal, but we run a Windows Server 2003 Terminal Server for about 20 users, with 10-15 logged on at time and have 8GB of RAM. We do not run with a pagefile and our server runs faster than it did from before. This obviously is not a solution for everything but we have run like this for 2 years now, and have had no issues that I am aware of.

link|flag
up vote 1 down vote

It seems a lot of severely limited people have an opinion on this subject but have never actually tried running their computer without a page file.

Few, if nearly none, have tried. Even less seem to know how Windows treats the pagefile. It doesn't "just" fill up when you run out of physical RAM. I bet most of you didn't even know that your "free" RAM is used as a file cache!

You CAN get massive performance improvements by disabling your page file. Your system WILL be more susceptible to out-of-memory errors (and do you know how your applications respond in that scenario - for the most part the OS just terminates the application). Start-up times from standby or long idle periods will be far snappier.

If Microsoft actually permitted you to set an option whereby the pagefile ONLY gets used when out of physical RAM (and all the file buffers have been discarded) then I would think there was little to gain from disabling the pagefile.

link|flag
up vote 0 down vote

I'm sure you are somehow better off with a pagefile but we have lots of W2K8 servers with 8GB and no pagefile, we're not pushing them too much but we've not ran into problems with them in this config. Of course it all depends on what you intend to do with it.

link|flag
1  
wow, wonder if whoever down-voted this would care to explain??? – Chopper3 Dec 14 '09 at 17:51
I'd downvote this because whatever the performance benefits of having no pagefile, on a server you very much need crash dump enabled, even if it's only a kernel dump (recommended). If you have a driver update or a patch causing a bluescreen, you will be running in circles without that dump. – dmoisan Feb 22 at 13:57
speak for yourself, we have MS-issued fixed builds for our servers, if they're going to crash they dump to flash-based HP iLO logs so we categorically DON'T need our pagefiles switched on - as I say speak for your own narrow range of experiences. – Chopper3 Feb 22 at 14:34
up vote -1 down vote

"Removing pagefile entirely can cause more disk thrashing."

No. When the paging file is disabled, if you load a program that requires more memory than is available, windows will issue an "Out of Virtual Memory" error and the operation will be cancelled.

Simple as that. No "additional disk thrasing."

link|flag
Memory is not only used for programs, but for cache, too. This cache-Memory is what the post is referring to, and this will be freed when a program requires memory. But sometimes it would be better to page out non-used-programs than to clear the cache. In these cases, disabling paging will increase disc trashing. You should have really read his comment and the details, to understand these details. – Sam Dec 21 '09 at 9:54
"no additional disk thrashing" is incorrect, James. The scenario I described in the fifth paragraph of my answer shows precisely how no pagefile can indeed lead to disk thrashing. What may have escaped you is that the lack of a pagefile does not stop all paging from occurring. – quux Jun 11 at 5:45
up vote -3 down vote

According to MS 64 bit XP can access 128 g bytes of RAM. If you can find a board to support that much memory (3-2010). So why drive your HD crazy swapping out "stuff" from MS, who get rich when their OEM's sell services which fix HD failures? They are the guys causing HD failures. At least put your stuff on a separate HD or maybe a "big" flash.

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.