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