--- linux-orig/mm/oom_kill.c 2005-02-23 20:03:11.000000000 -0500 +++ linux-2.6.10/mm/oom_kill.c 2005-02-25 00:21:20.000000000 -0500 @@ -44,8 +44,10 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) { - unsigned long points, cpu_time, run_time, s; + unsigned long points, cpu_time, run_time, s, pct_occ; + extern unsigned long num_physpages; struct list_head *tsk; + int is_superuser=0, has_hwaccess=0; if (!p->mm) return 0; @@ -55,6 +57,39 @@ */ points = p->mm->total_vm; + if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) || + p->uid == 0 || p->euid == 0) + { + is_superuser=1; + + } + + if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO)) { + has_hwaccess=1; + } + + if(is_superuser || has_hwaccess) + goto skip_pct_chk; + + /* If the process + * a. Does not belong to superuser + * b. Does not have hardware access, and + * c. Occupies more than or equal to 50% memory + * it is a very likely candidate to kill. + */ + pct_occ = points*100 / num_physpages; + + if (pct_occ >= 60) { +#ifdef DEBUG + printk(KERN_DEBUG "Process %s with PID %d occupied more + than 60% memory\n", p->comm, p->pid); +#endif + /* Return unusually high number to make sure this process + * gets killed + */ + return points*pct_occ; + } + skip_pct_chk: /* * Processes which fork a lot of child processes are likely * a good choice. We add the vmsize of the childs if they @@ -99,8 +134,7 @@ * Superuser processes are usually more important, so we make it * less likely that we kill those. */ - if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) || - p->uid == 0 || p->euid == 0) + if (is_superuser) points /= 4; /* @@ -109,7 +143,7 @@ * tend to only have this flag set on applications they think * of as important. */ - if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO)) + if (has_hwaccess) points /= 4; /*