[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220624080444.7619-5-christian.koenig@amd.com>
Date: Fri, 24 Jun 2022 10:04:34 +0200
From: "Christian König"
<ckoenig.leichtzumerken@...il.com>
To: linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
intel-gfx@...ts.freedesktop.org, amd-gfx@...ts.freedesktop.org,
nouveau@...ts.freedesktop.org, linux-tegra@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
dri-devel@...ts.freedesktop.org
Cc: mhocko@...e.com,
Christian König <christian.koenig@....com>
Subject: [PATCH 04/14] mm: shmem: provide RSS for shmem files
This gives the OOM killer an additional hint which processes are
referencing shmem files with potentially no other accounting for them.
Signed-off-by: Christian König <christian.koenig@....com>
---
mm/shmem.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/mm/shmem.c b/mm/shmem.c
index a6f565308133..b068ac5ba4bf 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2209,6 +2209,21 @@ unsigned long shmem_get_unmapped_area(struct file *file,
return inflated_addr;
}
+static long shmem_file_rss(struct file *file)
+{
+ struct inode *inode = file_inode(file);
+ unsigned long nrpages;
+
+ /* Only account shmem files which aren't part of any fs */
+ if (atomic_read(&inode->i_count) > 1)
+ return 0;
+
+ xa_lock(&file->f_mapping->i_pages);
+ nrpages = file->f_mapping->nrpages;
+ xa_unlock(&file->f_mapping->i_pages);
+ return nrpages;
+}
+
#ifdef CONFIG_NUMA
static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol)
{
@@ -3811,6 +3826,7 @@ EXPORT_SYMBOL(shmem_aops);
static const struct file_operations shmem_file_operations = {
.mmap = shmem_mmap,
.get_unmapped_area = shmem_get_unmapped_area,
+ .file_rss = shmem_file_rss,
#ifdef CONFIG_TMPFS
.llseek = shmem_file_llseek,
.read_iter = shmem_file_read_iter,
--
2.25.1
Powered by blists - more mailing lists