From patchwork Fri Sep 4 12:53:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 7122021 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5077E9F32B for ; Fri, 4 Sep 2015 12:55:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FF7B2089D for ; Fri, 4 Sep 2015 12:55:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F25FD20896 for ; Fri, 4 Sep 2015 12:55:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A39E6EBC0; Fri, 4 Sep 2015 05:55:19 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pegasos-out.vodafone.de (pegasos-out.vodafone.de [80.84.1.38]) by gabe.freedesktop.org (Postfix) with ESMTP id 126806EBC2 for ; Fri, 4 Sep 2015 05:55:18 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 30107261384; Fri, 4 Sep 2015 14:55:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at vodafone.de X-Spam-Score: -0.054 X-Spam-Level: X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Authentication-Results: rohrpostix1.prod.vfnet.de (amavisd-new); dkim=pass header.i=@vodafone.de Received: from pegasos-out.vodafone.de ([127.0.0.1]) by localhost (rohrpostix1.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IN5cgRLXNvwf; Fri, 4 Sep 2015 14:55:15 +0200 (CEST) Received: from smtp-05.vodafone.de (smtp-05.vodafone.de [10.215.254.32]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 915C1260754; Fri, 4 Sep 2015 14:55:15 +0200 (CEST) X-DKIM: OpenDKIM Filter v2.6.8 pegasos-out.vodafone.de 915C1260754 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafone.de; s=mail; t=1441371315; bh=jwXgfA1ZITJhL1d+pRAof0n/zcEZWMjHFnmljg9JLi8=; h=From:To:Subject:Date:In-Reply-To:References; b=XFNNv6/z5JKi9FIzk9ko3iiwfFf06H2TDvO+G7VImMUigsEtKcL5EDWZ6z4lntcmi LdAtAD4GpgvOQbpAQkKf1VEJIUPE9OrbAXwBhReftR1pmZII9vl5Qt7N4k3J49SdSW 6HBJQxciQBDj6PC6mW6n5OC53xvzUXfO44K2mYg8= X-Virus-Scanned: amavisd-new at vodafone.de Received: from smtp-05.vodafone.de ([127.0.0.1]) by localhost (xsmail-dmz1.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J8Wa5d-+o6B8; Fri, 4 Sep 2015 14:55:13 +0200 (CEST) From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: lkml@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] oom: take per file badness into account Date: Fri, 4 Sep 2015 14:53:32 +0200 Message-Id: <1441371213-3543-4-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441371213-3543-1-git-send-email-deathsimple@vodafone.de> References: <1441371213-3543-1-git-send-email-deathsimple@vodafone.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Try to make better decisions which process to kill based on per file OOM badness. Signed-off-by: Christian König Reviewed-by: Alex Deucher --- 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 #include #include +#include #define CREATE_TRACE_POINTS #include @@ -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); /*