[01/13] fs: add OOM badness callback to file_operatrations struct
Commit Message
From: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
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 <andrey.grodzovsky@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
---
fs/proc/fd.c | 4 ++++
include/linux/fs.h | 1 +
2 files changed, 5 insertions(+)
@@ -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))
@@ -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 {