Ubuntu / Linux news and application reviews.

Phoronix recently published an article regarding a ~200 lines Linux Kernel patch that improves responsiveness under system strain. Well, Lennart Poettering, a RedHat developer replied to Linus Torvalds on a maling list with an alternative to this patch that does the same thing yet all you have to do is run 2 commands and paste 4 lines in your ~/.bashrc file. I know it sounds unbelievable, but apparently someone even ran some tests which prove that Lennart's solution works. Read on!

Basically, Lennart explains you have to add this to your ~/.bashrc file (important: this won't work on Ubuntu. See instructions for Ubuntu further down the post!):

   if [ "$PS1" ] ; then  
           mkdir -m 0700 /sys/fs/cgroup/cpu/user/$$
           echo $$ > /sys/fs/cgroup/cpu/user/$$/tasks

And run the following commands as super user:
mount -t cgroup cgroup /sys/fs/cgroup/cpu -o cpu
mkdir -m 0777 /sys/fs/cgroup/cpu/user

Further more, a reply to Lennart's email states that his approach is actually better then the actual Kernel patch:

I've done some tests and the result is that Lennart's approach seems to work best. It also _feels_ better interactively compared to the vanilla kernel and in-kernel cgrougs on my machine. Also it's really nice to have an interface to actually see what is going on. With the kernel patch you're totally in the dark about what is going on right now.

-Markus Trippelsdorf

The reply also includes some benchmarks you can see @ http://lkml.org/lkml/2010/11/16/392

Use it in Ubuntu

Update (November 24): because many people had trouble following the instructions below, there is now a script that automatically does everything for you. See: Script To Automatically Apply the "200 Lines Kernel Patch" Alternative In Ubuntu

To use Lennart's solution in Ubuntu (not tested - thanks to Lsh for this), you have to replace "/sys/fs" with "/dev". So you would have to add the following commands in your /etc/rc.local (open it with: sudo gedit /etc/rc.local) file, above the "exit 0" line:

mkdir -p /dev/cgroup/cpu
mount -t cgroup cgroup /dev/cgroup/cpu -o cpu
mkdir -m 0777 /dev/cgroup/cpu/user
echo "/usr/local/sbin/cgroup_clean" > /dev/cgroup/cpu/release_agent

and make it executable:
sudo chmod +x /etc/rc.local

And then add the following to your ~/.bashrc file (to open it: gedit ~/.bashrc):

if [ "$PS1" ] ; then  
   mkdir -p -m 0700 /dev/cgroup/cpu/user/$$ > /dev/null 2>&1
   echo $$ > /dev/cgroup/cpu/user/$$/tasks
   echo "1" > /dev/cgroup/cpu/user/$$/notify_on_release

Run the following command:
sudo gedit /usr/local/sbin/cgroup_clean

And paste this:

if [ "$*" != "/user" ]; then
rmdir /dev/cgroup/cpu/$*

then save the file and make it executable:
sudo chmod +x /usr/local/sbin/cgroup_clean

And finally, restart the computer or manually run the /etc/rc.local file ("sudo /etc/rc.local").

Update November 19: The above instructions have been updated again to "really" automatically remove empty cgroups (thank to Ricardo Ferreira using the instructions he sent.).

Update 2: if you don't want to follow the manual steps above, you can use some patched kernels (Warning: use these at your own risk!!!) for Ubuntu 10.10:

If you want to go even further and install a patched Kernel, you can download a "200 lines" patched Kernel (for 64bit only!) from HERE (thanks to accumulator @ Phoronix forums).

Also, WebUpd8 reader Scott Franke shared a Kernel he patched with bfs with which he says he gets better performance then with the "200 lines patch". Download (also 64bit only!): 1 and 2 (both .deb files required).

Both of the above 2 Kernels are for Ubuntu 10.10 only! Use them at your own risk!

Read the discussion @ http://lkml.org/lkml/2010/11/16/392 | via Habrahabr.ru (thanks to Lsh)

More on this topic: