<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GenieReddicks</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GenieReddicks"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/GenieReddicks"/>
	<updated>2026-06-13T22:30:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Fairsched_API&amp;diff=10055</id>
		<title>Fairsched API</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Fairsched_API&amp;diff=10055"/>
		<updated>2011-03-29T10:14:59Z</updated>

		<summary type="html">&lt;p&gt;GenieReddicks: /* Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are several parameters tuning which the OpenVZ administrator can change the CPU usage of a CT. Usually one sets these parameters with the aid of the &amp;lt;code&amp;gt;vzctl&amp;lt;/code&amp;gt; utility. But sometimes it can be useful to modify these parameters directly, without using &amp;lt;code&amp;gt;vzctl&amp;lt;/code&amp;gt;. For example, it can be required by developers who want to implement an in-place solution to control a particular virtualization system based on OpenVZ. That is why the Fairsched API is introduced.&lt;br /&gt;
&lt;br /&gt;
The '''Fairsched API''' is the set of system calls that can be used (and that are, in fact, used in the &amp;lt;code&amp;gt;vzctl&amp;lt;/code&amp;gt; utility) for altering various parameters of the [[CPU Fair scheduler]], such as &amp;lt;code&amp;gt;cpuunits&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cpulimit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cpus&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;cpumask&amp;lt;/code&amp;gt;. The article is targeted at describing the API.&lt;br /&gt;
&lt;br /&gt;
== CPU weight ==&lt;br /&gt;
&lt;br /&gt;
=== Synopsis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int fairsched_chwt(unsigned int id, unsigned int wght);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
The CPU weight defines how much CPU time a CT gets. [http://www.top5optimizers.com speed optimizer] The smaller the weight is, the more CPU time the container gets. The CPU weight is a relative parameter. That means that multiplying the weight of all running CTs by the same value does not change the CPU time distribution. The minimal value of the weight is 1, and the maximal value is &amp;lt;code&amp;gt;FSCHWEIGHT_MAX&amp;lt;/code&amp;gt; (65535). The weight of a newly created CT is set to 500 by default.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;fairsched_chwt()&amp;lt;/code&amp;gt; system call sets the CPU weight of a CT. &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; is the id of the CT. &amp;lt;code&amp;gt;wght&amp;lt;/code&amp;gt; is the desired weight.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
On success, &amp;lt;code&amp;gt;fairsched_chwt()&amp;lt;/code&amp;gt; returns 0. On error, -1 is returned, and &amp;lt;code&amp;gt;errno&amp;lt;/code&amp;gt; is set appropriately.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;=0.&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: the value of &amp;lt;code&amp;gt;wght&amp;lt;/code&amp;gt; is out of the allowed range.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOENT&amp;lt;/code&amp;gt;: the CT does not exist.&lt;br /&gt;
* &amp;lt;code&amp;gt;EPERM&amp;lt;/code&amp;gt;: the caller does not have permissions to modify the CPU parameters of the CT.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
It is possible to change the CPU weight of the host system. The host system's id equals &amp;lt;code&amp;gt;INT_MAX&amp;lt;/code&amp;gt; (2147483647).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cpuunits&amp;lt;/code&amp;gt; option of the &amp;lt;code&amp;gt;vzctl&amp;lt;/code&amp;gt; utility is not the same thing as the CPU weight described above, but they are closely connected by the simple equation:&lt;br /&gt;
&lt;br /&gt;
''cpuweight = 500000 / cpuunits''&lt;br /&gt;
&lt;br /&gt;
== CPU limit ==&lt;br /&gt;
&lt;br /&gt;
=== Synopsis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int fairsched_rate(unsigned int id, int op, unsigned int rate);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
The CPU limit is the upper bound to the CPU usage for a CT. The limit is set for all CPUs the CT can execute on. That means the maximal value of the CPU limit (i.e. no limit) is the maximal limit on 1 CPU, which equals 1024, multiplied by NUM_CPUS, the number of CPUs this VM can execute on. The CPU limit is an absolute parameter in the sense that altering the limit of one CT does not affect the limits of other CTs.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;fairsched_rate()&amp;lt;/code&amp;gt; system call is used to set, get, or drop (i.e. set to the maximum) CPU limit of a CT. &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; is the id of the CT. &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; can be one of the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;FAIRSCHED_SET_RATE&amp;lt;/code&amp;gt; to set the limit; in this case &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; is the limit value to set.&lt;br /&gt;
* &amp;lt;code&amp;gt;FAIRSCHED_DROP_RATE&amp;lt;/code&amp;gt; to drop the limit; &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; is not used.&lt;br /&gt;
* &amp;lt;code&amp;gt;FAIRSCHED_GET_RATE&amp;lt;/code&amp;gt; to get the current value of the limit; the function returns the limit value, &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; is not used.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
On success, &amp;lt;code&amp;gt;fairsched_rate()&amp;lt;/code&amp;gt; returns the current value of the CPU limit if &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;FAIRSCHED_SET_RATE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;FAIRSCHED_GET_RATE&amp;lt;/code&amp;gt;, or 0 if &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;FAIRSCHED_DROP_RATE&amp;lt;/code&amp;gt;. On error, -1 is returned, and &amp;lt;code&amp;gt;errno&amp;lt;/code&amp;gt; is set appropriately.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;=0.&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; is invalid.&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt;=&amp;lt;code&amp;gt;FAIRSCHED_SET_RATE&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt;&amp;lt;=0.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOENT&amp;lt;/code&amp;gt;: the CT does not exist.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENODATA&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt;=&amp;lt;code&amp;gt;FAIRSCHED_GET_RATE&amp;lt;/code&amp;gt;, and the limit is not set (or was dropped).&lt;br /&gt;
* &amp;lt;code&amp;gt;EPERM&amp;lt;/code&amp;gt;: the caller does not have permissions to modify the CPU parameters of the CT.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
It is possible to limit the CPU usage of the host system. The host system's id equals &amp;lt;code&amp;gt;INT_MAX&amp;lt;/code&amp;gt; (2147483647).&lt;br /&gt;
&lt;br /&gt;
CPU limits are available only in RHEL5-based and RHEL6-based kernels, and they behave a bit differently in them in respect of distributing CPU time among CPUs the CT can execute on.&lt;br /&gt;
&lt;br /&gt;
In the RHEL5 kernel the limit has a container-wide meaning. For example, if there are 2 CPUs available for a container, and the limit is set to 1024 (of 2048), the container's CPU usage can be 100/0%, or 50/50%, or any other values whose sum does not exceed 100%.&lt;br /&gt;
&lt;br /&gt;
In the RHEL6 kernel the limit is divided between the CPUs proportionally, and a busy CPU cannot borrow time from an idle one, i.e. with a 2 CPUs container and 1024 (of 2048) limit set the usage of each CPU cannot exceed 50% in any case.&lt;br /&gt;
&lt;br /&gt;
As a result, the minimal value for the limit is 1 in the RHEL5 kernel and 1 * NUM_CPUS in the RHEL6 kernel. If the given limit is out of the allowed range it is automatically clamped to the range.&lt;br /&gt;
&lt;br /&gt;
== Number of CPUs ==&lt;br /&gt;
&lt;br /&gt;
=== Synopsis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int fairsched_vcpus(unsigned int id, unsigned int vcpus);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;fairsched_vcpus()&amp;lt;/code&amp;gt; system call sets the number of virtual CPUs available in a CT. &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; is the id of the CT. &amp;lt;code&amp;gt;vcpus&amp;lt;/code&amp;gt; is the number of virtual CPUs to set for the CT. If &amp;lt;code&amp;gt;vcpus&amp;lt;/code&amp;gt;=0, the call attempts to set the number of CPUs in the CT to the number of online CPUs.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
On success, &amp;lt;code&amp;gt;fairsched_vcpus()&amp;lt;/code&amp;gt; returns 0. On error, -1 is returned, and &amp;lt;code&amp;gt;errno&amp;lt;/code&amp;gt; is set appropriately.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;=0.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOENT&amp;lt;/code&amp;gt;: the CT does not exist.&lt;br /&gt;
* &amp;lt;code&amp;gt;EPERM&amp;lt;/code&amp;gt;: the caller does not have permissions to modify the CPU parameters of the CT.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
The parameter have not been implemented in the RHEL6 kernel yet.&lt;br /&gt;
&lt;br /&gt;
== CPU affinity mask ==&lt;br /&gt;
&lt;br /&gt;
=== Synopsis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int fairsched_cpumask(unsigned int id, unsigned int len, unsigned long *mask);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
A CT's CPU affinity mask determines the set of CPUs on which it is eligible to run. A CPU affinity mask is represented by an array of &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;s so that a CT is allowed to execute on the n-th CPU if and only if the (&amp;lt;code&amp;gt;n%sizeof(long)&amp;lt;/code&amp;gt;)-th bit of the (&amp;lt;code&amp;gt;n/sizeof(long)&amp;lt;/code&amp;gt;)-th element of the array is set.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;fairsched_cpumask()&amp;lt;/code&amp;gt; system call sets the CPU affinity mask for a CT. &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; is the id of the CT. &amp;lt;code&amp;gt;mask&amp;lt;/code&amp;gt; is the mask, and &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; is the size of the mask, in bytes.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
On success, &amp;lt;code&amp;gt;fairsched_cpumask()&amp;lt;/code&amp;gt; returns 0. On error, -1 is returned, and &amp;lt;code&amp;gt;errno&amp;lt;/code&amp;gt; is set appropriately.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EBUSY&amp;lt;/code&amp;gt;: the CT has a child cpuset which is not a subset of the mask.&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;=0.&lt;br /&gt;
* &amp;lt;code&amp;gt;EINVAL&amp;lt;/code&amp;gt;: the mask intersects with a cpuset, and either that cpuset or the CT's cpuset is marked exclusive.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOENT&amp;lt;/code&amp;gt;: the CT does not exist.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOMEM&amp;lt;/code&amp;gt;: there is no memory to copy the mask.&lt;br /&gt;
* &amp;lt;code&amp;gt;ENOSPC&amp;lt;/code&amp;gt;: the mask has no active CPUs set.&lt;br /&gt;
* &amp;lt;code&amp;gt;EPERM&amp;lt;/code&amp;gt;: the caller does not have permissions to modify the CPU parameters of the CT.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
The parameter is available since the [[Download/kernel/rhel6|RHEL6]] kernel.&lt;br /&gt;
&lt;br /&gt;
[[Category: Kernel]]&lt;br /&gt;
[[Category: Resource management]]&lt;/div&gt;</summary>
		<author><name>GenieReddicks</name></author>
		
	</entry>
</feed>