15dbf3359SPankaj Gupta 2*c5d7cfdaSPeter Maydell=========== 3*c5d7cfdaSPeter Maydellvirtio pmem 4*c5d7cfdaSPeter Maydell=========== 55dbf3359SPankaj Gupta 6*c5d7cfdaSPeter MaydellThis document explains the setup and usage of the virtio pmem device. 75dbf3359SPankaj GuptaThe virtio pmem device is a paravirtualized persistent memory device 85dbf3359SPankaj Guptaon regular (i.e non-NVDIMM) storage. 95dbf3359SPankaj Gupta 105dbf3359SPankaj GuptaUsecase 11*c5d7cfdaSPeter Maydell------- 125dbf3359SPankaj Gupta 135dbf3359SPankaj GuptaVirtio pmem allows to bypass the guest page cache and directly use 145dbf3359SPankaj Guptahost page cache. This reduces guest memory footprint as the host can 155dbf3359SPankaj Guptamake efficient memory reclaim decisions under memory pressure. 165dbf3359SPankaj Gupta 17*c5d7cfdaSPeter MaydellHow does virtio-pmem compare to the nvdimm emulation? 18*c5d7cfdaSPeter Maydell----------------------------------------------------- 195dbf3359SPankaj Gupta 205dbf3359SPankaj GuptaNVDIMM emulation on regular (i.e. non-NVDIMM) host storage does not 215dbf3359SPankaj Guptapersist the guest writes as there are no defined semantics in the device 225dbf3359SPankaj Guptaspecification. The virtio pmem device provides guest write persistence 235dbf3359SPankaj Guptaon non-NVDIMM host storage. 245dbf3359SPankaj Gupta 255dbf3359SPankaj Guptavirtio pmem usage 265dbf3359SPankaj Gupta----------------- 275dbf3359SPankaj Gupta 285dbf3359SPankaj GuptaA virtio pmem device backed by a memory-backend-file can be created on 29f21673c3SStefan Hajnoczithe QEMU command line as in the following example:: 305dbf3359SPankaj Gupta 315dbf3359SPankaj Gupta -object memory-backend-file,id=mem1,share,mem-path=./virtio_pmem.img,size=4G 325dbf3359SPankaj Gupta -device virtio-pmem-pci,memdev=mem1,id=nv1 335dbf3359SPankaj Gupta 345dbf3359SPankaj Guptawhere: 35f21673c3SStefan Hajnoczi 365dbf3359SPankaj Gupta - "object memory-backend-file,id=mem1,share,mem-path=<image>, size=<image size>" 375dbf3359SPankaj Gupta creates a backend file with the specified size. 385dbf3359SPankaj Gupta 395dbf3359SPankaj Gupta - "device virtio-pmem-pci,id=nvdimm1,memdev=mem1" creates a virtio pmem 405dbf3359SPankaj Gupta pci device whose storage is provided by above memory backend device. 415dbf3359SPankaj Gupta 425dbf3359SPankaj GuptaMultiple virtio pmem devices can be created if multiple pairs of "-object" 435dbf3359SPankaj Guptaand "-device" are provided. 445dbf3359SPankaj Gupta 455dbf3359SPankaj GuptaHotplug 465dbf3359SPankaj Gupta------- 475dbf3359SPankaj Gupta 485dbf3359SPankaj GuptaVirtio pmem devices can be hotplugged via the QEMU monitor. First, the 495dbf3359SPankaj Guptamemory backing has to be added via 'object_add'; afterwards, the virtio 505dbf3359SPankaj Guptapmem device can be added via 'device_add'. 515dbf3359SPankaj Gupta 525dbf3359SPankaj GuptaFor example, the following commands add another 4GB virtio pmem device to 53f21673c3SStefan Hajnoczithe guest:: 545dbf3359SPankaj Gupta 555dbf3359SPankaj Gupta (qemu) object_add memory-backend-file,id=mem2,share=on,mem-path=virtio_pmem2.img,size=4G 565dbf3359SPankaj Gupta (qemu) device_add virtio-pmem-pci,id=virtio_pmem2,memdev=mem2 575dbf3359SPankaj Gupta 585dbf3359SPankaj GuptaGuest Data Persistence 595dbf3359SPankaj Gupta---------------------- 605dbf3359SPankaj Gupta 615dbf3359SPankaj GuptaGuest data persistence on non-NVDIMM requires guest userspace applications 625dbf3359SPankaj Guptato perform fsync/msync. This is different from a real nvdimm backend where 635dbf3359SPankaj Guptano additional fsync/msync is required. This is to persist guest writes in 645dbf3359SPankaj Guptahost backing file which otherwise remains in host page cache and there is 655dbf3359SPankaj Guptarisk of losing the data in case of power failure. 665dbf3359SPankaj Gupta 675dbf3359SPankaj GuptaWith virtio pmem device, MAP_SYNC mmap flag is not supported. This provides 685dbf3359SPankaj Guptaa hint to application to perform fsync for write persistence. 695dbf3359SPankaj Gupta 705dbf3359SPankaj GuptaLimitations 71*c5d7cfdaSPeter Maydell----------- 72*c5d7cfdaSPeter Maydell 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