Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5774130ioo; Wed, 1 Jun 2022 12:17:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxr8RCvMhA58PIFNwGai4Re2DL3wVWpBO6mOzoJ67bLPVNVYOPF4FbRpU9mhkSvam8rpFs X-Received: by 2002:a17:90b:3b4c:b0:1e0:2c34:fbe8 with SMTP id ot12-20020a17090b3b4c00b001e02c34fbe8mr951319pjb.70.1654111043974; Wed, 01 Jun 2022 12:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654111043; cv=none; d=google.com; s=arc-20160816; b=p6YdWNAOFhehBdJuCNnaZBqeKj/Oe22afjV5i4CCV4zQA15L081Afoil7/wNN7Hktt YlPySWn+FGynIEO+Rd3Y0+50WHMLQF42XPk4U7PBcPfOLjApMNPcMejNTSXchKBwLTJu IdE04eeu74X4NWe/JRuTYyAzluv/qyTQIQ6Z/hywBB8uOOCSNnRVOao+BIRt4hzScpJN h8fG0iGqimHF/8GDrAR9Y65SiaOtaWFEW4t5CAByH6ZhA+fL/Xsj2/+7Zs8t5XajjRfq cGQzeWufJp8dz510h+Ng3c/msgx1kZ+/QCY6TTtljMhNKSgyN6j78KQ7FkeBO9eW0YYb a5CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SljQJAeVhGKeIBI51MbYTdJihy0sRNkihcgcWrQIyMk=; b=C6r171K6lB9I35QVog9Wp2fgC27+blglwgxEVV4LRYL/oJhwEDRjsqCtFQutKMHAw+ 2bC9Khle3K84ywckpQmAphHdONZwnQuhxzttw2VNp3SDwmCszW8S3p+ZVuii4e7oPD5y dtQ0FbOPXLMQ+AV08oz8aObSpr2VjhVPQT9/NHDrq2V+CElsqC0A6U3n20F82QLIqyVh SwC0glyGAtNwOLhI4GqdaOgXbwcqHCcnQzgKdFjj7eTVi+bq/SFH5dTR0+y7uATX3Onl xr0IQkYilPlHHVJYApx/whTYnYL0i+iI+i5GgbtVuW/ouU9EwNwJRITiwi8hqVjxpMuK j+1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZBp9EWdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b24-20020a17090a991800b001d9bee7dd25si6917114pjp.101.2022.06.01.12.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZBp9EWdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EED715AA6F; Wed, 1 Jun 2022 11:54:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245479AbiEaKAc (ORCPT + 99 others); Tue, 31 May 2022 06:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245405AbiEaKAP (ORCPT ); Tue, 31 May 2022 06:00:15 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB26482170; Tue, 31 May 2022 03:00:14 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id h11so16770606eda.8; Tue, 31 May 2022 03:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SljQJAeVhGKeIBI51MbYTdJihy0sRNkihcgcWrQIyMk=; b=ZBp9EWdv4dyFa/WsIYerVBV/5Czl1dSOQzB0bWaLR8VuemQ6QOm1M4R69eKpHA9nd6 c1HPF6oYuRRxZPShB/rzFxpDYr2SzpVcfmaTTI1/AsPIJMT2sPHv14VCM3Ka5VBHYXAs x+RhdpJZ93axyquUdQTI8BbhfGTHEGOHs1mum12ZFtPHB/T1dEkf20VpzDu5c8o8JJxt L5805s8can7oaGbMP04m/NeJEPnJ5J3kmnPoXDsme1EeBIo1b0t4i/Kl8NIO/OOcqJec 9FKHHAZGXXE+S9p7n7ifDG4TYZso+CBFSqXccDBgxGoDfbZX1IAhrrimZdFs69Jaqd2K a48g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SljQJAeVhGKeIBI51MbYTdJihy0sRNkihcgcWrQIyMk=; b=bIK/EBT9ZWRmBQZ1y5/uAXQZk3JD7K98FWmLdZCgazPPvb0DbfH2gHX3hHejGVWY16 A1Sm29RQo5EgZ+K5YQc2YZOkfNsAeV83zjUg5IEI44A7Jr8XxSE8FYhOmOWFzFWfOx1l VH+WKtxWfrSD9OKrHyYryG8ZWj3D0eICDCufPo4H26HN5dZbjQFDBVSibwQg9DAGWBzC j92rCISMcTjVyMxuEMqBtG46pWTyrXBxLmIlVsZlgH8+Wte6PFd8U5vBbgttRzdaJ63w zUNTYDawHw1vUPIk+YaVH+AmSekiU3B5lWo0oO/Zj/bUw4b18iuzihUim/702ixGmkjc DlYQ== X-Gm-Message-State: AOAM532J04tPSt+eeGIqlsvrdV94J54m7QWlBOQ4ogtUCrtp2btAQ1I7 CItAg0e1kpNq5fVWCfPFq0MHj2vysV3O0w== X-Received: by 2002:a05:6402:34d4:b0:42b:35e5:fc78 with SMTP id w20-20020a05640234d400b0042b35e5fc78mr53286582edc.372.1653991213421; Tue, 31 May 2022 03:00:13 -0700 (PDT) Received: from able.fritz.box (p5b0ea02f.dip0.t-ipconnect.de. [91.14.160.47]) by smtp.gmail.com with ESMTPSA id r13-20020a056402018d00b0042617ba6389sm582062edv.19.2022.05.31.03.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 03:00:13 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: christian.koenig@amd.com, alexander.deucher@amd.com, daniel@ffwll.ch, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, hughd@google.com, andrey.grodzovsky@amd.com Subject: [PATCH 02/13] oom: take per file badness into account Date: Tue, 31 May 2022 11:59:56 +0200 Message-Id: <20220531100007.174649-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220531100007.174649-1-christian.koenig@amd.com> References: <20220531100007.174649-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Grodzovsky Try to make better decisions which process to kill based on per file OOM badness. For this the per file oom badness is queried from every file which supports that and divided by the number of references to that file structure. Signed-off-by: Andrey Grodzovsky --- mm/oom_kill.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 49d7df39b02d..8a4d05e9568b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -52,6 +52,8 @@ #define CREATE_TRACE_POINTS #include +#include + int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks = 1; @@ -189,6 +191,19 @@ static bool should_dump_unreclaim_slab(void) return (global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B) > nr_lru); } +/* Sumup how much resources are bound by files opened. */ +static int oom_file_badness(const void *points, struct file *file, unsigned n) +{ + long badness; + + if (!file->f_op->oom_badness) + return 0; + + badness = file->f_op->oom_badness(file); + *((long *)points) += DIV_ROUND_UP(badness, file_count(file)); + return 0; +} + /** * oom_badness - heuristic function to determine which candidate task to kill * @p: task struct of which task we should calculate @@ -229,6 +244,12 @@ long oom_badness(struct task_struct *p, unsigned long totalpages) */ points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) + mm_pgtables_bytes(p->mm) / PAGE_SIZE; + + /* + * 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); /* Normalize to oom_score_adj units */ -- 2.25.1