<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 9, 2015 at 2:53 PM, Blank Field <span dir="ltr"><<a href="mailto:ihatethisfield@gmail.com" target="_blank">ihatethisfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p dir="ltr">I've noted recently that libvirt adds -realtime mlock=off by default.<br>
But in regular QEMU it's default on.<br>
Moreover, i thought that using mlock is necessary for vfio.<br>
Can someone clarify what is happenning there under the hood?</p>
</blockquote><div># /usr/libexec/qemu-kvm -help<br></div><div>...</div><div><div>-realtime [mlock=on|off]</div><div>                run qemu with realtime features</div><div>                mlock=on|off controls mlock support (default: on)</div></div><div><br></div><div>While that sort of implies that "-realtime" alone might do something, it doesn't appear to, it's just an identifier for options that are realtime-ish.  If you're running in a realtime environment, you don't want your pages to be swapped out and mlock does that, thus mlock=on.  If you want VM density, then you may want swappable VMs, thus mlock=off.</div><div><br></div><div>vfio also locks pages, but for other reasons, using other mechanisms, and it happens regardless of this QEMU option.  The short description is that the IOMMU maps physical addresses so VM pages need to be pinned to those physical addresses or else much badness would occur, including guest access to host kernel memory.  So, we can't rely on userspace to decide whether it should mlock the pages and we can't rely that a user's mlock will stick, because they could always munlock them later, so vfio's pinning happens independently, making the mlock QEMU option pretty much useless for a guest while an assigned device is present.  Of course you could always hot-unplug an assigned device and the vfio pinning would go away, and then your mlock setting would take effect.</div></div></div></div>