| View previous topic :: View next topic |
| Author |
Message |
turtles Veteran


Joined: 31 Dec 2004 Posts: 1670
|
Posted: Tue Nov 22, 2011 7:59 pm Post subject: How to limit the amount of memory udev and children uses? |
|
|
udev udisks and pollkit eat up all my memory and are not able to connect to GUI apps.
in order to further investigate this problem I need to make a memory container as I am hard locking my system several times per hour.
I simply need the kernel to cut off udev and child processes when they need over say 1/2 gig of ram.
I don't mind being booted off my x session to console but hard locks are just too much.
Any ideas on how to do this? _________________ Donate to Gentoo |
|
| Back to top |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 22170
|
Posted: Wed Nov 23, 2011 2:55 am Post subject: |
|
|
| The most common answer is to use a cgroup. Make a new cgroup, move the offending tasks into the cgroup, confine it appropriately, and you should be set. Any children they create later will start in the same cgroup as the parent. |
|
| Back to top |
|
 |
turtles Veteran


Joined: 31 Dec 2004 Posts: 1670
|
Posted: Mon Nov 28, 2011 10:45 pm Post subject: |
|
|
Thanks Hu
| Hu wrote: | | Make a new cgroup, move the offending tasks into the cgroup, confine it appropriately, and you should be set. |
I am trying to make a cgroup for udev limiting its memory and cpu.
Any advice on that? Still not sure where to start.
I emerged dev-libs/libcgroup
I now have a /etc/cgroup:
cgconfig.conf cgrules.conf
and /sys/fs/cgroup/
Been reading:
http://en.gentoo-wiki.com/wiki/Improve_responsiveness_with_cgroups
http://hydra.geht.net/tino/english/faq/debian/squeeze/cgroups/
http://www.mjmwired.net/kernel/Documentation/cgroups/memory.txt
EDIT Here is what i have so far[/code]:
http://www.kernel.org/doc/Documentation/cgroups/cgroups.txt
making my mem_udev cgroup:
| Code: | ls /sys/fs/cgroup/
mount -t tmpfs cgroup_root /sys/fs/cgroup
mkdir /sys/fs/cgroup/mem_udev
mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/mem_udev
|
EDIT#2 It seems like the available commands after the -o flag are | Code: | cat /proc/cgroups
#subsys_name hierarchy num_cgroups enabled
cpuset 1 1 1
cpu 0 1 1
cpuacct 0 1 1
devices 0 1 1
freezer 0 1 1
blkio 0 1 1
perf_event 0 1 1
|
EDIT#3
Looks like I needed:
| Code: | CONFIG_CGROUP_MEM_RES_CTLR
CONFIG_CGROUP_MEM_RES_CTLR_SWAP |
recompiling now.
The comands will be from http://www.kernel.org/doc/Documentation/cgroups/memory.txt
Sub section (3)
| memory.txt wrote: | 3. User Interface
0. Configuration
a. Enable CONFIG_CGROUPS
b. Enable CONFIG_RESOURCE_COUNTERS
c. Enable CONFIG_CGROUP_MEM_RES_CTLR
d. Enable CONFIG_CGROUP_MEM_RES_CTLR_SWAP (to use swap extension)
1. Prepare the cgroups (see cgroups.txt, Why are cgroups needed?)
# mount -t tmpfs none /sys/fs/cgroup
# mkdir /sys/fs/cgroup/memory
# mount -t cgroup none /sys/fs/cgroup/memory -o memory
2. Make the new group and move bash into it
# mkdir /sys/fs/cgroup/memory/0
# echo $$ > /sys/fs/cgroup/memory/0/tasks
Since now we're in the 0 cgroup, we can alter the memory limit:
# echo 4M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
NOTE: We can use a suffix (k, K, m, M, g or G) to indicate values in kilo,
mega or gigabytes. (Here, Kilo, Mega, Giga are Kibibytes, Mebibytes, Gibibytes.)
NOTE: We can write "-1" to reset the *.limit_in_bytes(unlimited).
NOTE: We cannot set limits on the root cgroup any more.
# cat /sys/fs/cgroup/memory/0/memory.limit_in_bytes
4194304
We can check the usage:
# cat /sys/fs/cgroup/memory/0/memory.usage_in_bytes
1216512
A successful write to this file does not guarantee a successful set of
this limit to the value written into the file. This can be due to a
number of factors, such as rounding up to page boundaries or the total
availability of memory on the system. The user is required to re-read
this file after a write to guarantee the value committed by the kernel.
# echo 1 > memory.limit_in_bytes
# cat memory.limit_in_bytes
4096
The memory.failcnt field gives the number of times that the cgroup limit was
exceeded.
The memory.stat file gives accounting information. Now, the number of
caches, RSS and Active pages/Inactive pages are shown.
|
EDIT#4
Recompiled with memory support
Now same mount steps but with -o memory
| Code: |
mount -t tmpfs cgroup_root /sys/fs/cgroup
mkdir /sys/fs/cgroup/memory
mount -t cgroup none /sys/fs/cgroup/memory -o memory
mkdir /sys/fs/cgroup/memory/0
|
Now looking for our process to jail udevd hopefully this grabs all that *kit stuff as well:
| Code: | ps -C udevd -o pid=
2016
2488
2489
|
Now move them into jail:
| Code: | cgclassify -g memory:0 --sticky 2016 2488 2489
list of controllers is memory
cgroup path is 0
found memory in rw,relatime,memory
Found cgroup option rw,relatime,memory, count 0
Will move pid 2016 to cgroup '0'
Adding controller memory
Will move pid 2488 to cgroup '0'
Adding controller memory
Will move pid 2489 to cgroup '0'
Adding controller memory
|
Let udev use up to 256 megabytes.
| Code: | echo 256M > /sys/fs/cgroup/memory/0/memory.limit_in_bytes
cat /sys/fs/cgroup/memory/0/memory.limit_in_bytes
268435456
|
Testing now _________________ Donate to Gentoo
Last edited by turtles on Tue Nov 29, 2011 4:46 am; edited 1 time in total |
|
| Back to top |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 22170
|
Posted: Tue Nov 29, 2011 4:06 am Post subject: |
|
|
| I build in all the production-oriented cgroups and mount a single cgroup management point. It is less flexible than what you seem to be doing, but it is easy to set up and requires no additional packages. I do not use dev-libs/libcgroup. |
|
| Back to top |
|
 |
turtles Veteran


Joined: 31 Dec 2004 Posts: 1670
|
Posted: Tue Nov 29, 2011 5:04 am Post subject: |
|
|
Hi Could you give me an example?
I am not sure if what I did is working.
I just logged into a xfce session and my memory went through up to 2 gigs in less than 30 seconds.
I am not sure I am getting all the child processes.
I need to quarantine all this kit* and D-bus stuff so i can get a working system again.
This is the longest I have gone without a functional DE in a very long time. _________________ Donate to Gentoo |
|
| Back to top |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 22170
|
Posted: Wed Nov 30, 2011 4:17 am Post subject: |
|
|
From memory, assuming no prior setup on the machine:
| Code: | mount -t cgroup cgroup /sys/fs/cgroup -o nodev,noexec,blkio,freezer,devices,memory,cpuacct,cpu,cpuset,clone_children
cd /sys/fs/cgroup
mkdir udev
cd udev
for c in `pidof udev`; do echo "$c" > tasks; done
echo 1024000 > memory.max_usage_in_bytes | You may need to experiment with which memory file to use. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|