Swapping to a large sparse file

jd1008 jd1008 at gmail.com
Fri Jan 16 21:26:13 UTC 2015


On 01/16/2015 01:57 PM, Chris Murphy wrote:
> 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.
>
>
>
Thank you Chris.
Yes, it works if I losetup /dev/loop? as the device.

Reason I asked, is that I just upgraded my laptop to 8GB ram
and I really do not want to have to repartition the drive to have a
larger swap space and restore everything from backup.

In older "traditional" practices, swap space was normally
about twice the ram size. Today, with some systems having
64 and even 128GB and even larger RAM, it becomes interesting
how big swap space should be. Where is the cutoff for performance?
Paging in and out 128GB memory space could prove to be itself a
performance bottleneck on very busy or memory bound servers.

Cheers,

JD



More information about the users mailing list