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
12struct seq_file;12struct seq_file;
13struct seq_operations;13struct seq_operations;
14 14
15struct 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
15#ifdef CONFIG_PROC_FS30#ifdef CONFIG_PROC_FS
16 31
17typedef int (*proc_write_t)(struct file *, char *, size_t);32typedef 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
43 58
44extern struct proc_dir_entry *proc_create_data(const char *, umode_t,59extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
45 struct proc_dir_entry *,60 struct proc_dir_entry *,
46 const struct file_operations *,61 const struct proc_ops *,
47 void *);62 void *);
48 63
49struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);64struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
50extern void proc_set_size(struct proc_dir_entry *, loff_t);65extern void proc_set_size(struct proc_dir_entry *, loff_t);
51extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);66extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
52extern void *PDE_DATA(const struct inode *);67extern 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
108#define proc_create_seq(name, mode, parent, ops) ({NULL;})123#define proc_create_seq(name, mode, parent, ops) ({NULL;})
109#define proc_create_single(name, mode, parent, show) ({NULL;})124#define proc_create_single(name, mode, parent, show) ({NULL;})
110#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})125#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
111#define proc_create(name, mode, parent, proc_fops) ({NULL;})126#define proc_create(name, mode, parent, proc_ops) ({NULL;})
112#define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})127#define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
113 128
114static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}129static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
115static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}130static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}