Editing
Util-vserver:Cgroups
(section)
From Linix VServer
Jump to navigation
Jump to search
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.
Anti-spam check. Do
not
fill this in!
== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=11|edit]]]</span> <span class="mw-headline"> Ben's install on Debian Lenny </span> == I used the kernels from [http://repo.psand.net [2]], described at [http://kernels.bristolwireless.net/ [3]]. I've done this on a few versions, works for 2.6.31.7 with patch vs2.3.0.36.27 on amd64, also 2.6.31.11 with patch vs2.3.0.36.28. I used the stock Lenny util-vserver, patched as described below. The kernel config is critically important, with specific cgroup options necessary in order to get cgroups working in this way. Check the configs for the [http://repo.psand.net [4]] kernels to see which ones I used. <span id="Getting_Lenny_Ready"></span> <span id="edit-getting-lenny-ready"></span> ==== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=12|edit]]]</span> <span class="mw-headline"> Getting Lenny Ready </span> ==== There's a very old version of util-vserver on Lenny, it needs this patch applying before it will set the cgroups properly, it basically only adds one line: <pre>--- /usr/lib/util-vserver/vserver.suexec.orig 2008-12-12 22:56:25.000000000 -0600 +++ /usr/lib/util-vserver/vserver.suexec 2009-08-20 02:11:42.000000000 -0500 @@ -22,7 +22,8 @@ test -z "$is_stopped" -o "$OPTION_INSECU exit 1 } generateOptions "$VSERVER_DIR" -addtoCPUSET "$VSERVER_DIR" +addtoCPUSET "$VSERVER_DIR" +attachToCgroup "$VSERVER_DIR" user=$1 shift</pre> Next I added a correctly mounted cgroup file system on /dev/cgroup/. <pre>$ mkdir /dev/cgroup $ mount -t cgroup vserver /dev/cgroup</pre> For the util-vserver to do the right thing, this directory needed adding too: <pre>$ mkdir /etc/vservers/.defaults/cgroup</pre> <span id="Sharing_out_the_CPU_between_guest_servers"></span> <span id="edit-sharing-out-the-cpu-between-guest-servers"></span> ==== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=13|edit]]]</span> <span class="mw-headline"> Sharing out the CPU between guest servers </span> ==== I have a few test guests hanging around that I play with, call onetime, twotime, threetime, fourtime and fivetime. I order to set the shares for each guest I did this: <pre>mkdir /etc/vservers/fivetime/cgroup/ /etc/vservers/fourtime/cgroup/ /etc/vservers/threetime/cgroup/ /etc/vservers/twotime/cgroup/ /etc/vservers/twotime/cgroup/ echo "512" > /etc/vservers/fivetime/cgroup/cpu.shares echo "1024" > /etc/vservers/fourtime/cgroup/cpu.shares echo "1024" > /etc/vservers/threetime/cgroup/cpu.shares echo "1536" > /etc/vservers/twotime/cgroup/cpu.shares echo "1024" > /etc/vservers/onetime/cgroup/cpu.shares</pre> Then started the guests. When the system was loaded (I used one instance of cpuburn on each server - not advised but a useful test) they each should have got the following percentage of CPU. {| class="wikitable wikitable" |- ! Guest Name ! cpu.share given ! percentage of cpu |- | fivetime | 512 | 10% |- | fourtime | 1024 | 20% |- | threetime | 1024 | 20% |- | twotime | 1536 | 30% |- | onetime | 1024 | 20% |} This didn't quite happen, as each process could migrate to other CPUs. When I fixed every guest to use only one of the available CPUs (see below how I did this) the percentage of processing time alloted to each guest were then pretty much exact! Each process was given exactly it's designated percentage of time according to vtop. <span id="Dishing_out_different_processors_sets_to_different_guest_servers"></span> <span id="edit-dishing-out-different-processors-sets-to-different-guest-servers"></span> ==== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=14|edit]]]</span> <span class="mw-headline"> Dishing out different processors sets to different guest servers </span> ==== The "cpuset" for each guest is the subset of CPUs which it is permitted to use. I found out the number of CPUs available on my system by doing this: <pre>$ cat /dev/cgroup/cpuset.cpus</pre> This gave me the result 0-1, meaning that the overall set for my cgroups consists of CPUs 0 and 1 (for a quad core system one would expect the result 0-3, or for quad core with HT, 0-7). I stopped my guests, then for each guest specified a cpuset containing only CPU 0 for each of them: <pre>$ echo "0" > /etc/vservers/onetime/cgroup/cpuset.cpus $ echo "0" > /etc/vservers/twotime/cgroup/cpuset.cpus $ echo "0" > /etc/vservers/threetime/cgroup/cpuset.cpus $ echo "0" > /etc/vservers/fourtime/cgroup/cpuset.cpus $ echo "0" > /etc/vservers/fivetime/cgroup/cpuset.cpus</pre> On restarting the guest, I could see (using vtop) that these guest were only using the CPU 0 (the column "Last used cpu (SMP)" needs to be on in vtop in order to see this). This set up isn't particularly useful, but did allow me to check that the cpu.shares I specified for my guest were working as expected. <span id="Doing_this_to_servers_live"></span> <span id="edit-doing-this-to-servers-live"></span> ==== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=15|edit]]]</span> <span class="mw-headline"> Doing this to servers live </span> ==== The parameters in the last two sections can be set when the servers are running. For example to move the guest "threetime" so that it could use both CPUs I did this: <pre>$ echo "0-1" > /dev/cgroup/threetime/cpuset.cpus</pre> The processes running on threetime instantly were allocated cycle on both CPUs. Then: <pre>$ echo "1" > /dev/cgroup/threetime/cpuset.cpus</pre> Shifts them all to CPU 1. One can change where cycles are allocated with impunity. The same with CPU shares: <pre>$ echo "4096" > /dev/cgroup/threetime/cpu.shares</pre> Gave threetime a much bigger slice of the processors when it was under load. '''NOTE''': The range "0-1" is not the only way of specifying a set of CPUs, I could have used "0,1". On bigger systems, with say 8 CPUs one could use "0-2,4,5", which would be the same as "0,1,2,4,5" or "0-2,4-5". <span id="Making_sure_all_of_this_gets_set_up_after_a_reboot"></span> <span id="edit-making-sure-all-of-this-gets-set-up-after-a-reboot"></span> ==== <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=16|edit]]]</span> <span class="mw-headline"> Making sure all of this gets set up after a reboot </span> ==== This process will make sure /dev/cgroup is present at boot and correctly mounted: * patch util-vserver (see above) * mkdir /etc/vservers/.defaults/cgroup * mkdir /lib/udev/devices/cgroup (this will mean that the /dev/cgroup is created early in the boot process) * add the following line to /etc/fstab <pre>vserver /dev/cgroup cgroup cpu,cpuset,memory 0 0</pre> <span id="Ben.27s_install_on_Debian_Squeeze.2FSid"></span> <span id="edit-bens-install-on-debian-squeezesid"></span>
Summary:
Please note that all contributions to Linix VServer may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Linix VServer:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Page actions
Page
Discussion
Read
Edit
History
Page actions
Page
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
About
Overview
Paper
News
Developers
Donations
Search
Getting Started
Downloads
FAQs
Documentation
Support
Participate
How to participate
Report a Bug
Communicate
Teams/Projects
Hall of Fame
Resources
Archives
Recent Wiki Changes
Pastebin
Related Projects
VServer Hosting
Happy VServer Users
Tools
What links here
Related changes
Special pages
Page information