1# Pmem 2 3crosvm supports `virtio-pmem` to provide a virtual device emulating a byte-addressable persistent 4memory device. The disk image is provided to the guest using a memory-mapped view of the image file, 5and this mapping can be directly mapped into the guest's address space if the guest operating system 6and filesystem support [DAX](https://www.kernel.org/doc/html/latest/filesystems/dax.html). 7 8Pmem devices may be added to crosvm using the `--pmem-device` (read only) or `--rw-pmem-device` 9(read-write) flag, specifying the filename of the backing image as the parameter. 10 11```sh 12crosvm run \ 13 --pmem-device disk.img \ 14 ... # usual crosvm args 15``` 16 17The Linux virtio-pmem driver can be enabled with the `CONFIG_VIRTIO_PMEM` option. It will expose 18pmem devices as `/dev/pmem0`, `/dev/pmem1`, etc., which may be mounted like any other block device. 19A pmem device may also be used as a root filesystem by adding a `root=` kernel command line 20parameters: 21 22```sh 23crosvm run \ 24 --pmem-device rootfs.img \ 25 -p "root=/dev/pmem0 ro" \ 26 ... # usual crosvm args 27``` 28 29The advantage of pmem over a regular block device is the potential for less cache duplication; since 30the guest can directly map pages of the pmem device, it does not need to perform an extra copy into 31the guest page cache. This can result in lower memory overhead versus `virtio-block` (when not using 32`O_DIRECT`). 33 34The file backing a persistent memory device is mapped directly into the guest's address space, which 35means that only the raw disk image format is supported; disk images in qcow2 or other formats may 36not be used as a pmem device. See the [`block`](block.md) device for an alternative that supports 37more file formats. 38