<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:ËÎÌå;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@ËÎÌå";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.trans
        {mso-style-name:trans;}
.MsoChpDefault
        {mso-style-type:export-only;}
/* Page Definitions */
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="blue" vlink="purple" style="text-justify-trim:punctuation">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi all</span><span style="font-family:ËÎÌå">£º</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Currently, we use cgroup(memory) to support memory QoS on KVM platform, and use "mlock" on qemu to support "memory reserved".<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The "mlock" seems to be not appropriate.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Now qemu "mlock" memory in the main thread, which would lock iothread (qemu_mutex_lock_iothread), if the memory size is large, that will consume lots of time.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">It means whenever we want to set a new 'mlock', the VM would be blocked for a while.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Here is my optimization:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  1. Add a global variable (lock_ram_size) to save the value of "memory reserved";
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  2. Add a qmp commond "set_ram_minguarantee" to change lock_ram_size;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  3. Create a new thread to mlock(lock_ram_zie), while is waked up by the "set_ram_minguarantee" qmp command.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Flow chart:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">           main funciton           qmp command "set_ram_minguarantee"<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">                 |                           |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">                 |                           |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">        create "mlock" thread           change value of lock_ram_size<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">                 |                           |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">                 |                           |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">    |------>thread wait<-------------wake up "mlock" thread<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">    |            |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">    |            |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">    |            |<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">    |-------mlock(lock_ram_zie)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">We have tested this demo a few days, it seems to be worked well.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But we are not sure is there any other problems , if the main thread and mlock thread access one memory zone at one time without a mutex lock.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Is it workable?Or Is there any other idea to support "memory reserved" ?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">zhanghailiang<o:p></o:p></span></p>
</div>
</body>
</html>