+-------------------------------------------------------------------------------
| Running zram on OpenBSD
+-------------------------------------------------------------------------------

Booting the zram kernel
=======================

zram(4) comes with its own kernels, the kernels of this release with
the zram changes: /bsd.zram is the GENERIC.MP one and /bsd.zram.sp the
GENERIC one. Have the boot loader load /bsd.zram:

    # echo set image /bsd.zram >> /etc/boot.conf
    # reboot

On a machine with a single processor, where "sysctl hw.ncpufound" shows
1, load /bsd.zram.sp instead:

    # echo set image /bsd.zram.sp >> /etc/boot.conf
    # reboot

The installer only keeps the objects of the kernel it installed as /bsd,
and the relinking of /bsd at boot looks for those of the running kernel,
so it fails with the wrong one.

/bsd is left alone, so the stock kernel can still be booted by typing
"boot /bsd" at the boot> prompt. syspatch(8) and the relinking of the
kernel at boot only apply to /bsd: kernel errata come with new versions
of this package.

Removing the package also removes the "set image" line from
/etc/boot.conf, so that the next boot uses /bsd again.

Upgrading to a new release
==========================

The boot loader reads /etc/boot.conf after it has picked /bsd.upgrade,
so with the "set image" line sysupgrade(8) boots the zram kernel again
instead of the installer, at every boot. An upgrade from bsd.rd would
leave the line in place and boot the zram kernel with the userland of
the new release. The package only works with the release it was built
for: remove it before upgrading.

    # pkg_delete zram
    # sysupgrade

If sysupgrade(8) has already been run, remove the line from
/etc/boot.conf and reboot: the upgrade then starts.

Swap on zram
============

List the disks to configure in /etc/zramctl.conf, then enable the script
which configures them and adds their b partitions as swap space:

    # rcctl enable zram
    # rcctl start zram

Do not list zram disks in fstab(5): the script adds them itself, later
in the boot. It then moves the other swap devices still at priority 0,
such as the swap partition of the root disk, to priority 1, so that zram
is used first.

At securelevel 2, set in /etc/rc.securelevel, disks cannot be opened
for writing once the securelevel is raised, which happens before the
script runs, so it refuses to start. Leave it disabled and configure the
disks from /etc/rc.securelevel instead, before the line raising the
securelevel, and move the swap partition of the root disk after them:

    /usr/local/sbin/zramctl -s 50% zram0 && swapctl -a /dev/zram0b &&
        swapctl -c -p 1 /dev/sd0b

Pages paged out to zram are not encrypted. The device nodes, created when
the package is installed and removed when it is deleted, are only
accessible by root.
