How do I defragment Windows paging file

5

Any suggestions how can I make pagefile.sys contiguous and move it to the beginning of the disk? Much appreciated.

Update:

I use Windows 7 64-bit edition.

user2543574

Posted 2014-12-21T10:36:04.753

Reputation: 429

What version of Windows? – Dude named Ben – 2014-12-21T11:15:42.543

@DudenamedBen 64-bit Windows 7 – user2543574 – 2014-12-21T11:38:52.763

1btw, the word you are looking for is contiguous, rather than continuous. – Tetsujin – 2014-12-21T11:48:15.927

Welcome. . . ;) – Tetsujin – 2014-12-21T15:06:28.690

Answers

1

If you want your swap file to truly be at the front of the drive use partitioning software, like gparted, to shrink your C: drive and create a partition, d: for example, and place the swap file there. If you are doing this to get better peformance you are better off getting a second, smaller hard drive or ssd, and dedicating it to only the swap file.

cybernard

Posted 2014-12-21T10:36:04.753

Reputation: 11 200

The only way to get really better performance is to buy more RAM. And it is probably cheaper too. – Tonny – 2014-12-21T16:32:11.917

@Tonny I guess I should have qualified that, the question only asks about the swap file. The only way to get better performance from your swap file. Better performance globally is new CPU,8+gb RAM, motherboard, SSD and etc – cybernard – 2014-12-21T16:35:49.663

@cybernard Thanks! That's really clever! Guess I'll stick to that and create another partition. – user2543574 – 2014-12-21T19:01:49.227

5

A simple solution (which won't move the pagefile to the beginning of the disk) is to disable virtual memory, then reboot and finally re-enable pagefile (this time with a fixed size).

This method will ensure your new pagefile is in one "chunk" on your disk and will also prevent any future fragmentation of the pagefile.

Kristian

Posted 2014-12-21T10:36:04.753

Reputation: 2 982

1Unfortunately, Windows likes to pick up every tiny free space hole. When I do this I get 70000 fragments for a 16GB file. NTFS has horrible allocation algorithms. – usr – 2018-12-11T10:20:08.990

3

Moving it to the beginning of the disk is relatively pointless nowadays, but for defragmenting it you can use PageDefrag. Note that fragmented files are not an issue on SSDs.

Wormbo

Posted 2014-12-21T10:36:04.753

Reputation: 248

I was till now convinced that the pagefile can't be fragmented. – marsh-wiggle – 2014-12-21T11:42:07.440

1it can quite easily frag if it's set to system managed size. It shrinks, a file is placed next to it, it grows - fragged. – Tetsujin – 2014-12-21T11:43:43.483

@Tetsujin off topic to my comment and the question, but does the pagefile get ever shrinked (except when its done manually)? – marsh-wiggle – 2014-12-21T12:16:01.017

1if it's system managed, yes, as Windows sees fit. – Tetsujin – 2014-12-21T12:32:27.233

1

Smart Defrag come with a lot of additional software. Bloatware. I would recommend Defraggler. It's small and fast and also has boot time defrag option. It display drive map and visualize what's being done (read, write) as it go with defragmentation (normal not boot time). At boot time it give you a textual output. Defraggler is free but has paid version with commercial support if you'd like. I use free one as it just is all I need.

termil0r

Posted 2014-12-21T10:36:04.753

Reputation: 131

1

There is a useful piece of software from Iobit called 'smart defrag' that will de-fragment files such as the page file for you on boot through 'Boot Time Disk Defrag'.

Smart Defrag

Bennett Yeo

Posted 2014-12-21T10:36:04.753

Reputation: 493

0

First remove the pagefile entirely. Then defrag your C:-drive with Puran Defrag or similar software. And finally set the pagefile to a fixed size, the recommended size + 2 MB. Use the same size for the minimum and te maximum size, so the pagefile will not defragment anymore.

Sjaak Dekker

Posted 2014-12-21T10:36:04.753

Reputation: 1

Welcome to Super User. For readers unfamiliar with the procedures, can you expand your answer a little to describe how to remove the pagefile, and how to enable it and set the size? Thanks. BTW, just noticed that this pretty much duplicates Kristian's answer. The intention is that each answer provide a substantially different solution than what has already been contributed. So adding some instructions (that were also lacking in Kristian's), would differentiate this answer. – fixer1234 – 2018-12-02T11:10:49.773