Andre Schulze (as8@Rcs1.urz.tu-dresden.de) wrote:
AS> Am Don den 22 Feb 2001 um 10:44:53 +0100 schrieb Reinhard Foerster:
Wie sieht es damit eigentlich in 2.4.x aus? Wurde dort der Umgang mit Speichenengpässen geändert?
AS> Super! Obwohl das Verhalten mit dem overcommit memory immer noch so AS> ist, trifft es jetzt wenigstens bei kills den richtigen Übeltäter. Das AS> Verhalten ist reproduzierbar. Ob immer der größte Prozess gesteinigt AS> wird, muß man wohl mal im Code nachsehen.
Ich poste einfach mal den Ausschnitt aus /usr/src/linux-2.4.0/mm/oom_kill.c ... man möge mir verzeihen, falls das irgendwie gegen die Netikette ist.
/** * oom_badness - calculate a numeric value for how bad this task has been * @p: task struct of which task we should calculate * * The formula used is relatively simple and documented inline in the * function. The main rationale is that we want to select a good task * to kill when we run out of memory. * * Good in this context means that: * to kill when we run out of memory. * * Good in this context means that: * 1) we lose the minimum amount of work done * 2) we recover a large amount of memory * 3) we don't kill anything innocent of eating tons of memory * 4) we want to kill the minimum amount of processes (one) * 5) we try to kill the process the user expects us to kill, this * algorithm has been meticulously tuned to meet the priniciple * of least surprise ... (be careful when you change it) */
static int badness(struct task_struct *p) { int points, cpu_time, run_time;
if (!p->mm) return 0; /* * The memory size of the process is the basis for the badness. */ points = p->mm->total_vm;
/* * CPU time is in seconds and run time is in minutes. There is no * particular reason for this other than that it turned out to work * very well in practice. This is not safe against jiffie wraps * but we don't care _that_ much... */ cpu_time = (p->times.tms_utime + p->times.tms_stime) >> (SHIFT_HZ + 3); run_time = (jiffies - p->start_time) >> (SHIFT_HZ + 10);
points /= int_sqrt(cpu_time); points /= int_sqrt(int_sqrt(run_time));
/* * Niced processes are most likely less important, so double * their badness points. */ if (p->nice > 0) points *= 2;
/* * 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) points /= 4;
/* * We don't want to kill a process with direct hardware access. * Not only could that mess up the hardware, but usually users * 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)) points /= 4; #ifdef DEBUG printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n", p->pid, p->comm, points); #endif return points; }