Changes

Jump to: navigation, search

Ubstat system call

16 bytes added, 14:36, 5 February 2010
m
do not use level1 headings
This article describes an interesting system call which was designed to pick beancounters statistics.
== Overview ==
The system call appeared in the very first version of the OpenVZ. Its API is rather sloppy, but this is something we have to live with due to backward compatibility reasons.
The main intention of this system call is to allow a user space process get the beancounters statistics ''periodically''. This statistics includes the fields observed in the <code>/proc/user_beancounters</code> file and one more field - the so called <code>minheld</code> value which is opposite to the <code>maxheld</code> one. As long as exporting the statistics the system call also notifies the task about the desired period has elapsed. The notification is performed by sending a signal to a process and this notification is one-shot.
-= How it works ==
The typical usage of this call is in performing the following steps.
# Request the amount of resources
In a signal handler one should just perform a respective system call to get the stats and schedule the next notification (yes, they are performed in one go; see below for more details).
=== API ===
The system call description is
All the times used are in seconds.
=== Notification ===
The notification info is passed via the <code>notif</code> argument and is being set up for all the functions except the <code>UBLIST</code> and the <code>UBPARNUM</code>. The notification is one-shot, but note that once you requested the statistics the next shot is scheduled at the same time.
The <code>signum</code> is the signal that will be sent to notify.
=== Return value ===
The system call returns -1 in case error has occurred. In case of <code>UBSTAT_UBPARMNUM</code it returns <code>UB_RESOURCES</code> and in all other cases it returns the amount of bytes written to the <code>buf</code>.
== Demo ==
The following program demonstrates how you can (but not should) use the described API. This example is deliberately made very stupid and simple to demonstrate the main idea and will only work on x86_64.
<pre>
</pre>
== Implementation constraints ==
Unfortunately the API is not architecture independent and thus 32-bit application will simply not work on x86_64.
[[Category:UBC]]

Navigation menu