/**
* 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
* 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;
/* 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)
*/
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;