Le 21/11/2011 21:51, Jarry a écrit :
> Hi,
>
> I'm trying to set-up memory limits for my vserver-guests.
> Documentation says "Beginning with vs2.3.0.36.29 you should
> use cgroups to set memory limits".
>
> util-vserver:Cgroups says: "make sure /dev/cgroup is mounted
> with -o...,memory to be able to use this feature".
>
> This I do not understand at all. I have /dev/cgroups
> already visible in vserver-host. So where should I mount
> /dev/cgroups again? In vserver-guests?
>
> Further, util-vserver:Cgroups says:
> "you may wish to add the cgroup mount to /etc/fstab"
> Is it fstab of vserver-host, or vserver-guest?
>
> Jarry
Hello,
Here is an example (in this example we will have 1gb of memory on the
guest and no virtual swap (soft and hard limit are the same, raise
VDSRAMHARDLIMIT to 2048 if you want 1gb of memory + 1gb of "swap")) :
(print in mksh is a builtin "equivalent" to echo in bash)
VDSRAMLIMIT="1024"
VDSRAMHARDLIMIT="1024"
VDSRAMLIMITBYTES="$(print -- "${VDSRAMLIMIT}*1048576" |bc)"
VDSRAMHARDLIMITBYTES="$(print -- "${VDSRAMHARDLIMIT}*1048576" |bc)"
print -- "$VDSRAMLIMITBYTES" >|
/etc/vservers/${xid}/cgroup/memory.limit_in_bytes
print -- "$VDSRAMHARDLIMITBYTES" >|
/etc/vservers/${xid}/cgroup/memory.memsw.limit_in_bytes
print -- "$VDSRAMLIMITBYTES" >| /dev/cgroup/${xid}/memory.limit_in_bytes
print -- "$VDSRAMHARDLIMITBYTES" >|
/dev/cgroup/${xid}/memory.memsw.limit_in_bytes
And the old way (for the same amount of memory) :
print -- "$(( (${VDSRAMLIMIT}*1024)/4 ))" >
/etc/vservers/${xid}/rlimits/rss
print -- "$(( (${VDSRAMHARDLIMIT}*1024)/4 ))" >
/etc/vservers/${xid}/rlimits/rss.hard
vlimit -c ${xid} -S --rss "$(( (${VDSRAMLIMIT}*1024)/4 ))"
vlimit -c ${xid} --rss "$(( (${VDSRAMHARDLIMIT}*1024)/4 ))"
By the way, you cant access cgroups from the guests, only from the host
and in the recent VServer versions you dont even need to mount cgroup,
it mounts itself automatically on /dev/cgroup with the required cgroups
subsystems (be aware that putting incorrect mount options on cgroups
will make the system unbootable so dont try to play with mount options
on a production server).
Example of the cgroup mount on a 3.0.4-vs2.3.1-pre10.1-beng with
0.30.216-pre2994-1 utils :
vserver on /dev/cgroup type cgroup
(rw,cpuset,cpu,cpuacct,memory,devices,freezer,net_cls,blkio,perf_event)
Regards.
Received on Mon Nov 21 22:02:06 2011