Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

On-demand accounting

518 bytes added, 12:55, 24 January 2008
m
kernel internals
{{UBC toc}}
[[Category: Kernel internals]]
This page describes a very promising way of beancounters optimisationoptimization.
== Current accounting model ==
Basically allocation of any kind of resource looks like this:
<presource lang="c">
struct some_resource *get_the_resource(int amount)
{
return ret;
}
</presource>
We change this behaviour to work like this:
<presource lang="c">
struct some_resource *get_the_resource(int amount)
{
return NULL;
}
</presource>The <code>charge_beancounter()</code> call is responsible for checking whether the user is allowed to consume desired get the requested amount of the resource, i.e. if the resource consumption level is lower than the limit set.
Obviously, this change slows down the original code, as <code>charge_beancounter() </code> takes some slow operations like taking locks. We have an idea of how to optimize this behavior.
== On-demand accounting basics ==
The main idea sonds like this:
{{out|If the cunsumption consumption level of any resource can be easily upper estimated with some value, and this setimation estimation is lower than the limit, then we do not need to know the exact consumption level and allow the resource allocation without additional checks}}Apparently, when the estimation exceeds the limit, we must switch to the slower mode, that will give us more presice precise value of the consumption level and (probably) allocate another portion of the resource.
== Examples Example ==Let's look at some examples example of how this will workwith the user memory accounting.=== The user memory ===Currently we account for the [[physpages]] resource. That , that is -- , the number of physical pages consumed by the a set of processes. The accounting hooks are placed inside the page faults fault handlers and hurt thus hurting the performance. The Currently accounting looks like this:<presource lang="c">
struct page *get_new_page(struct mm_struct *mm)
{
return NULL;
}
</presource>
However, we have a good upper estimation of the RSS size -- that is the lenghts lengths of mappings of the processes. Since the physical pages can only be allocated within these mappgins mappings, the RSS value can never exceed the sum of theis lenghstheir lengths. The accounting will then look like this:<presource lang="c">
struct vm_area_struct *get_new_mapping(struct mm_struct *mm,
unsigned long pages)
return NULL;
}
</presource>We do not call the slow <code>charge_beancounter()</code> function in the page fault (<code>get_new_page()</code>). Instead we account for the upper estimation in <code>get_new_mapping()</code> call that happens rarely and thus increase do not affect the performance.
Note, that the <code>recalculate_the_rss()</code> is called to calculate the exact RSS value on the beancounter.
 
== More things to do ==
In this model we switch from the fast acounting to the slow one. However, if the upper estimation becomes lower than the limit again we can switch back to the fast model. However, these switches are not very fast themselves, and being too frequent can hurt the performance instead of improving. So this would require some further investigations.