A swapfile is a portion of hard disk space set aside to be used for additional memory beyond a system's RAM. At this day and age, a swapfile is pretty much antiquated for current desktop systems as RAM exceeds one gigabyte in off the shelf computers. It does however still serve a purpose in some cases, in low memory systems or memory intensive applications.

Getting Started
When you start up a computer application, the code is executed as a process on the machine. Among other things, the program's binary code is loaded into RAM or the main memory of the system. Different operating systems and architectures load different things in different ways, but the gist is the same. As the program runs, with or without human interaction, it will need additional memory from the system. The amount depends on the data types being loaded or processed, but believe me they add up. Be they spreadsheet columns or aliens threatening the earth's existence, each thing that appears on the screen takes memory. Even things that don't appear on the screen need space.

Getting Stopped
There is a particular problem that arises when your RAM is full. Even though you bought a nifty box with a gigabyte of RAM, your computer is choking. You have zero KB of free memory left but you still need to paste another 500 rows of floating points into the spreadsheet. Now the operating system kicks in to save the day! And you thought that was something Bill Gates would never help do.

When your program and its data are loaded into memory they are divided into units called pages. When a process requests additional main memory and the operating system has no free memory to allocate, the OS begins goes on a hunt for memory to borrow. Those pages that compromise each process and its data are tagged with a value that indicates when they were last used. The operating system finds some pages that have not been used in a long time and copies them to the swapfile. The pages moved to the swapfile can be from any process; they do not have to be taken away from the requestion process. Once enough memory is free for the waiting process, the memory gets reallocated. If any of the pages moved to the swapfile are needed again, the OS reloads them into main memory, doing additional swaps as needed to create enough free space. Pretty spiffy, eh?

Do note, however, that this is the main reason your computer appears slow. Espcially the case in laptop machines, where harddrives are normally even slower than those in desktop machines. Always try to maximize the amount of memory in machines you use; faster processors do squat when they can't get the data they need quickly.

The problem here is that hard drives are incredibly slow compared to the rest of your computer. Believe it or not, a hard drive about 100,000 times slower than main memory. This is a horrendous bottleneck when the system needs to move a lot of data from main memory to the swapfile. The swaps back and forth can eventually bring the computer to a stand still where the only work being done is the moving of data from the disk to memory and back again. This is calling the "thrashing point" and it makes people very unhappy.

Different Operating Systems
On *nix machines, you actually designate an entire partition to act as the swapfile. This partition, along with its size, is normally establish during the installation of the OS.

Windows systems refers to the swap file as the page file. On Windows XP, this is an actual file, pagefile.sys, that is set up on some partition of yours. You can change the size of the pagefile and it's location through Control Panel -> System -> Advanced -> Performance -> Settings -> Advanced -> Virtual Memory -> Change. Gotta love Windoze simplicity.

Regardless of the operating system, it is a good idea to place the swapfile on a separate hard disk than the OS. Since page swaps tie up disk I/O, it takes longer and longer to access important data or programs as page swaps increase. The best solution is to put the swapfile on its own disk or a disk that holds infrequently modified data. A good example would to keep your operating system, important programs and games on one hard drive and you movies, music, pictures and swapfile on another.

Log in or register to write something here or to contact authors.