Thursday, May 13, 2010

TerminateSafe, Save-free Applications, and oom_adj

The logo of freedesktop.Image via Wikipedia
There's a good proposal going through the rounds on the FreeDesktop.org mailing list which seeks to help the kernel decide which process(es) to kill first in the event of memory pressure. The proposal is simply adding a TerminateSafe=true key to the .desktop files of applications which are stateless or which constantly save user data. Examples of stateless applications might be the character map and calculator tool. Applications which save continuously might include Tomboy. Terminals, office suites, and IDEs would not have this key set to "true."

The Linux kernel's OOM (out of memory) Killer has a method to determine which processes get killed first in a critical situation: it's called "magic." No, not really. It is complicated, though, and it offers a "user-friendly" way to help the kernel make its decision. oom_score is located in /proc/ under the number of each running process. The oom_score for each process is based on factors such as memory use and running time. The process directory also contains oom_adj, which, as the name suggests, allows one to adjust the score of the process. Think of it like nice, but for killing, not running.

If TerminateSafe=true were implemented on Linux, it would likely signal the desktop environment to adjust oom_score to put the application on the top op the assassination list using oom_adj. Other OSes might use a different method or not support the key at all.

The problem with this approach is that the process the .desktop file spawns may not even be the main process if the file calls a script. The situation is made worse by processes that fork. Luckily, the kernel offers process groups to handle this situation, something Systemd is planning to use.

I hope you've heard of Systemd, the init/upstart replacement with a model half way between launchd and inetd. If you haven't you should take a look at it.
Reblog this post [with Zemanta]

No comments:

Post a Comment

Other I' Been to Ubuntu Stories

Related Posts with Thumbnails