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` flag, specifying the filename of the backing 9image as the parameter. By default, the pmem device will be writable; add `ro=true` to create a 10read-only pmem device instead. 11 12```sh 13crosvm run \ 14 --pmem disk.img \ 15 ... # usual crosvm args 16``` 17 18The Linux virtio-pmem driver can be enabled with the `CONFIG_VIRTIO_PMEM` option. It will expose 19pmem devices as `/dev/pmem0`, `/dev/pmem1`, etc., which may be mounted like any other block device. 20A pmem device may also be used as the root filesystem by adding `root=true` to the `--pmem` flag: 21 22```sh 23crosvm run \ 24 --pmem rootfs.img,root=true,ro=true \ 25 ... # usual crosvm args 26``` 27 28The advantage of pmem over a regular block device is the potential for less cache duplication; since 29the guest can directly map pages of the pmem device, it does not need to perform an extra copy into 30the guest page cache. This can result in lower memory overhead versus `virtio-block` (when not using 31`O_DIRECT`). 32 33The file backing a persistent memory device is mapped directly into the guest's address space, which 34means that only the raw disk image format is supported; disk images in qcow2 or other formats may 35not be used as a pmem device. See the [`block`](block.md) device for an alternative that supports 36more file formats. 37