History

proc: decouple proc from VFS with "struct proc_ops"

Currently core /proc code uses "struct file_operations" for custom hooks, however, VFS doesn't directly call them. Every time VFS expands file_operations hook set, /proc code bloats for no reason. Introduce "struct proc_ops" which contains only those hooks which /proc allows to call into (open, release, read, write, ioctl, mmap, poll). It doesn't contain module pointer as well. Save ~184 bytes per usage: add/remove: 26/26 grow/shrink: 1/4 up/down: 1922/-6674 (-4752) Function old new delta sysvipc_proc_ops - 72 +72 ... config_gz_proc_ops - 72 +72 proc_get_inode 289 339 +50 proc_reg_get_unmapped_area 110 107 -3 close_pdeo 227 224 -3 proc_reg_open 289 284 -5 proc_create_data 60 53 -7 rt_cpu_seq_fops 256 - -256 ... default_affinity_proc_fops 256 - -256 Total: Before=5430095, After=5425343, chg -0.09%

Alexey Dobriyan committed 6 years ago

Commit d56c0d41 parent 0d6e24d7 files · +98 −80Browse files

Showing the changes to include/linux (1 of 7 files). Show all

Unified · Split

include/linux/proc_fs.h+19−4
@@ -12,6 +12,21 @@ struct proc_dir_entry; · 11 unmodified lines
1212 struct seq_file;
1313 struct seq_operations;
1414
15+struct proc_ops {
16+ int (*proc_open)(struct inode *, struct file *);
17+ ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
18+ ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
19+ loff_t (*proc_lseek)(struct file *, loff_t, int);
20+ int (*proc_release)(struct inode *, struct file *);
21+ __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
22+ long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
23+#ifdef CONFIG_COMPAT
24+ long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
25+#endif
26+ int (*proc_mmap)(struct file *, struct vm_area_struct *);
27+ unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
28+};
29+
1530 #ifdef CONFIG_PROC_FS
1631
1732 typedef int (*proc_write_t)(struct file *, char *, size_t);
@@ -43,10 +58,10 @@ struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode, · 25 unmodified lines
4358
4459 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
4560 struct proc_dir_entry *,
46− const struct file_operations *,
61+ const struct proc_ops *,
4762 void *);
4863
49−struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
64+struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
5065 extern void proc_set_size(struct proc_dir_entry *, loff_t);
5166 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
5267 extern void *PDE_DATA(const struct inode *);
@@ -108,8 +123,8 @@ static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, · 55 unmodified lines
108123 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
109124 #define proc_create_single(name, mode, parent, show) ({NULL;})
110125 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
111−#define proc_create(name, mode, parent, proc_fops) ({NULL;})
112−#define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
126+#define proc_create(name, mode, parent, proc_ops) ({NULL;})
127+#define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
113128
114129 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
115130 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}