Open main menu

OpenVZ Virtuozzo Containers Wiki β

Editing On-demand accounting

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
{{UBC toc}}
 
{{UBC toc}}
[[Category: Kernel internals]]
 
  
 
This page describes a very promising way of beancounters optimization.
 
This page describes a very promising way of beancounters optimization.
Line 6: Line 5:
 
== Current accounting model ==
 
== Current accounting model ==
 
Basically allocation of any kind of resource looks like this:
 
Basically allocation of any kind of resource looks like this:
<source lang="c">
+
<pre>
 
struct some_resource *get_the_resource(int amount)
 
struct some_resource *get_the_resource(int amount)
 
{
 
{
Line 14: Line 13:
 
         return ret;
 
         return ret;
 
}
 
}
</source>
+
</pre>
 
We change this behaviour to work like this:
 
We change this behaviour to work like this:
<source lang="c">
+
<pre>
 
struct some_resource *get_the_resource(int amount)
 
struct some_resource *get_the_resource(int amount)
 
{
 
{
Line 31: Line 30:
 
         return NULL;
 
         return NULL;
 
}
 
}
</source>
+
</pre>
The <code>charge_beancounter()</code> call is responsible for checking whether the user is allowed to get the requested amount of the resource, i.e. if the resource consumption level is lower than the limit set.
+
The <code>charge_beancounter()</code> call is responsible for checking whether the user is allowed to consume desired 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.
+
Obviously, this change slows down the original code, as charge_beancounter() takes some slow operations like taking locks. We have an idea of how to optimize this behavior.
  
 
== On-demand accounting basics ==
 
== On-demand accounting basics ==
 
The main idea sonds like this:
 
The main idea sonds like this:
{{out|If the consumption level of any resource can be easily upper estimated with some value, and this 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}}
+
{{out|If the cunsumption level of any resource can be easily upper estimated with some value, and this setimation 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 precise value of the consumption level and (probably) allocate another portion of the resource.
+
Apparently, when the estimation exceeds the limit, we must switch to the slower mode, that will give us more presice value of the consumption level and (probably) allocate another portion of the resource.
  
 
== Example ==
 
== Example ==
 
Let's look at example of how this will work with the user memory accounting.
 
Let's look at example of how this will work with the user memory accounting.
  
Currently we account for the [[physpages]] resource, that is, the number of physical pages consumed by a set of processes. The accounting hooks are placed inside the page fault handlers and thus hurting the performance. Currently accounting looks like this:
+
Currently we account for the [[physpages]] resource. That is -- the number of physical pages consumed by the processes. The accounting hooks are placed inside the page faults and hurt the performance. The accounting looks like this:
<source lang="c">
+
<pre>
 
struct page *get_new_page(struct mm_struct *mm)
 
struct page *get_new_page(struct mm_struct *mm)
 
{
 
{
Line 60: Line 59:
 
         return NULL;
 
         return NULL;
 
}
 
}
</source>
+
</pre>
  
However, we have a good upper estimation of the RSS size that is the lengths of mappings of the processes. Since the physical pages can only be allocated within these mappings, the RSS value can never exceed the sum of their lengths. The accounting will then look like this:
+
However, we have a good estimation of the RSS size -- that is the lenghts of mappings of the processes. Since the physical pages can only be allocated within these mappgins the RSS value can never exceed the sum of theis lenghs. The accounting will then look like this:
<source lang="c">
+
<pre>
 
struct vm_area_struct *get_new_mapping(struct mm_struct *mm,
 
struct vm_area_struct *get_new_mapping(struct mm_struct *mm,
 
                 unsigned long pages)
 
                 unsigned long pages)
Line 97: Line 96:
 
         return NULL;
 
         return NULL;
 
}
 
}
</source>
+
</pre>
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 do not affect the performance.
+
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 the performance.
  
 
Note, that the <code>recalculate_the_rss()</code> is called to calculate the exact RSS value on the beancounter.
 
Note, that the <code>recalculate_the_rss()</code> is called to calculate the exact RSS value on the beancounter.

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: