Editing
Util-vserver:Cgroups
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!
<div id="content"> <span id="top"></span> <span id="firstHeading"></span> = util-vserver:Cgroups = <div id="bodyContent"> <span id="siteSub"></span> === From Linux-VServer === <div id="contentSub"> </div> <div id="jump-to-nav"> Jump to: [[#column-one|navigation]], [[#searchInput|search]] </div> Bears run away when you yell at them, even <code>lynx</code>es. {| id="toc" class="wikitable toc" summary="Contents" |- | <div id="toctitle"> <span id="contents"></span> == Contents == </div> * [[#Kernel_configuration|<span class="tocnumber">1</span> <span class="toctext">Kernel configuration</span>]] * [[#Prerequisites|<span class="tocnumber">2</span> <span class="toctext">Prerequisites</span>]] * [[#Draft_-_Distributing_cpu_shares_with_cgroups|<span class="tocnumber">3</span> <span class="toctext">Draft - Distributing cpu shares with cgroups</span>]] * [[#Making_share_permanent_with_util_vserver|<span class="tocnumber">4</span> <span class="toctext">Making share permanent with util vserver</span>]] * [[#cgroup_and_CFS_based_CPU_hard_limiting_that_replaces_sched_hard|<span class="tocnumber">5</span> <span class="toctext">cgroup and CFS based CPU hard limiting that replaces sched_hard</span>]] ** [[#References|<span class="tocnumber">5.1</span> <span class="toctext">References</span>]] ** [[#Requirements|<span class="tocnumber">5.2</span> <span class="toctext">Requirements</span>]] ** [[#Configuration|<span class="tocnumber">5.3</span> <span class="toctext">Configuration</span>]] * [[#using_cgroup_to_enforce_memory_limits|<span class="tocnumber">6</span> <span class="toctext">using cgroup to enforce memory limits</span>]] * [[#Real_world_Examples_of_Scheduling|<span class="tocnumber">7</span> <span class="toctext">Real world Examples of Scheduling</span>]] ** [[#Ben.27s_install_on_Debian_Lenny|<span class="tocnumber">7.1</span> <span class="toctext">Ben's install on Debian Lenny</span>]] *** [[#Getting_Lenny_Ready|<span class="tocnumber">7.1.1</span> <span class="toctext">Getting Lenny Ready</span>]] *** [[#Sharing_out_the_CPU_between_guest_servers|<span class="tocnumber">7.1.2</span> <span class="toctext">Sharing out the CPU between guest servers</span>]] *** [[#Dishing_out_different_processors_sets_to_different_guest_servers|<span class="tocnumber">7.1.3</span> <span class="toctext">Dishing out different processors sets to different guest servers</span>]] *** [[#Doing_this_to_servers_live|<span class="tocnumber">7.1.4</span> <span class="toctext">Doing this to servers live</span>]] *** [[#Making_sure_all_of_this_gets_set_up_after_a_reboot|<span class="tocnumber">7.1.5</span> <span class="toctext">Making sure all of this gets set up after a reboot</span>]] ** [[#Ben.27s_install_on_Debian_Squeeze.2FSid|<span class="tocnumber">7.2</span> <span class="toctext">Ben's install on Debian Squeeze/Sid</span>]] |} <span id="Kernel_configuration"></span> <span id="edit-kernel-configuration"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=1|edit]]]</span> <span class="mw-headline"> Kernel configuration </span> == When configuring your kernel for cgroups with util-vserver you must make sure <code>CONFIG_CGROUP_NS</code> ('''CGroup Namespaces''') is unset for the time being. '''CGroup Namespaces''' are a different approach to namespaces than that used by Linux vServer, and are not currently supported. <span id="Prerequisites"></span> <span id="edit-prerequisites"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=2|edit]]]</span> <span class="mw-headline"> Prerequisites </span> == To use <code>util-vserver</code>'s Control Groups (<code>cgroups</code>) support, you need to have <code>/dev/cgroup</code> mounted. Recent versions of <code>util-vserver</code> sort this out for you by including the appropriate mount command in the <code>util-vserver</code> <code>init</code> (ie: runlevel) script included in the <code>util-vserver</code> distribution, however this apparently only works for the <code>sysv</code> <code>init</code> script, and not the Debian or Gentoo ones. If you were to mount the <code>cgroup</code> Control Groups filesystem manually, you would use something like: <code># mkdir /dev/cgroup </code> # mount -t cgroup -o ''<subsystems>'' /dev/cgroup Where ''<code><subsystems></code>'' is something like <code>cpuset,memory</code>. To avoid the need for manual configuration after reboot, on Gentoo you may wish to add the cgroup mount to <code>/etc/fstab</code>. For Debian see the live examples section at the bottom of this page. <pre> none /dev/cgroup cgroup cpu,cpuset,memory 0 2</pre> <span id="Draft_-_Distributing_cpu_shares_with_cgroups"></span> <span id="edit-draft---distributing-cpu-shares-with-cgroups"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=3|edit]]]</span> <span class="mw-headline"> Draft - Distributing cpu shares with cgroups </span> == From what i gathered in sched-design-CFS.txt [http://people.redhat.com/mingo/cfs-scheduler/sched-design-CFS.txt [1]] This is simply done by adjusting the cpu.shares. Just do: echo '512' > /dev/cgroup/<guest name>/cpu.shares The share you get is equal to the guest's share divided by the sum of the cpu shares of all the guest. So for exemple : <pre> vserver guest 1 => 512 vserver guest 2 => 512 vserver guest 3 => 2048 vserver guest 4 => 512</pre> so you have a total of 3584 cpu shares (2048+512+512+512) , then you get : <pre> vserver guest 1 => 512 / 3584 = 14% cpu vserver guest 2 => 512 / 3584 = 14% cpu vserver guest 3 => 2048 / 3584 = 57% cpu vserver guest 4 => 512 / 3584 = 14% cpu</pre> <br /> <br /> Note that this is fair scheduling and this will not enfore HARD limit (as far as i know). <span id="Making_share_permanent_with_util_vserver"></span> <span id="edit-making-share-permanent-with-util-vserver"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=4|edit]]]</span> <span class="mw-headline"> Making share permanent with util vserver </span> == You must use the "cgroup" directory. You can apply defaults to all vservers or choose different settings for each guest: * /etc/vservers/.default/cgroup , this directory contains settings applying to all guest when they start * /etc/vservers/<guestname>/cgroup , this directory contains settings for the guest when it starts. <br /> Example : <pre> mkdir /etc/vservers/.defaults/cgroup mkdir /etc/vservers/<guestname>/cgroup echo '2048' > /etc/vservers/<guestname>/cgroup/cpu.shares # List of CPUs echo 1 > /etc/vservers/<guestname>/cgroup/cpuset.cpus # NUMA nodes echo 1 > /etc/vservers/<guestname>/cgroup/cpuset.mems</pre> Note that /etc/vservers is an example, in my Aqueos install i use /usr/local/etc/vservers but /etc/vservers seems to be the defaults for the classic installs. Regards, Ghislain. <span id="cgroup_and_CFS_based_CPU_hard_limiting_that_replaces_sched_hard"></span> <span id="edit-cgroup-and-cfs-based-cpu-hard-limiting-that-replaces-sched_hard"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=5|edit]]]</span> <span class="mw-headline"> cgroup and CFS based CPU hard limiting that replaces sched_hard </span> == <span id="References"></span> <span id="edit-references"></span> === <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=6|edit]]]</span> <span class="mw-headline">References</span> === You can find documentation about the CFS hard limiting in <code>Documentation/scheduler/sched-cfs-hard-limits.txt</code> inside your kernel source dir. <span id="Requirements"></span> <span id="edit-requirements"></span> === <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=7|edit]]]</span> <span class="mw-headline">Requirements</span> === This feature is currently available in <code>patch-2.6.31.2-vs2.3.0.36.15.diff</code> and is in testing phase as of this patch set so report any bugs to the mailing list. To get the hard limit setup on every vServer start you need a recent utils package. It worked for me with: <code>0.30.216-pre2864</code>. (Download from [http://people.linux-vserver.org/~dhozac/t/uv-testing/ util-vserver prereleases]) Before trying to setup limits for one guest you should mount the cgroup filesystem: <pre>[ -d /dev/cgroup ] || mkdir /dev/cgroup mount -t cgroup -ocpu none /dev/cgroup</pre> <span id="Configuration"></span> <span id="edit-configuration"></span> === <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=8|edit]]]</span> <span class="mw-headline">Configuration</span> === Example for an upper bound of 2/5th (or 40%) of the all CPU power that a guest/cgroup can use : <pre> # force CFS hard limit (only needed for older kernel versions) # echo 1 > /etc/vservers/<guestname>/cgroup/cpu.cfs_hard_limit # time assigned to guest (in microseconds) 200000 = 0,2 sec echo 200000 > /etc/vservers/<guestname>/cgroup/cpu.cfs_runtime_us # in each specified period (in microseconds) 500000 = 0,5 sec echo 500000 > /etc/vservers/<guestname>/cgroup/cpu.cfs_period_us</pre> This limit is an hard limit, see it like an upper wall for the resources used by the cgroup. If you set both CPU share AND hard limit the system will do fine but hard limits takes priority over CPU share scheduling, so CPU share will do the job but each cgroup will have an upper bound that it cannot cross even if the CPU share you gave it is higher. The hard limit feature adds 3 cgroup files for the CFS group scheduler: * <code>cfs_runtime_us</code>: Hard limit for the group in microseconds. * <code>cfs_period_us</code>: Time period in microseconds within which hard limits is enforced. * <code>cfs_hard_limit</code>: The control file to enable or disable hard limiting for the group. <br /> <span id="using_cgroup_to_enforce_memory_limits"></span> <span id="edit-using-cgroup-to-enforce-memory-limits"></span> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=9|edit]]]</span> <span class="mw-headline"> using cgroup to enforce memory limits </span> == in linux-vserver patch version vs2.3.0.36.29 memory limiting by cgroup is introduced. to use it you need to have the following config lines in your kernel build (aditionally to the others mentioned for cgroup cpu limits): * CONFIG_RESOURCE_COUNTERS=y * CONFIG_CGROUP_MEM_RES_CTLR=y * CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y make sure /dev/cgroup is mounted with -o...,memory to be able to use this feature. The following files let you adjust memory limits of a running vserver (create them in /etc/vservers/-vserver-name- /cgroup/ to make them permanent): * memory.memsw.limit_in_bytes the total memory limit (memory+swap) of your cgroup context * memory.limit_in_bytes the total memory limit values are stored in bytes. When writing to those files you can use suffixes: K,M,G. Note: cgroup memory limits are to replace rss.soft and rss.hard some time in the future. When you wish the guests to see only their limited memory pool, be sure to include VIRT_MEM in your cflags config file. For a deeper understanding check out Documentation/cgroups/memory.txt of your kernel source tree. <span id="Real_world_Examples_of_Scheduling"></span> <span id="edit-real-world-examples-of-scheduling"></span> = <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=10|edit]]]</span> <span class="mw-headline"> Real world Examples of Scheduling </span> = This section is for working and tested examples you have put in place. Please add the following information for each example you put here (use <code>vserver-info</code>). * Base kernel version * vServer version * Other kernel patches in use (<code>grsec</code>, etc.) * <code>util-vserver</code> release <span id="Ben.27s_install_on_Debian_Lenny"></span> <span id="edit-bens-install-on-debian-lenny"></span> == <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> == <span class="editsection">[<nowiki/>[[index.php?title=util-vserver:Cgroups&action=edit§ion=17|edit]]]</span> <span class="mw-headline"> Ben's install on Debian Squeeze/Sid </span> == Squeeze is due to ship with the 2.6.32 kernel. Currently the package linux-image-2.6.32-2-vserver-amd64 works well for cgroup scheduling. The following steps are simplest way to set it up: * 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 cpuset,cpu,cpuacct,devices,freezer,net_cls,memory 0 0</pre> * reboot the server Instructions for setting particular parameters are the same as for Lenny. The reason for specifying the cgroup subsystems is that if the namespace subsystem "ns" is included, Linux-Vserver will not work. The /etc/fstab line above mounts /dev/cgroup with all the available subsystems excluding "ns". <div class="printfooter"> Retrieved from "http://wiki.linux-vserver.org/util-vserver:Cgroups" </div> <div class="visualClear"> </div> </div> </div>
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