Reputation: 2937
I want to create a new cgroup and limit RAM access of that group to 1MB.
Here is my first attempt:
mkdir /sys/fs/cgroup/mygroup
mount -t cgroup -o memory mygroup /sys/fs/cgroup/mygroup
But I keep getting this error
mount: /sys/fs/cgroup/mygroup already mounted or /sys/fs/cgroup/mygroup busy
I tried a different method using cgcreate
cgcreate -g memory:mygroup2
But when I run cgexect -g memory:mygroup2 ./a.out
I get this error: cgroup change of group failed
I also saw that we can create a group by changing the /etc/cgconfig.cf file but I cannot find anything like that inside /etc even though I've installed libcgroup1 and cgroup-bin. Please help!
Thanks in advance!
Upvotes: 5
Views: 10062
Reputation: 73
I believe there is no need to mount your new directory if the cgroup filesystem is already mounted. You can check to make sure the cgroup filesystem is already mounted by typing this command:
cat /proc/mounts | grep cgroup
You know it is mounted if it returns something like this:
cgroup /sys/fs/cgroup/memory ...
Next, If you want to create a cgroup that limits memory access, I believe you should create your new cgroup in the memory sub-directory, rather than in the root of the cgroup directory. It should look something like this:
mkdir /sys/fs/cgroup/memory/mycgroup
From there, you can add tasks into your cgroup using the echo command:
echo $pid > /sys/fs/cgroup/memory/mycgroup/tasks
Finally, you can limit the memory usage to 1MB by:
echo 1M > /sys/fs/cgroup/memory/mycgroup/memory.max_usage_in_bytes
Hope this helps.
Upvotes: 3