Warming EBS volumes in Windows Link to heading

If you have ever launched an EC2 instance from a custom AMI or attached a new EBS volume from a snapshot, you might have noticed that the disk seems kind of slow at first, but that performance gradually improves over time.

This is because snapshots (including the ones that back custom AMIs) are stored in S3, and EBS employs “lazy loading”. This means that your EBS volume won’t copy over a block from S3 until your EC2 instance actually tries to read or write to that block.

So what do you do if you need performance right away? You could turn on fast snapshot restore, which will make sure your disks are pre-warmed and ready to go right away, but it’s very expensive (almost a dollar an hour) and is charged per zone.

There’s a better option for cheapskates: you can pre-warm your disks by reading from them with a tool like fio or dd. This will force all blocks to get copied over from S3 to EBS.

Let’s try this with fio (I find it is easier to use than dd). You’ll need a package manager to help you install it. I use the chocolatey package manager:

choco install fio

To test things out on your root disk, just run the one-liner below:

fio --filename=\\.\PHYSICALDRIVE0 --rw=read --bs=128k --iodepth=32 --direct=1 --name=volume-initialize

Replace PHYSICALDRIVE0 with the appropriate drive index for the drive you want to warm.

And we’re done! This will read all the blocks from the C:\ drive (PHYSICALDRIVE0), forcing them to get copied from S3 into EBS. After this command finishes, you should see a noticeable speed improvement on your freshly-launched Windows EC2 instances.