diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2019-03-12 02:28:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 13:04:01 -0400 |
commit | d5a572a4cb1e484d8d8c79bdfd16aaa18fa1470b (patch) | |
tree | 60509f727ebe752228ef7a7f3f19b704ae6a5780 /fs/proc | |
parent | b5420237ec817b0b5f729a674c81ace0865c3b3b (diff) |
proc: calculate end pointer for /proc/*/* lookup at compile time
Compilers like to transform loops like
for (i = 0; i < n; i++) {
[use p[i]]
}
into
for (p = p0; p < end; p++) {
...
}
Do it by hand, so that it results in overall simpler loop
and smaller code.
Space savings:
$ ./scripts/bloat-o-meter ../vmlinux-001 ../obj/vmlinux
add/remove: 0/0 grow/shrink: 2/1 up/down: 4/-9 (-5)
Function old new delta
proc_tid_base_lookup 17 19 +2
proc_tgid_base_lookup 17 19 +2
proc_pident_lookup 179 170 -9
The same could be done to proc_pident_readdir(), but the code becomes
bigger for some reason.
[sfr@canb.auug.org.au: merge fix for proc_pident_lookup() API change]
Link: http://lkml.kernel.org/r/20190131160135.4a8ae70b@canb.auug.org.au
Link: http://lkml.kernel.org/r/20190114200422.GB9680@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: James Morris <jmorris@namei.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/base.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 5ab1849971b4..1b548d060d28 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -2459,11 +2459,10 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry, | |||
2459 | 2459 | ||
2460 | static struct dentry *proc_pident_lookup(struct inode *dir, | 2460 | static struct dentry *proc_pident_lookup(struct inode *dir, |
2461 | struct dentry *dentry, | 2461 | struct dentry *dentry, |
2462 | const struct pid_entry *ents, | 2462 | const struct pid_entry *p, |
2463 | unsigned int nents) | 2463 | const struct pid_entry *end) |
2464 | { | 2464 | { |
2465 | struct task_struct *task = get_proc_task(dir); | 2465 | struct task_struct *task = get_proc_task(dir); |
2466 | const struct pid_entry *p, *last; | ||
2467 | struct dentry *res = ERR_PTR(-ENOENT); | 2466 | struct dentry *res = ERR_PTR(-ENOENT); |
2468 | 2467 | ||
2469 | if (!task) | 2468 | if (!task) |
@@ -2473,8 +2472,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
2473 | * Yes, it does not scale. And it should not. Don't add | 2472 | * Yes, it does not scale. And it should not. Don't add |
2474 | * new entries into /proc/<tgid>/ without very good reasons. | 2473 | * new entries into /proc/<tgid>/ without very good reasons. |
2475 | */ | 2474 | */ |
2476 | last = &ents[nents]; | 2475 | for (; p < end; p++) { |
2477 | for (p = ents; p < last; p++) { | ||
2478 | if (p->len != dentry->d_name.len) | 2476 | if (p->len != dentry->d_name.len) |
2479 | continue; | 2477 | continue; |
2480 | if (!memcmp(dentry->d_name.name, p->name, p->len)) { | 2478 | if (!memcmp(dentry->d_name.name, p->name, p->len)) { |
@@ -2610,7 +2608,7 @@ static struct dentry *proc_##LSM##_attr_dir_lookup(struct inode *dir, \ | |||
2610 | { \ | 2608 | { \ |
2611 | return proc_pident_lookup(dir, dentry, \ | 2609 | return proc_pident_lookup(dir, dentry, \ |
2612 | LSM##_attr_dir_stuff, \ | 2610 | LSM##_attr_dir_stuff, \ |
2613 | ARRAY_SIZE(LSM##_attr_dir_stuff)); \ | 2611 | LSM##_attr_dir_stuff + ARRAY_SIZE(LSM##_attr_dir_stuff)); \ |
2614 | } \ | 2612 | } \ |
2615 | \ | 2613 | \ |
2616 | static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \ | 2614 | static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \ |
@@ -2655,7 +2653,8 @@ static struct dentry *proc_attr_dir_lookup(struct inode *dir, | |||
2655 | struct dentry *dentry, unsigned int flags) | 2653 | struct dentry *dentry, unsigned int flags) |
2656 | { | 2654 | { |
2657 | return proc_pident_lookup(dir, dentry, | 2655 | return proc_pident_lookup(dir, dentry, |
2658 | attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff)); | 2656 | attr_dir_stuff, |
2657 | attr_dir_stuff + ARRAY_SIZE(attr_dir_stuff)); | ||
2659 | } | 2658 | } |
2660 | 2659 | ||
2661 | static const struct inode_operations proc_attr_dir_inode_operations = { | 2660 | static const struct inode_operations proc_attr_dir_inode_operations = { |
@@ -3091,7 +3090,8 @@ static const struct file_operations proc_tgid_base_operations = { | |||
3091 | static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) | 3090 | static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) |
3092 | { | 3091 | { |
3093 | return proc_pident_lookup(dir, dentry, | 3092 | return proc_pident_lookup(dir, dentry, |
3094 | tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff)); | 3093 | tgid_base_stuff, |
3094 | tgid_base_stuff + ARRAY_SIZE(tgid_base_stuff)); | ||
3095 | } | 3095 | } |
3096 | 3096 | ||
3097 | static const struct inode_operations proc_tgid_base_inode_operations = { | 3097 | static const struct inode_operations proc_tgid_base_inode_operations = { |
@@ -3463,7 +3463,8 @@ static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx) | |||
3463 | static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) | 3463 | static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) |
3464 | { | 3464 | { |
3465 | return proc_pident_lookup(dir, dentry, | 3465 | return proc_pident_lookup(dir, dentry, |
3466 | tid_base_stuff, ARRAY_SIZE(tid_base_stuff)); | 3466 | tid_base_stuff, |
3467 | tid_base_stuff + ARRAY_SIZE(tid_base_stuff)); | ||
3467 | } | 3468 | } |
3468 | 3469 | ||
3469 | static const struct file_operations proc_tid_base_operations = { | 3470 | static const struct file_operations proc_tid_base_operations = { |