@@ -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;
+}
@@ -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))
@@ -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);
@@ -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 {