From patchwork Tue May 31 09:59:55 2022 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: 12865246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1AFEC4332F for ; Tue, 31 May 2022 10:00:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 726D36B0073; Tue, 31 May 2022 06:00:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FA846B0074; Tue, 31 May 2022 06:00:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C3E06B0075; Tue, 31 May 2022 06:00:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4DF3F6B0073 for ; Tue, 31 May 2022 06:00:14 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 1F659602C5 for ; Tue, 31 May 2022 10:00:14 +0000 (UTC) X-FDA: 79525592748.17.6E69F1E Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf27.hostedemail.com (Postfix) with ESMTP id E10F940024 for ; Tue, 31 May 2022 10:00:09 +0000 (UTC) Received: by mail-ej1-f54.google.com with SMTP id n10so25580020ejk.5 for ; Tue, 31 May 2022 03:00:13 -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=s/d7KhR0z000Hs/IA+QwE65RKZidQwaLcmmsuNIx8Rk=; b=jlmbD0lwi6rUzLqjCUjXO1DNk/hQQjjKuOHlr6e8k22ViZDgKVzUz93W5EYx10np0/ Xh2ALDpQ6yIyeIe45k8a2sJl4amrOM+41IYI/txxFcT5UiQiv8db1GOFm4nHNEit2nsT t6Lk/Ru1k3XgR2+zaythLqoBQNPWx0Sq35QwntG6y1Dagw4XSMLJoD/MgsY7xDjJfu0E RDqGAq6AuvEeKHy4q+b3C0gubIRXhKGHY2dodSyKGXyL5yGmdZeVPY58oq3Uvft0jR6c xVeACw7Idp6VxMTOsOvsq4Sy7+v2x6+Yzp3O+8Z7K9aogRlAi/UblC7icee5ruMftqkd rgVw== 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=s/d7KhR0z000Hs/IA+QwE65RKZidQwaLcmmsuNIx8Rk=; b=3bxcyTHG/CUv54zBYb5GkCuesBOBVUI2+XGHD3WxtgAO7ahBbjq61aPKMRvyv1f7j3 B1fQtohKMZDxZQfW8teSCdtLqpefsMyOVV0zMxbT2wz6pR5csN14Ek7zLtLUwnSFUt8Z qimETrdB4anH39kaFbaaRyOje9CfMCQBE1TWj9viuY6vjAJ/ERg3cEklfceFrzZZLkOX 1qk2NgB4f5u+DWPjBYP8J3Vi1Rp/FCUAuTd6j7IiWmN+pbVIv49LGdMko/jaSzo1OpHu elGAkvB8zb0jVDkEJgKLWcXcaUzgTaZQYqXwwWpahBV5p1VTv/zOwcFys6dDHj7WCTYC /NBg== X-Gm-Message-State: AOAM530dU9uH0+j5o7pgVmzq/sn5tzfFOEjFL6YmWXaU3nL9SnzVvF3j 0kB2LiLhWSvwqSup6+JVVkc= X-Google-Smtp-Source: ABdhPJyprdDlfIYDCtP3JSXlPBRA6lpUaNM/DoimNqu/NR7jJ7DMpCFACqCWHS14mUBV5Y9XUPfxDg== X-Received: by 2002:a17:907:9483:b0:6ff:b1:467a with SMTP id dm3-20020a170907948300b006ff00b1467amr31727121ejc.683.1653991211970; Tue, 31 May 2022 03:00:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 03:00:11 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=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 01/13] fs: add OOM badness callback to file_operatrations struct Date: Tue, 31 May 2022 11:59:55 +0200 Message-Id: <20220531100007.174649-2-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 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jlmbD0lw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of ckoenig.leichtzumerken@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=ckoenig.leichtzumerken@gmail.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E10F940024 X-Stat-Signature: uqpjepghki4fje6nwpd7ci9h3fjekc7o X-HE-Tag: 1653991209-789480 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Grodzovsky This allows file_operation implementations to specify an additional badness for the OOM killer when they allocate memory on behalf of userspace. This badness is per file because file descriptor and therefor the reference to the allocated memory can migrate between processes. For easy debugging this also adds printing of the per file oom badness to fdinfo inside procfs. Signed-off-by: Andrey Grodzovsky Signed-off-by: Christian König --- fs/proc/fd.c | 4 ++++ include/linux/fs.h | 1 + 2 files changed, 5 insertions(+) diff --git a/fs/proc/fd.c b/fs/proc/fd.c index 172c86270b31..d1905c05cb3a 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c @@ -59,6 +59,10 @@ static int seq_show(struct seq_file *m, void *v) real_mount(file->f_path.mnt)->mnt_id, file_inode(file)->i_ino); + if (file->f_op->oom_badness) + seq_printf(m, "oom_badness:\t%lu\n", + file->f_op->oom_badness(file)); + /* show_fd_locks() never deferences files so a stale value is safe */ show_fd_locks(m, file, files); if (seq_has_overflowed(m)) diff --git a/include/linux/fs.h b/include/linux/fs.h index bbde95387a23..d5222543aeb0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1995,6 +1995,7 @@ struct file_operations { struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); + long (*oom_badness)(struct file *); } __randomize_layout; struct inode_operations {