Hi I finally solved this issue. The problem can be re-described as follows. I am using my desktop computer to run simulations. I have 64 bit linux and 4GB RAM. I run simulations which can run for tenths of minutes and use a lot of virtual memory (a python script using numpy on large matrices). While waiting for the simultations to finish, I would like to use the pc for interactive tasks (such as web browsing). The problem is that the simulation uses a lot of cpu compared to interactive processes and accesses to the memory much more frequently. Therefore the LRU list of active pages fills up with pages belonging to the simulation while the pages owned by the interactive processes are swapped away. Thus, even if I am using, say firefox, the python script gets almost all my physical memory and the system becomes unresponsive (because X, firefox, etc are being swapped away). Setting nice to a higher level does not help, because almost all the cpu is used by the script anyway. I do not want to limit the amount of virtual memory available to the script (e.g. using the ulimit -v argument of bash) but I would like to limit the amount of physical memory to, say, 3GB out of 4. If I am not wrong, this would make the script swap (I do not care if it takes a little more) more but could avoid X to swap every time I move the mouse. The problem is that the rss max size limit is not enforced. I asked Rik van Riel about an old patch he created to enforce the rss limit. He kindly answered me and pointed me out that newer kernels provide cgroups wich can solve my issue. Therefore, after reading some documentation about cgroups, I wrote the following script. I also added a link in /etc/init.d and run update-rc.d to make it start at boot.
Usage: ungreedy start # mounts the cgroups filesystem, creates the ungreedy cgroup and sets the rss limit to a percentage of the available RAM ungreedy on # assigns the current bash to the ungreedy cgroup and every process started form it (past and future) ungreedy # same as before ungreedy off # removes the current bash from the ungreedy cgroup ungreedy CMD ARG1 ARG2 # executes the CMD command under the ungreedy cgroup ungreedy stop # umounts the cgroups filesystem ######## ungreedy ########## #! /bin/sh PERC="0.75" CMD=${1:-on} case "$CMD" in start) if ! test -d /dev/cgroups/ungreedy ; then if ! test -d /dev/cgroups ; then mkdir -p /dev/cgroups mount -t cgroup none /dev/cgroups -o memory fi mkdir -p /dev/cgroups/ungreedy chmod a+w /dev/cgroups/ungreedy/memory.limit_in_bytes /dev/cgroups/ungreedy/tasks /dev/cgroups/tasks memlimit=$(cat /proc/meminfo | awk '/MemTotal/ {print int($2*p)substr($3,1,1)}' p=$PERC) /bin/echo $memlimit > /dev/cgroups/ungreedy/memory.limit_in_bytes fi ;; stop) umount /dev/cgroups rm -r /dev/cgroups ;; on) /bin/echo $PPID > /dev/cgroups/ungreedy/tasks ;; off) /bin/echo $PPID > /dev/cgroups/tasks ;; *) /bin/echo $$ > /dev/cgroups/ungreedy/tasks $@ ;; esac -- Ubuntu interface becomes unresponsive underheavy load https://bugs.launchpad.net/bugs/289892 You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs