0

Question inspired by this gif from wikipedia:

enter image description here

(Source: https://en.wikipedia.org/wiki/Defragmentation#/media/File:FragmentationDefragmentation.gif)

In the gif, the blocks (sectors?) are moved to free space, and rearranged (defragmentation).

Is free space required?

4
  • Why do you want to defrag? Keep your pagefile.sys and hiberfil.sys on a separate partition
    – user2497
    Feb 6, 2018 at 9:04
  • Why wouldn't you want to defragment? Defragmenting helps HDD read times doesn't it?
    – potatoman
    Feb 7, 2018 at 0:01
  • Yes - I recommend you set up a 40-50GiB partition for swap and hibernation data, as swap particularly just writes anywhere, ALL over the main volume. It’s the number one fragging culprit. I can provide a link, or you can google. I can tell you why Microsoft went with a file swap model, but SE moderates obscenities. hiberfil.sys will in size not exceed RAM, but pagefile.sys will.
    – user2497
    Feb 7, 2018 at 6:04
  • What OS? What file system? Feb 9, 2018 at 14:30

2 Answers 2

1

From the very article you got the gif:

To defragment a disk, defragmentation software (also known as a "defragmenter") can only move files around within the free space available. This is an intensive operation and cannot be performed on a filesystem with little or no free space. wikipedia-defragmentation-mitigation

Windows XP Defrag requires 15% free disc space.

4
  • This is a generally good answer, but I'm curious why you would reference Win XP rather than a more current version.
    – fixer1234
    Feb 6, 2018 at 6:47
  • Well, I wasn't very attentive. Would you know how much W10 requires?
    – potatoman
    Feb 6, 2018 at 7:42
  • Shouldn't that be up to the author of the answer to determine?
    – Ramhound
    Feb 6, 2018 at 10:58
  • 2
    I knew for XP, after I switched to Linux ^^
    – kai-dj
    Feb 6, 2018 at 12:51
1

There are two options for defragmentation. You can do it the Easy Way, or you can do it the Good Way:

  1. Keep the data to be moved and defragmented entirely in memory. Essentially you have to read entire files until you free up enough space to then write one back in a continuous block.

    • the upside to this is that it will be faster and not need extra storage on the disk
  2. Move the data elsewhere on disk, then move it back when a continuous block large enough is created.

    • this way is a lot slower as data has to be repeatedly read and written somewhere else.

Option 1 potentially does not need extra space on the disk, but is also potentially dangerous.

  • While files are being read and deleted the data no longer exists on disk. In the event of a power cut whatever files have been read but not restored to their new location are lost, potentially with catastrophic effects.
  • you have no idea how large a buffer you might need to read files. You might have multi gigabyte files that need moving or a lot of tiny files. It needs either the ability to allocate potentially infinite amounts of memory (expanding the page file and making fragmentation worse), or use a fixed percentage of memory. If you have a fixed buffer size you could load (and truncate) part of the file to free up space, but you end up in a worse position in that you could have missing parts of files in the event of power failure which would arguably be worse than missing the whole file.

Option 2 always guarantees that your data is on disk, especially if you copy first and then delete blocks.

So yes, for safe defragmentation without looming threat of catastrophic data loss, you need some disk space free.

You must log in to answer this question.

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