From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
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,
dri-devel@lists.freedesktop.org
Cc: mhocko@suse.com, "Andrey Grodzovsky" <andrey.grodzovsky@amd.com>,
"Christian König" <christian.koenig@amd.com>
Subject: [PATCH 01/14] fs: add per file RSS
Date: Fri, 24 Jun 2022 10:04:31 +0200 [thread overview]
Message-ID: <20220624080444.7619-2-christian.koenig@amd.com> (raw)
In-Reply-To: <20220624080444.7619-1-christian.koenig@amd.com>
From: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Some files allocate large amounts of memory on behalf of userspace without
any on disk backing store. This memory isn't necessarily mapped into the
address space, but should still accounts towards the RSS of a process just
like mapped shared pages do.
That information can then be used by the OOM killer to make better
decisions which process to reap.
For easy debugging this also adds printing of the per file RSS to fdinfo.
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
---
fs/file.c | 23 +++++++++++++++++++++++
fs/proc/fd.c | 3 +++
include/linux/fdtable.h | 1 +
include/linux/fs.h | 1 +
4 files changed, 28 insertions(+)
diff --git a/fs/file.c b/fs/file.c
index 3bcc1ecc314a..b58730a513be 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -1307,3 +1307,26 @@ int iterate_fd(struct files_struct *files, unsigned n,
return res;
}
EXPORT_SYMBOL(iterate_fd);
+
+static int sumup_file_rss(const void *sum, struct file *file, unsigned n)
+{
+ if (!file->f_op->file_rss)
+ return 0;
+
+ *((unsigned long *)sum) += file->f_op->file_rss(file);
+ return 0;
+}
+
+/**
+ * files_rss- how much resources are bound by opened files
+ * @files: opened files
+ *
+ * Returns sum of all resources bound by files not accounted in file systems.
+ */
+unsigned long files_rss(struct files_struct *files)
+{
+ unsigned long sum = 0;
+
+ iterate_fd(files, 0, sumup_file_rss, &sum);
+ return sum;
+}
diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index 913bef0d2a36..9943bfca74f7 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -59,6 +59,9 @@ 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->file_rss)
+ seq_printf(m, "rss:\t%lu\n", file->f_op->file_rss(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/fdtable.h b/include/linux/fdtable.h
index e066816f3519..101770266f38 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -122,6 +122,7 @@ void do_close_on_exec(struct files_struct *);
int iterate_fd(struct files_struct *, unsigned,
int (*)(const void *, struct file *, unsigned),
const void *);
+unsigned long files_rss(struct files_struct *files);
extern int close_fd(unsigned int fd);
extern int __close_range(unsigned int fd, unsigned int max_fd, unsigned int flags);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9ad5e3520fae..edacbdce5e4c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2003,6 +2003,7 @@ struct file_operations {
loff_t len, unsigned int remap_flags);
int (*fadvise)(struct file *, loff_t, loff_t, int);
int (*uring_cmd)(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
+ long (*file_rss)(struct file *);
} __randomize_layout;
struct inode_operations {
--
2.25.1
next prev parent reply other threads:[~2022-06-24 8:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 8:04 [RFC] Per file OOM-badness / RSS once more Christian König
2022-06-24 8:04 ` Christian König [this message]
2022-06-24 8:04 ` [PATCH 02/14] oom: take per file RSS into account Christian König
2022-06-24 8:04 ` [PATCH 03/14] proc: expose per file RSS Christian König
2022-06-24 8:04 ` [PATCH 04/14] mm: shmem: provide RSS for shmem files Christian König
2022-06-24 8:04 ` [PATCH 05/14] dma-buf: provide file RSS for DMA-buf files Christian König
2022-06-24 8:04 ` [PATCH 06/14] drm/gem: adjust per file RSS on handling buffers Christian König
2022-06-24 8:04 ` [PATCH 07/14] drm/gma500: use drm_file_rss Christian König
2022-06-24 8:04 ` [PATCH 08/14] drm/amdgpu: " Christian König
2022-06-24 8:04 ` [PATCH 09/14] drm/radeon: use drm_oom_badness Christian König
2022-06-28 10:34 ` Michel Dänzer
2022-06-24 8:04 ` [PATCH 10/14] drm/i915: use drm_file_rss Christian König
2022-06-24 8:04 ` [PATCH 11/14] drm/nouveau: " Christian König
2022-06-24 8:04 ` [PATCH 12/14] drm/omap: " Christian König
2022-06-24 8:04 ` [PATCH 13/14] drm/vmwgfx: " Christian König
2022-06-24 8:04 ` [PATCH 14/14] drm/tegra: " Christian König
2022-06-24 9:59 ` [RFC] Per file OOM-badness / RSS once more Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220624080444.7619-2-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrey.grodzovsky@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=nouveau@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®