15dbf3359SPankaj Gupta 25dbf3359SPankaj Gupta======================== 35dbf3359SPankaj GuptaQEMU virtio pmem 45dbf3359SPankaj Gupta======================== 55dbf3359SPankaj Gupta 65dbf3359SPankaj Gupta This document explains the setup and usage of the virtio pmem device 75dbf3359SPankaj Gupta which is available since QEMU v4.1.0. 85dbf3359SPankaj Gupta 95dbf3359SPankaj Gupta The virtio pmem device is a paravirtualized persistent memory device 105dbf3359SPankaj Gupta on regular (i.e non-NVDIMM) storage. 115dbf3359SPankaj Gupta 125dbf3359SPankaj GuptaUsecase 135dbf3359SPankaj Gupta-------- 145dbf3359SPankaj Gupta 155dbf3359SPankaj Gupta Virtio pmem allows to bypass the guest page cache and directly use 165dbf3359SPankaj Gupta host page cache. This reduces guest memory footprint as the host can 175dbf3359SPankaj Gupta make efficient memory reclaim decisions under memory pressure. 185dbf3359SPankaj Gupta 195dbf3359SPankaj Guptao How does virtio-pmem compare to the nvdimm emulation supported by QEMU? 205dbf3359SPankaj Gupta 215dbf3359SPankaj Gupta NVDIMM emulation on regular (i.e. non-NVDIMM) host storage does not 225dbf3359SPankaj Gupta persist the guest writes as there are no defined semantics in the device 235dbf3359SPankaj Gupta specification. The virtio pmem device provides guest write persistence 245dbf3359SPankaj Gupta on non-NVDIMM host storage. 255dbf3359SPankaj Gupta 265dbf3359SPankaj Guptavirtio pmem usage 275dbf3359SPankaj Gupta----------------- 285dbf3359SPankaj Gupta 295dbf3359SPankaj Gupta A virtio pmem device backed by a memory-backend-file can be created on 30*f21673c3SStefan Hajnoczi the QEMU command line as in the following example:: 315dbf3359SPankaj Gupta 325dbf3359SPankaj Gupta -object memory-backend-file,id=mem1,share,mem-path=./virtio_pmem.img,size=4G 335dbf3359SPankaj Gupta -device virtio-pmem-pci,memdev=mem1,id=nv1 345dbf3359SPankaj Gupta 355dbf3359SPankaj Gupta where: 36*f21673c3SStefan Hajnoczi 375dbf3359SPankaj Gupta - "object memory-backend-file,id=mem1,share,mem-path=<image>, size=<image size>" 385dbf3359SPankaj Gupta creates a backend file with the specified size. 395dbf3359SPankaj Gupta 405dbf3359SPankaj Gupta - "device virtio-pmem-pci,id=nvdimm1,memdev=mem1" creates a virtio pmem 415dbf3359SPankaj Gupta pci device whose storage is provided by above memory backend device. 425dbf3359SPankaj Gupta 435dbf3359SPankaj Gupta Multiple virtio pmem devices can be created if multiple pairs of "-object" 445dbf3359SPankaj Gupta and "-device" are provided. 455dbf3359SPankaj Gupta 465dbf3359SPankaj GuptaHotplug 475dbf3359SPankaj Gupta------- 485dbf3359SPankaj Gupta 495dbf3359SPankaj GuptaVirtio pmem devices can be hotplugged via the QEMU monitor. First, the 505dbf3359SPankaj Guptamemory backing has to be added via 'object_add'; afterwards, the virtio 515dbf3359SPankaj Guptapmem device can be added via 'device_add'. 525dbf3359SPankaj Gupta 535dbf3359SPankaj GuptaFor example, the following commands add another 4GB virtio pmem device to 54*f21673c3SStefan Hajnoczithe guest:: 555dbf3359SPankaj Gupta 565dbf3359SPankaj Gupta (qemu) object_add memory-backend-file,id=mem2,share=on,mem-path=virtio_pmem2.img,size=4G 575dbf3359SPankaj Gupta (qemu) device_add virtio-pmem-pci,id=virtio_pmem2,memdev=mem2 585dbf3359SPankaj Gupta 595dbf3359SPankaj GuptaGuest Data Persistence 605dbf3359SPankaj Gupta---------------------- 615dbf3359SPankaj Gupta 625dbf3359SPankaj Gupta Guest data persistence on non-NVDIMM requires guest userspace applications 635dbf3359SPankaj Gupta to perform fsync/msync. This is different from a real nvdimm backend where 645dbf3359SPankaj Gupta no additional fsync/msync is required. This is to persist guest writes in 655dbf3359SPankaj Gupta host backing file which otherwise remains in host page cache and there is 665dbf3359SPankaj Gupta risk of losing the data in case of power failure. 675dbf3359SPankaj Gupta 685dbf3359SPankaj Gupta With virtio pmem device, MAP_SYNC mmap flag is not supported. This provides 695dbf3359SPankaj Gupta a hint to application to perform fsync for write persistence. 705dbf3359SPankaj Gupta 715dbf3359SPankaj GuptaLimitations 725dbf3359SPankaj Gupta------------ 735dbf3359SPankaj Gupta- Real nvdimm device backend is not supported. 745dbf3359SPankaj Gupta- virtio pmem hotunplug is not supported. 755dbf3359SPankaj Gupta- ACPI NVDIMM features like regions/namespaces are not supported. 765dbf3359SPankaj Gupta- ndctl command is not supported. 77