Add support for locking domain's memory pages

The following XML configuration can be used to request all domain's
memory pages to be kept locked in host's memory (i.e., domain's memory
pages will not be swapped out):

      <memoryBacking>
        <locked/>
      </memoryBacking>
This commit is contained in:
Jiri Denemark 2013-05-16 22:00:03 +02:00
parent 4734f1f53b
commit 555866389c
4 changed files with 33 additions and 19 deletions

View File

@ -595,22 +595,28 @@
&lt;memoryBacking&gt;
&lt;hugepages/&gt;
&lt;nosharepages/&gt;
&lt;locked/&gt;
&lt;/memoryBacking&gt;
...
&lt;/domain&gt;
</pre>
<p>The optional <code>memoryBacking</code> element may contain several
elements that influence how virtual memory pages are backed by host
pages.</p>
<dl>
<dt><code>memoryBacking</code></dt>
<dd>The optional <code>memoryBacking</code> element has two
optional elements. The element <code>hugepages</code> tells
the hypervisor that the guest should have its memory allocated
using hugepages instead of the normal native page size. And the
optional element <code>nosharepages</code>
(<span class="since">since 1.0.6</span>) tells the hypervisor
that share pages (memory merge, KSM) should be disabled on guest
startup.
</dd>
<dt><code>hugepages</code></dt>
<dd>This tells the hypervisor that the guest should have its memory
allocated using hugepages instead of the normal native page size.</dd>
<dt><code>nosharepages</code></dt>
<dd>Instructs hypervisor to disable shared pages (memory merge, KSM) for
this domain. <span class="since">Since 1.0.6</span></dd>
<dt><code>locked</code></dt>
<dd>When set and supported by the hypervisor, memory pages belonging
to the domain will be locked in host's memory and the host will not
be allowed to swap them out.
<span class="since">Since 1.0.6</span></dd>
</dl>

View File

@ -501,6 +501,11 @@
<empty/>
</element>
</optional>
<optional>
<element name="locked">
<empty/>
</element>
</optional>
</interleave>
</element>
</optional>

View File

@ -10411,6 +10411,9 @@ virDomainDefParseXML(xmlDocPtr xml,
if ((node = virXPathNode("./memoryBacking/nosharepages", ctxt)))
def->mem.nosharepages = true;
if (virXPathBoolean("boolean(./memoryBacking/locked)", ctxt))
def->mem.locked = true;
/* Extract blkio cgroup tunables */
if (virXPathUInt("string(./blkiotune/weight)", ctxt,
&def->blkio.weight) < 0)
@ -15766,17 +15769,16 @@ virDomainDefFormatInternal(virDomainDefPtr def,
def->mem.swap_hard_limit)
virBufferAddLit(buf, " </memtune>\n");
if (def->mem.hugepage_backed || def->mem.nosharepages)
if (def->mem.hugepage_backed || def->mem.nosharepages || def->mem.locked) {
virBufferAddLit(buf, " <memoryBacking>\n");
if (def->mem.hugepage_backed)
virBufferAddLit(buf, " <hugepages/>\n");
if (def->mem.nosharepages)
virBufferAddLit(buf, " <nosharepages/>\n");
if (def->mem.hugepage_backed || def->mem.nosharepages)
if (def->mem.hugepage_backed)
virBufferAddLit(buf, " <hugepages/>\n");
if (def->mem.nosharepages)
virBufferAddLit(buf, " <nosharepages/>\n");
if (def->mem.locked)
virBufferAddLit(buf, " <locked/>\n");
virBufferAddLit(buf, " </memoryBacking>\n");
}
virBufferAddLit(buf, " <vcpu");
virBufferAsprintf(buf, " placement='%s'",

View File

@ -1863,6 +1863,7 @@ struct _virDomainDef {
unsigned long long cur_balloon; /* in kibibytes */
bool hugepage_backed;
bool nosharepages;
bool locked;
int dump_core; /* enum virDomainMemDump */
unsigned long long hard_limit; /* in kibibytes */
unsigned long long soft_limit; /* in kibibytes */