From: Christian König <christian.koenig@xxxxxxx> Try to make better decisions which process to kill based on per file OOM badness. Signed-off-by: Christian König <christian.koenig@xxxxxxx> Reviewed-by: Alex Deucher <alexander.deucher@xxxxxxx> --- mm/oom_kill.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 2b665da..4bcb3f4 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -35,6 +35,7 @@ #include <linux/freezer.h> #include <linux/ftrace.h> #include <linux/ratelimit.h> +#include <linux/fdtable.h> #define CREATE_TRACE_POINTS #include <trace/events/oom.h> @@ -138,6 +139,19 @@ static bool oom_unkillable_task(struct task_struct *p, } /** + * oom_file_badness - add per file badness + * @points: pointer to summed up badness points + * @file: tasks open file + * @n: file descriptor id (unused) + */ +static int oom_file_badness(const void *points, struct file *file, unsigned n) +{ + *((long*)points) += atomic_long_read(&file->f_oom_badness); + + return 0; +} + +/** * oom_badness - heuristic function to determine which candidate task to kill * @p: task struct of which task we should calculate * @totalpages: total present RAM allowed for page allocation @@ -171,6 +185,12 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, */ points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) + atomic_long_read(&p->mm->nr_ptes) + mm_nr_pmds(p->mm); + + /* + * Add how much memory a task uses in opened files, e.g. device drivers. + */ + iterate_fd(p->files, 0, oom_file_badness, &points); + task_unlock(p); /* -- 1.9.1 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel