vserver 1.9.3
[linux-2.6.git] / mm / oom_kill.c
index 3de04b6..2d30feb 100644 (file)
@@ -26,6 +26,7 @@
 /**
  * oom_badness - calculate a numeric value for how bad this task has been
  * @p: task struct of which task we should calculate
+ * @p: current uptime in seconds
  *
  * The formula used is relatively simple and documented inline in the
  * function. The main rationale is that we want to select a good task
@@ -41,9 +42,9 @@
  *    of least surprise ... (be careful when you change it)
  */
 
-static int badness(struct task_struct *p)
+static unsigned long badness(struct task_struct *p, unsigned long uptime)
 {
-       int points, cpu_time, run_time, s;
+       unsigned long points, cpu_time, run_time, s;
 
        if (!p->mm)
                return 0;
@@ -57,12 +58,16 @@ static int badness(struct task_struct *p)
        /* add vserver badness ;) */
 
        /*
-        * 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.
+        * CPU time is in tens of seconds and run time is in thousands
+         * of seconds. There is no particular reason for this other than
+         * that it turned out to work very well in practice.
         */
        cpu_time = (p->utime + p->stime) >> (SHIFT_HZ + 3);
-       run_time = (get_jiffies_64() - p->start_time) >> (SHIFT_HZ + 10);
+
+       if (uptime >= p->start_time.tv_sec)
+               run_time = (uptime - p->start_time.tv_sec) >> 10;
+       else
+               run_time = 0;
 
        s = int_sqrt(cpu_time);
        if (s)
@@ -109,13 +114,15 @@ static int badness(struct task_struct *p)
  */
 static struct task_struct * select_bad_process(void)
 {
-       int maxpoints = 0;
+       unsigned long maxpoints = 0;
        struct task_struct *g, *p;
        struct task_struct *chosen = NULL;
+       struct timespec uptime;
 
+       do_posix_clock_monotonic_gettime(&uptime);
        do_each_thread(g, p)
                if (p->pid) {
-                       int points = badness(p);
+                       unsigned long points = badness(p, uptime.tv_sec);
                        if (points > maxpoints) {
                                chosen = p;
                                maxpoints = points;