43

I am using Windows 7 64 bit with 8G ram. After some use, I feel Windows is getting sluggish. The drive is thrashing. When I look at the resource monitor and disk activity, I see a few instances of use of the page file (c:\pagefile.sys). I check the physical memory and I see about 2.3G available memory and 700M free memroy.

Why doesn't Windows use more of the free memory and less of the page file? Does it need to leave some x amount of free ram, how much would that be? Is it a percentage of physical ram?

My plan is get more ram and an SSD for the main drive. Meanwhile I am suffering from slow performance.

6
  • 1
    Just because it is writing/reading to the page file does not mean it us using it, it may just be updating it so it can dump the memory quicker if there is a sudden demand. I recommend running performance monitor or do a deep diagnostic and seeing what is causing the sluggishness. Aug 3, 2012 at 17:49
  • Having more than 8GB of RAM will not increase performance in 99.(9)% of cases. Have you stuffed your mobo full of cheap low frequency/high latency RAM chips? Replacing them would be a better idea than adding more.
    – kotekzot
    Aug 3, 2012 at 18:41
  • 3
    @kotekzot That depends. I've generally found RAM latency to be somewhat negligible in most bottlenecks. If he has enough memory that he's not having to wait for applications to be paged in when he alt-tabs through all of them, then the next biggest bottleneck by several orders of magnitude is almost always the harddrive, and an SSD will fix that right up. Aug 3, 2012 at 18:46
  • @if I have more ram, I can put the page file in a ramdisk which is much faster than HD access. It's a Dell laptop workstation level so I am sure the components are not cheap. I am aware that laptops have slower hard drives and IO subsystsem than desktops. Aug 3, 2012 at 23:06
  • 1
    Please don't put your page file on a RAMdisk. That will only make the system incur more page faults. Yes, if they're to the pagefile-on-RAMdisk they will be resolved more quickly than if it had gone to a real disk, but not having them at all is still far faster; also, many of the increased page faults will be to mapped files, and those will not be helped by the RAMdisk at all. Jul 30, 2014 at 8:54

6 Answers 6

34

First, don't place your page file on an SSD. While SSDs have gotten better about wear leveling, the page file is written to frequently and it will degrade your SSD much faster than general use.

What a lot of people don't understand is that windows never really has free memory. There's a few MBs which are kept free for burst demands, but otherwise, the difference between active in-use application memory and the total memory is generally consumed by what is known as "standby" memory.

System memory

These are memory pages which can be dumped if needed (standby memory is a great, big cache), so from an application standpoint, it's available, but they are not by any means not being used. Usually, they function as disk cache, or a pagefile cache.

Windows' goal is to keep the data most likely to be used in this standby cache, based on usage patterns. To use a contrived example, let's compare the relative value of the private memory of a program like Windows Update (usually configured to run once a week), over the caching the contents of your desktop in this standby memory:

For a good majority of the time, Windows Update is sleeping. It's holding up memory and for the most part, doing absolutely nothing of value with it while it's waiting for the schedule to come around. The contents of your desktop folder on the other hand, might be queried constantly, especially if you like to save files to it.

In this case, what Windows will do is page out the memory allocated to Windows Update (even though memory isn't "full", and use the space made available in RAM to cache the contents of your desktop. This results in better performance for you.

Windows is making thousands of these decisions and managing a disk cache for hundreds of files being constantly written to by background services while trying to balance this with memory demands of active applications. Sometimes it gets it wrong for a moment, and we might have to wait for it to page data back into memory when we switch to an application that's been sleeping in the background for a while. But what you have to think about is if it had kept that application completely in memory, how many other applications would in turn be bogged down waiting for disk writes and reads to complete, or themselves be forced to page out? What if those were applications you were using in the meantime?


Applications frequently allocate memory pages which are used very rarely, such as start-up code (used once and then not needed), shut-down code (used once and then not needed), or update code. It's not practical to keep all this in memory when there are much more important uses, so once Windows identifies sections of code that haven't been needed for the current operation of an application, it happily pages out those sections to the pagefile, even if it technically could retain them in memory.

(And actually, depending on the applications, systems might frequently allocate more memory than they actually have, expecting most of it to wind up paged out. If you're looking at a detailed memory breakdown, the "Commit" or "Commit" charge is how much memory Windows has allocated to various applications. The pagefile is used to provide guarantees for this memory, even if it doesn't have enough physical RAM to cover it.)


I just noticed you did make a distinction between available and free memory in your question; My apologies if you feel lectured and already knew the difference. Ideally, free memory is always 0. However, while standby memory is memory that can be released, it's not always memory that can be released quickly. If I try to write a 1GB file to disk, windows is going to stick it in a disk cache in memory if it can, and then slowly write it out to the harddrive in the background. If an application needs to request 50MB of additional memory, but none is available because this huge disk cache is still being flushed out, then the application will hang until it's available. Keeping a small buffer on hand allows the system to resolve this issue with minimal lag from the user's standpoint. You might also wind up with larger-than-normal buffers if Windows just emptied part of the standby cache or released a lot of in-use memory, but hasn't filled it with new cache data yet.

43
  • 6
    @FrankComputer See the screenshot I posted for my 8GB work system: 6300MB in-use, 1700MB standby disk/cache, 42MB free. Looking at my home system (32GB memory), you're actually correct, but just at the wrong threshold: 9.2GB in-use, 14.5GB disk cache, 8.6GB free. You'll have free memory if windows has simply run out of things to cache, but that threshold is pretty high. Windows is not constantly swapping because disk cache is not swap space - it's passively cached when files are requested and not in the cache. You don't notice the times that it pulls from the cache and there's no HDD activity. Aug 3, 2012 at 19:38
  • 8
    @FrankComputer: If your system is performing well, it's not because of the free memory. Free memory is memory the system is not using, and it can have no more effect on performance than memory sitting on your desk. The only way to improve performance with memory is to use it, so if it's free, it's not being used to improve performance. Making more memory free means using less, making performance worse. Aug 3, 2012 at 22:47
  • 1
    @Tony_Henrich Disabling the page file is bad. Very bad. (Moving the pagefile to a ramdisk is effectively the same as disabling it. Windows is unable to move data it doesn't need immediately out of memory). Many programs request memory that they do not immediately need, but might need in the future. Usually, windows allocates this memory on the page file, and it does nothing. For example. MSSQL server allocates 8GB of ram when it starts up. Even for 0 databases. Just because. If you put your pagefile on a ramdisk, you will waste considerable amounts of RAM that could otherwise be used for cache Aug 4, 2012 at 5:41
  • 1
    @Tony_Henrich Currently, windows is optimally managing your pagefile and your RAM, given how you use your system. The only improvements you can make upon it are such: Add more memory, or move your OS to an SSD. Messing with your pagefile will degrade your overall system performance at best, or affect your system stability at worst. Aug 4, 2012 at 5:53
  • 2
    I upgraded my SSD to a larger and faster one on my home computer. Upgrades will happen before an SSD breaks down. SSDs are getting cheaper per SSD, faster and larger. So this frequent argument about their wear is ought to stop at some point because it won't be relevant anymore. Aug 6, 2012 at 5:00
4

It's called planning ahead.

Writing memory pages to the pagefile when there is still plenty of RAM is a good thing. As soon as a program requests more memory than there is free, the OS can start clearing out space as soon as possible. Better to prepare now than later.

If the OS were to wait around, then you run into a performance bottleneck. If a program asks for more memory than is available, now you have to wait until the OS writes out changed memory block, and then free them up.

4
  • With 16G+ and with light programs, the times when a program asks for more memory than what is free is much less than the frequent use of the page file. So for those cases, it's better to use some of the free memory and less of the page file. There's no one solution that fits all cases. Aug 6, 2012 at 5:03
  • 1
    I don't think you get it. It doesn't have to be one or the other. Windows can write to free memory and write to the pagefile. It isn't like writing to the page file or writing to memory.
    – surfasb
    Aug 9, 2012 at 3:26
  • 1
    But by trying to plan ahead, isn’t Windows potentially filling the HDD’s/SDD’s on-chip cache—making concurrent file writing/loading operations slower? This pre-swapping of RAM does sound like a good idea, but it seems like it incidentally puts load on the system at bad times.
    – binki
    Apr 30, 2015 at 16:32
  • 1
    @binki: Yes, it does interfere with disk read/write times, but if I recall, they're using a lower priority, so other read-writes should go first in general. Jun 5, 2016 at 19:03
4

There is a tool to set the disk-cache by SysInternal.

cacheset.exe

You can find it here:

http://technet.microsoft.com/en-us/sysinternals/bb897561.aspx

3

I have had page file turned off for the last 7 years. Actually it's the first thing I do after fresh install. Never had any problem with it. (Actually I had one - game called "titan quest" performed a very stupid check at startup so I created a 4 MB pagefile only to make it happy and turned PF back off later). As for the original question. Windows uses our RAM for disk I/O cache. For some reason it thinks the disk cache is equally important to the active programs code and data. And there's no way to limit disk cache size. It's there by design and we can't do anything about it... Oh, wait! We can! Just turn the pagefile off. Running applications that are heavy on RAM? Buy more RAM or close one app before launching another. You can use Process Explorer to see how much memory is used at any given moment. Personally I have 8 GB RAM both at work (vmware + virtualbox + eclipse + firefox + delphi + adobe premiere + skype + more background programs ) and at home (heavy gaming) and can't remember when was the last time I saw the "low on memory" warning.

16
  • 1
    Getting rid of the pagefile will not turn off disk caching. May 25, 2016 at 2:18
  • 1
    You wrote: "[Disk cacheing] is there by design and we can't do anything about it. Oh wait! We can! Just turn the pagefile off." Well, turning the pagefile off doesn't do anyting about disk cacheing, so what are you saying? It's a stupid idea anyway, as it forces the OS to keep all private commit in RAM forever once it's been touched. This makes less room for mapped virtual memory (like code), so that stuff has to be paged more. The proactive disk cache (superfetch) uses what's left over after all of the above, so it doesn't increase paging of either. May 25, 2016 at 15:57
  • 1
    I never said (or thought) that turning off the pagefile was your idea, so I wasn't saying anything about "your idea". Oh, while I"m here: "For some reason [Windows] thinks the disk cache is equally important to the active programs code and data" is flatly wrong. Superfetch only uses pages that are on the Standby list and hence already part of "available" RAM; it does not take pages from programs' code and data. And those pages remain available, i.e. immediately available for programs' code and data, even after they contain cached data from files. May 25, 2016 at 20:43
  • 1
    I'm not saying anything of the sort. (Where are you getting this?) I am saying, though, that Windows never pages anything out to make room for disk cache. On the contrary, the cache uses pages that are not currently parts of processes and would therefore otherwise be wasted. Such RAM remains immediately available to code and data that needs it for paging stuff in, so it is not "used up" by the cache, merely "borrowed". So the cache does not reduce the amount of code and data that can be paged into, or kept in, RAM. Ref: Windows Internals by Solomon, Russinovich, and Ionescu. May 26, 2016 at 20:45
  • 1
    I've already replied in DA's answer. But what you just said isn't what he said. He said that Windows will page out long-inactive processes (true). And he also said that the disk cache might use the pages freed thereby (also true). But that doesn't mean the disk cache is necessarily taking precedence. The disk cache only uses those pages if nothing else of higher priority needs them. A huge amount of testing has demonstrated that this is a good tradeoff. May 27, 2016 at 8:34
1

The arguments (here and here) for keeping and using the page file even if there is enough RAM are:

  • Even if there is free memory now, the machine may run out of memory later. Better to drop little used parts of memory to disk in advance.
  • There is also "standby" memory that appears as free but is actually used for disk caching. It is also important for performance, better to have some.
  • If you run out of RAM with the page file disabled, it is the hard crash.
  • While 2, 4, 16 or any other number of Gb of RAM may look like "a lot", this may be not as true as you believe. You need to profile.

With Windows Resource monitor it is possible to see how much RAM is used for caching (shown as "Standby").

If you see that your RAM is actually used or in standby, the page file is useful for you. If the combination of your tasks and available RAM is such that significant part of memory shows up as unused ("Free"), I think there is no need to grind the hard drive just from respect to somebody who "knows better and said so here".

-1

All these comments and the correct answer is missing. Turn OFF your page file. It isn't needed with 8GB RAM,and if you need more RAM, buy it. pretty simple really.

14
  • 4
    Windows is quite clever in determining what (not) to put in the page file. With the exception of some almost purely theoretical scenarios, turning it off will harm performance, even with 8 GB of RAM. Even if the correct answer were missing, this is certainly not it. Dec 17, 2012 at 0:36
  • 4
    Got any evidence to back up your "harm performance" claim? I present an MS article support.microsoft.com/kb/889654
    – a2552308
    Dec 18, 2012 at 1:34
  • 7
    Simply put: page files can only increase disk activity... and windows isn't smart enough to not use it at all if it has lots of RAM. On an SSD system this may not be too noticable, on a spindle system this may affect application performance a lot. Refer original poster.
    – a2552308
    Dec 18, 2012 at 1:42
  • 2
    Relevant section from MS article: "However, as more RAM is added to a computer, the need for a page file decreases. If you have enough RAM installed in your computer, you may not require a page file at all, unless one is required by a specific application." I couldn't find the relevant sections from the many articles you linked, maybe you could quote the relevant sections?
    – a2552308
    Dec 18, 2012 at 21:48
  • 2
    Sounds good in theory, not what I have observed in practice though.
    – a2552308
    Dec 19, 2012 at 1:08

You must log in to answer this question.

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