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

View File

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

View File

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

View File

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