1*189c099fSAlex Bennée 2*189c099fSAlex Bennée=========== 3*189c099fSAlex Bennéevirtio pmem 4*189c099fSAlex Bennée=========== 5*189c099fSAlex Bennée 6*189c099fSAlex BennéeThis document explains the setup and usage of the virtio pmem device. 7*189c099fSAlex BennéeThe virtio pmem device is a paravirtualized persistent memory device 8*189c099fSAlex Bennéeon regular (i.e non-NVDIMM) storage. 9*189c099fSAlex Bennée 10*189c099fSAlex BennéeUsecase 11*189c099fSAlex Bennée------- 12*189c099fSAlex Bennée 13*189c099fSAlex BennéeVirtio pmem allows to bypass the guest page cache and directly use 14*189c099fSAlex Bennéehost page cache. This reduces guest memory footprint as the host can 15*189c099fSAlex Bennéemake efficient memory reclaim decisions under memory pressure. 16*189c099fSAlex Bennée 17*189c099fSAlex BennéeHow does virtio-pmem compare to the nvdimm emulation? 18*189c099fSAlex Bennée----------------------------------------------------- 19*189c099fSAlex Bennée 20*189c099fSAlex BennéeNVDIMM emulation on regular (i.e. non-NVDIMM) host storage does not 21*189c099fSAlex Bennéepersist the guest writes as there are no defined semantics in the device 22*189c099fSAlex Bennéespecification. The virtio pmem device provides guest write persistence 23*189c099fSAlex Bennéeon non-NVDIMM host storage. 24*189c099fSAlex Bennée 25*189c099fSAlex Bennéevirtio pmem usage 26*189c099fSAlex Bennée----------------- 27*189c099fSAlex Bennée 28*189c099fSAlex BennéeA virtio pmem device backed by a memory-backend-file can be created on 29*189c099fSAlex Bennéethe QEMU command line as in the following example:: 30*189c099fSAlex Bennée 31*189c099fSAlex Bennée -object memory-backend-file,id=mem1,share,mem-path=./virtio_pmem.img,size=4G 32*189c099fSAlex Bennée -device virtio-pmem-pci,memdev=mem1,id=nv1 33*189c099fSAlex Bennée 34*189c099fSAlex Bennéewhere: 35*189c099fSAlex Bennée 36*189c099fSAlex Bennée - "object memory-backend-file,id=mem1,share,mem-path=<image>, size=<image size>" 37*189c099fSAlex Bennée creates a backend file with the specified size. 38*189c099fSAlex Bennée 39*189c099fSAlex Bennée - "device virtio-pmem-pci,id=nvdimm1,memdev=mem1" creates a virtio pmem 40*189c099fSAlex Bennée pci device whose storage is provided by above memory backend device. 41*189c099fSAlex Bennée 42*189c099fSAlex BennéeMultiple virtio pmem devices can be created if multiple pairs of "-object" 43*189c099fSAlex Bennéeand "-device" are provided. 44*189c099fSAlex Bennée 45*189c099fSAlex BennéeHotplug 46*189c099fSAlex Bennée------- 47*189c099fSAlex Bennée 48*189c099fSAlex BennéeVirtio pmem devices can be hotplugged via the QEMU monitor. First, the 49*189c099fSAlex Bennéememory backing has to be added via 'object_add'; afterwards, the virtio 50*189c099fSAlex Bennéepmem device can be added via 'device_add'. 51*189c099fSAlex Bennée 52*189c099fSAlex BennéeFor example, the following commands add another 4GB virtio pmem device to 53*189c099fSAlex Bennéethe guest:: 54*189c099fSAlex Bennée 55*189c099fSAlex Bennée (qemu) object_add memory-backend-file,id=mem2,share=on,mem-path=virtio_pmem2.img,size=4G 56*189c099fSAlex Bennée (qemu) device_add virtio-pmem-pci,id=virtio_pmem2,memdev=mem2 57*189c099fSAlex Bennée 58*189c099fSAlex BennéeGuest Data Persistence 59*189c099fSAlex Bennée---------------------- 60*189c099fSAlex Bennée 61*189c099fSAlex BennéeGuest data persistence on non-NVDIMM requires guest userspace applications 62*189c099fSAlex Bennéeto perform fsync/msync. This is different from a real nvdimm backend where 63*189c099fSAlex Bennéeno additional fsync/msync is required. This is to persist guest writes in 64*189c099fSAlex Bennéehost backing file which otherwise remains in host page cache and there is 65*189c099fSAlex Bennéerisk of losing the data in case of power failure. 66*189c099fSAlex Bennée 67*189c099fSAlex BennéeWith virtio pmem device, MAP_SYNC mmap flag is not supported. This provides 68*189c099fSAlex Bennéea hint to application to perform fsync for write persistence. 69*189c099fSAlex Bennée 70*189c099fSAlex BennéeLimitations 71*189c099fSAlex Bennée----------- 72*189c099fSAlex Bennée 73*189c099fSAlex Bennée- Real nvdimm device backend is not supported. 74*189c099fSAlex Bennée- virtio pmem hotunplug is not supported. 75*189c099fSAlex Bennée- ACPI NVDIMM features like regions/namespaces are not supported. 76*189c099fSAlex Bennée- ndctl command is not supported. 77