Update for 2020 as requested by the poster
Several answers from 2014 do not apply anymore, and some were even incorrect at that time. What has changed:
- Computers, operating systems and programs are now mostly 64-bit,
- RAM is no longer limited (practically only by the motherboard) in size and is much cheaper,
- SSD disks are everywhere and have become as reliable as hard disks.
The pagefile is still a necessitynecessary, since all operating systems, before launching a program, take care to reserve enough swap space for totally swapping the program out in case its RAM is urgently needed. Reservation is not the same as allocating, as allocation will only occur if required.
However, with the large RAM of modern computers, swap is rarely done. Swapping is now more symptomatic of a rogue program that badly manages its memory.
As in my answer from 2014, the currently most important usage of the
page-file is for containing the Windows crash dump file in case of a
BSOD (crash). Without a pagefile, this information is not written out
to a .dmp
file when Windows is next booted up, so postmortem
analysis becomes impossible.
Having the pagefile in RAM was always next to useless, since it will be lost in a crash or when the computer is turned off for hibernation.
As such, the pagefile is absolutely required and must reside on disk.
The appropriate size for the pagefile was once counseled to be double the RAM, but nowadays the same size is enough. Although RAM is now larger, with today's larger disks allocating a pagefile of this size is not a problem.
The accepted answer above gives as an example the mapping of a file to memory as taking up part of the physical RAM. This was never correct, as such a file is mapped to virtual memory, where blocks are brought into RAM only when and as they are referenced. Although the technique here is somewhat similar to swap, this does not use the pagefile.