diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2018-02-06 18:37:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-06 21:32:43 -0500 |
commit | 93ad5bc6d4addb74e30d421cd3ba5249c961fb3e (patch) | |
tree | 6c739b20c4d25cab23c2bd0e008c8ded561f86c5 | |
parent | 15b158b4e6274351fc3cf652cbabc57104efb547 (diff) |
proc: rearrange args
Rearrange args for smaller code.
lookup revolves around memcmp() which gets len 3rd arg, so propagate
length as 3rd arg.
readdir and lookup add additional arg to VFS ->readdir and ->lookup, so
better add it to the end.
Space savings on x86_64:
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18 (-18)
Function old new delta
proc_readdir 22 13 -9
proc_lookup 18 9 -9
proc_match() is smaller if not inlined, I promise!
Link: http://lkml.kernel.org/r/20180104175958.GB5204@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/proc/generic.c | 18 | ||||
-rw-r--r-- | fs/proc/internal.h | 5 | ||||
-rw-r--r-- | fs/proc/proc_net.c | 4 |
3 files changed, 13 insertions, 14 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 793a67574668..5d709fa8f3a2 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | static DEFINE_RWLOCK(proc_subdir_lock); | 29 | static DEFINE_RWLOCK(proc_subdir_lock); |
30 | 30 | ||
31 | static int proc_match(unsigned int len, const char *name, struct proc_dir_entry *de) | 31 | static int proc_match(const char *name, struct proc_dir_entry *de, unsigned int len) |
32 | { | 32 | { |
33 | if (len < de->namelen) | 33 | if (len < de->namelen) |
34 | return -1; | 34 | return -1; |
@@ -60,7 +60,7 @@ static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir, | |||
60 | struct proc_dir_entry *de = rb_entry(node, | 60 | struct proc_dir_entry *de = rb_entry(node, |
61 | struct proc_dir_entry, | 61 | struct proc_dir_entry, |
62 | subdir_node); | 62 | subdir_node); |
63 | int result = proc_match(len, name, de); | 63 | int result = proc_match(name, de, len); |
64 | 64 | ||
65 | if (result < 0) | 65 | if (result < 0) |
66 | node = node->rb_left; | 66 | node = node->rb_left; |
@@ -84,7 +84,7 @@ static bool pde_subdir_insert(struct proc_dir_entry *dir, | |||
84 | struct proc_dir_entry *this = rb_entry(*new, | 84 | struct proc_dir_entry *this = rb_entry(*new, |
85 | struct proc_dir_entry, | 85 | struct proc_dir_entry, |
86 | subdir_node); | 86 | subdir_node); |
87 | int result = proc_match(de->namelen, de->name, this); | 87 | int result = proc_match(de->name, this, de->namelen); |
88 | 88 | ||
89 | parent = *new; | 89 | parent = *new; |
90 | if (result < 0) | 90 | if (result < 0) |
@@ -211,8 +211,8 @@ void proc_free_inum(unsigned int inum) | |||
211 | * Don't create negative dentries here, return -ENOENT by hand | 211 | * Don't create negative dentries here, return -ENOENT by hand |
212 | * instead. | 212 | * instead. |
213 | */ | 213 | */ |
214 | struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir, | 214 | struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, |
215 | struct dentry *dentry) | 215 | struct proc_dir_entry *de) |
216 | { | 216 | { |
217 | struct inode *inode; | 217 | struct inode *inode; |
218 | 218 | ||
@@ -235,7 +235,7 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir, | |||
235 | struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry, | 235 | struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry, |
236 | unsigned int flags) | 236 | unsigned int flags) |
237 | { | 237 | { |
238 | return proc_lookup_de(PDE(dir), dir, dentry); | 238 | return proc_lookup_de(dir, dentry, PDE(dir)); |
239 | } | 239 | } |
240 | 240 | ||
241 | /* | 241 | /* |
@@ -247,8 +247,8 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry, | |||
247 | * value of the readdir() call, as long as it's non-negative | 247 | * value of the readdir() call, as long as it's non-negative |
248 | * for success.. | 248 | * for success.. |
249 | */ | 249 | */ |
250 | int proc_readdir_de(struct proc_dir_entry *de, struct file *file, | 250 | int proc_readdir_de(struct file *file, struct dir_context *ctx, |
251 | struct dir_context *ctx) | 251 | struct proc_dir_entry *de) |
252 | { | 252 | { |
253 | int i; | 253 | int i; |
254 | 254 | ||
@@ -292,7 +292,7 @@ int proc_readdir(struct file *file, struct dir_context *ctx) | |||
292 | { | 292 | { |
293 | struct inode *inode = file_inode(file); | 293 | struct inode *inode = file_inode(file); |
294 | 294 | ||
295 | return proc_readdir_de(PDE(inode), file, ctx); | 295 | return proc_readdir_de(file, ctx, PDE(inode)); |
296 | } | 296 | } |
297 | 297 | ||
298 | /* | 298 | /* |
diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 5ba317874f0d..d697c8ab0a14 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h | |||
@@ -153,10 +153,9 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i | |||
153 | * generic.c | 153 | * generic.c |
154 | */ | 154 | */ |
155 | extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int); | 155 | extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int); |
156 | extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *, | 156 | struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *); |
157 | struct dentry *); | ||
158 | extern int proc_readdir(struct file *, struct dir_context *); | 157 | extern int proc_readdir(struct file *, struct dir_context *); |
159 | extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *); | 158 | int proc_readdir_de(struct file *, struct dir_context *, struct proc_dir_entry *); |
160 | 159 | ||
161 | static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde) | 160 | static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde) |
162 | { | 161 | { |
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index a2bf369c923d..68c06ae7888c 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c | |||
@@ -135,7 +135,7 @@ static struct dentry *proc_tgid_net_lookup(struct inode *dir, | |||
135 | de = ERR_PTR(-ENOENT); | 135 | de = ERR_PTR(-ENOENT); |
136 | net = get_proc_task_net(dir); | 136 | net = get_proc_task_net(dir); |
137 | if (net != NULL) { | 137 | if (net != NULL) { |
138 | de = proc_lookup_de(net->proc_net, dir, dentry); | 138 | de = proc_lookup_de(dir, dentry, net->proc_net); |
139 | put_net(net); | 139 | put_net(net); |
140 | } | 140 | } |
141 | return de; | 141 | return de; |
@@ -172,7 +172,7 @@ static int proc_tgid_net_readdir(struct file *file, struct dir_context *ctx) | |||
172 | ret = -EINVAL; | 172 | ret = -EINVAL; |
173 | net = get_proc_task_net(file_inode(file)); | 173 | net = get_proc_task_net(file_inode(file)); |
174 | if (net != NULL) { | 174 | if (net != NULL) { |
175 | ret = proc_readdir_de(net->proc_net, file, ctx); | 175 | ret = proc_readdir_de(file, ctx, net->proc_net); |
176 | put_net(net); | 176 | put_net(net); |
177 | } | 177 | } |
178 | return ret; | 178 | return ret; |