Social Icons

Friday, June 21, 2013

Can I delete pagefile.sys? What is it?

Pagefile.sys is the Windows paging file, also known as the file that Windows uses as Virtual Memory. As I've discussed before, Virtual Memory is simply disk space that Windows uses when it runs out of physical memory or RAM. Some of the contents of RAM are written out to disk to make room for whatever other memory request might have come in. If that "paged out" memory is needed again, some other RAM is written to disk and the previously written information is read back in.
Pagefile.sys is the file where Windows keeps all that:
Windows Explorer showing pagefile.sys
(Note that pagefile.sys is a system file, and thus in order to see the file in Windows Explorer "Show hidden files and folders" should be enabled and "Hide protected operating system files" should be disabled.)
"... Virtual Memory is simply disk space that Windows uses when it runs out of physical memory or RAM."
Now, since the file is being used by Windows, you can't just delete it. It'll either tell you permission denied, or "file in use" or something like that. Extra steps are required.
You'll probably notice that your paging file is roughly the same size as your configured virtual memory settings.
This leads to our first way to get rid of it: set your Virtual Memory to zero, and reboot. Once you return, Windows will no longer be using the file, and thus you can delete it.
If you have enough RAM in your system to handle the amount of memory needed to run the programs you run, you may not need VM at all. That happens to be how I run. (In fact, in researching this article I noticed I had a pagefile.sys when I did not expect one. I'd simply forgotten to delete it after setting my Virtual Memory to zero.)
Pagefile.sys will return if you re-enable virtual memory.
The other approach to deleting pagefile.sys is less useful, but I'll include it for completeness: boot into another operating system, and delete the file.
Quite literally, if you were to boot from a Linux Live CD, and explore your Windows hard drive you'll find, and should be able to delete, pagefile.sys.
We've done exactly what you asked for, but there's a problem.
As soon as you boot Windows, if you have Virtual Memory configured, pagefile.sys will return.
This approach is benign, but I'm guessing this isn't really what you were after.
Ultimately, unless you have some reason to be playing with your Virtual Memory settings, or know that you can run without Virtual Memory at all, I suggest simply leaving the settings, and pagefile.sys, the way they are.

Hiberfil.sys and Windows Hibernate function

Hiberfil.sys and Windows Hibernate function

To understand why hiberfil.sys exists, we must look at the Windows Hibernate function. When you activate Hibernate, Windows takes a snap shot of your current session (all your running programs, open files, etc.) and writes that information to your hard drive. Hibernate was designed to speedup shut downs and restarts and save power on laptops.
Windows hiberfil.sys
Figure A
Hiberfil.sys, as the name suggests, is the file to which Windows saves the snap shot data. Thus, the file is always equal in size to the total amount of available RAM on the computer (see Figure A). On a computer with plenty of free disk space having such a large file just hanging around usually isn’t a problem. But if you’re running low on hard drive space and never use the Hibernate feature, hiberfil.sys is unnecessarily eating up valuable disk real estate.

Disabling Windows Hibernation

As I noted earlier, you can manually delete hiberfil.sys, but it will just come back. To permanently remove the file, you must disable the Windows Hibernate function. You can do this through either the Windows GUI or from the command line.

Windows XP

On Windows XP systems, you can easily disable Hibernate through the GUI using the following steps:
  1. Open the Control Panel and access Power Options.
  2. Select the Hibernate tab in the Power Options Properties dialog box.
  3. Clear the Enable Hibernation check box (see Figure B) and click OK.
Windows XP - Power Options - Hibernate
Figure B
If you would prefer to disable Hibernate through he command line, you can use the steps outlined below.

Windows Vista and Windows 7

Completely disabling Hibernate through the GUI on Windows Vista and Windows 7 is significantly more difficult than on Windows XP. The Hibernate settings are still stored under the Control Panel’s Power Options applet, but they are buried under each power plan’s advanced power settings submenu. In fact, I was unable to remove hiberfil.sys by altering the appropriate Power Options (Allow hybrid sleep and Hibernate after) on either Windows Vista or Windows 7 (seeFigure C).
Windows 7 Power Options - Advanced Settings - Sleep and Hibernate
Figure C
The only surefire method of disabling Hibernate, and thus removing hiberfil.sys, on Windows Vista and Windows 7, is through the command prompt and the following steps:
  1. Open a command prompt with administrative privileges.
  2. Enter “powercfg.exe -h off” (see Figure D).
  3. Exit the command prompt.
Windows powercfg.exe
Figure D
As soon as you clear the check box or execute the above powercfg.exe command, Windows should delete hiberfil.sys. If not, you can manually delete it.

Re-enabling Windows Hibernate

To turn the Hibernate function back on, simply recheck the Enable Hibernation setting under Power Option Properties or enter “powercfg.exe -h on” at a command prompt with administrative privileges.