Swapping to a large sparse file

Chris Murphy lists at colorremedies.com
Fri Jan 16 20:57:46 UTC 2015


On Fri, Jan 16, 2015 at 1:08 PM, jd1008 <jd1008 at gmail.com> wrote:
> Can it be done?
>
> So far, swapon says:
> swapon: /var/swapfile: skipping - it appears to have holes.
>
> I was hoping that the kernel's swapper would allow the filesystem to
> allocate
> real blocks to the sparse file when they are needed rather than check
> up front to see if they already exist.
>
> Maybe the devs can have a look and see if they can modify the swapper to
> allow sparse swap files??

No the issue is that the swap code doesn't actually write through the
file system. Essentially it gets the LBA range of the file from the
file system, and then asserts direct control to write to those blocks.
And in this case the sparse file has no real blocks so swapon fails.

It's similar problem to swapfiles on NFS and Btrfs. There are patches
floating around to get this working on NFS that Btrfs was also going
to leverage. I don't know the status of that work,  it seems a bit
stalled to me.

You could probably create a sparsefile to back a loop device, and then
specify the loop device as swap. But reports are this will be slower
than a swapfile.


-- 
Chris Murphy


More information about the users mailing list