Thursday, July 10, 2014

RAM ZFS pool

It's probably not efficient to have a temporary ZFS pool on top of a RAM disk.
After all the ZFS ARC and L2ARC are very efficient intermediate caches.

Anyway, it's possible to define a temporary ZFS pool on top of a RAM disk.
Perhaps (still have to check) I could disable ARC and L2ARC.
It's also possible that this ZFS pool be encrypted.

At this point, perhaps I could have a case to justify this idea.
But I'm not recommending nor advising anything.
For now, I'm just exploring technologies.

Assume I already have a RAM disk:

# ramdiskadm
Block Device                Size  Removable
/dev/ramdisk/c-01      268435456    Yes


On top of this block device I can establish the temporary ZFS pool.
And I want its root dataset to be encrypted right from the start.

# zpool create -R /c-01 -O encryption=on c-01 /dev/ramdisk/c-01
Enter passphrase for 'c-01':
Enter again:

After entering twice the passphrase the temporary ZFS pool will be created.
By default, a passphrase is prompted for encryption.
There's a space overhead for ZFS metadata.

# zpool list c-01
NAME  SIZE  ALLOC  FREE  CAP  DEDUP  HEALTH  ALTROOT
c-01  250M   100K  250M   0%  1.00x  ONLINE  /c-01


# zpool status c-01
  pool: c-01
 state: ONLINE
  scan: none requested
config:

    NAME                     STATE     READ WRITE CKSUM

    c-01                     ONLINE       0     0     0
      /dev/ramdisk/c-01      ONLINE       0     0     0


The -R option automatically sets the altroot and cachefile properties. 
 
# zpool get all c-01
NAME  PROPERTY       VALUE                 SOURCE
c-01  allocated      100K                  -
c-01  altroot        /c-01                 local
c-01  autoexpand     off                   default
c-01  autoreplace    off                   default
c-01  bootfs         -                     default
c-01  cachefile      none                  local
c-01  capacity       0%                    -
c-01  dedupditto     0                     default
c-01  dedupratio     1.00x                 -
c-01  delegation     on                    default
c-01  failmode       wait                  default
c-01  free           250M                  -
c-01  guid           14233173042207590481  -
c-01  health         ONLINE                -
c-01  listshares     off                   default
c-01  listsnapshots  off                   default
c-01  readonly       off                   -
c-01  size           250M                  -
c-01  version        34                    default

 
The -O option sets the defaults for encryption.
Also note the default mountpoint for the associated root dataset.

# zfs get all c-01
NAME  PROPERTY              VALUE                  SOURCE
c-01  aclinherit            restricted             default
c-01  aclmode               discard                default
c-01  atime                 on                     default
c-01  available             218M                   -
c-01  canmount              on                     default
c-01  casesensitivity       mixed                  -
c-01  checksum              sha256-mac             local
c-01  compression           off                    default
c-01  compressratio         1.00x                  -
c-01  copies                1                      default
c-01  creation              Thu Jul 10 11:20 2014  -
c-01  dedup                 off                    default
c-01  devices               on                     default
c-01  encryption            on                     local
c-01  exec                  on                     default
c-01  keychangedate         Thu Jul 10 11:20 2014  local
c-01  keysource             passphrase,prompt      local
c-01  keystatus             available              -
c-01  logbias               latency                default
c-01  mlslabel              none                   -
c-01  mounted               yes                    -
c-01  mountpoint            /c-01                  local
c-01  multilevel            off                    -
c-01  nbmand                off                    default
c-01  normalization         none                   -
c-01  primarycache          all                    default
c-01  quota                 none                   default
c-01  readonly              off                    default
c-01  recordsize            128K                   default
c-01  referenced            33K                    -
c-01  refquota              none                   default
c-01  refreservation        none                   default
c-01  rekeydate             Thu Jul 10 11:20 2014  local
c-01  reservation           none                   default
c-01  rstchown              on                     default
c-01  secondarycache        all                    default
c-01  setuid                on                     default
c-01  shadow                none                   -
c-01  share.*               ...                    local
c-01  snapdir               hidden                 default
c-01  sync                  standard               default
c-01  type                  filesystem             -
c-01  used                  100K                   -
c-01  usedbychildren        67.5K                  -
c-01  usedbydataset         33K                    -
c-01  usedbyrefreservation  0                      -
c-01  usedbysnapshots       0                      -
c-01  utf8only              off                    -
c-01  version               6                      -
c-01  vscan                 off                    default
c-01  xattr                 on                     default
c-01  zoned                 off                    default


As I said earlier ZFS provides an intelligent and layered caching architecture comprised by the ARC (Adaptive Replacement Cache) and the L2ARC (Layer 2 ARC). Each ZFS dataset (file system, volume, etc...) has two properties for each type of cache, primarycache for ARC and secondarycache for L2ARC. Both properties provide a way to tell the ZFS engine how each cache should be used. Each property admits three possible values: all, metadata and none. As the backing ZFS pool device is a RAM disk I propose to evaluate the effect of setting both properties to none.

# zfs set primarycache=none c-01

# zfs set secondarycache=none c-01

# zfs get primarycache,secondarycache c-01
NAME  PROPERTY        VALUE  SOURCE
c-01  primarycache    none   local
c-01  secondarycache  none   local

   
The way I've presented above, as I presumed since beginning, this experiment doesn't seem to present any advantage when the system is mostly idle or yet not heavily loaded. But it could be interesting to develop several scenarios in order to provide a better overall evaluation.