7

I have a CentOS server that is using zfs to manage a big, slow, network attached volume.

We read quite a lot from this volume, hence I would like to optimize the read performances.

The idea is clearly a L2ARC cache.

Unfortunately I only have a single SSD disk attached to this machine already formated with xfs hosting the / and I cannot attach more (managed machine by somebody else).

I was wondering if it was possible to create a file in the SSD disk and somehow put the L2ARC in that file.

I was thinking about mounting in loop the disk, however it seems like the loop mounting support only read-only devices.

Is there an alternative?

$ dd if=/dev/zero of=/root/cache size...
$ mount -o rw,loop /root/cache /mnt/cache-file
mount: /dev/loop0 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
Siscia
  • 183

2 Answers2

7

Yes, you can use a file for L2ARC. You don't even need the loopback mount: you can simply issue zpool add tank cache <absolute_file_path>

That said, L2ARC is only useful in specific circumstances, so it is not granted that it will improve your situation.

shodanshok
  • 52,255
2

The currently accepted answer, if used naïvely, results in an error;

    $>touch /zfs.cache
    $>zpool add poolname cache /zfs.cache
cannot add to 'poolname': device is less than the maximum size (64M)

One needs to reserve a file first:

truncate -s 256g /etc/zfs.cache

or use

zpool set cachefile=/zfscache/zpool.cache poolname

aphid
  • 179
  • 1
  • 10