* [PATCH] proc: calculate end pointer for /proc/*/* lookup at compile time
@ 2019-01-14 20:04 Alexey Dobriyan
2019-01-29 22:18 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2019-01-14 20:04 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
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
Note: this trick bloats readdir, so don't do it :-\
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
fs/proc/base.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2459,11 +2459,10 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry,
static struct dentry *proc_pident_lookup(struct inode *dir,
struct dentry *dentry,
- const struct pid_entry *ents,
- unsigned int nents)
+ const struct pid_entry *p,
+ const struct pid_entry *end)
{
struct task_struct *task = get_proc_task(dir);
- const struct pid_entry *p, *last;
struct dentry *res = ERR_PTR(-ENOENT);
if (!task)
@@ -2473,8 +2472,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
* Yes, it does not scale. And it should not. Don't add
* new entries into /proc/<tgid>/ without very good reasons.
*/
- last = &ents[nents];
- for (p = ents; p < last; p++) {
+ for (; p < end; p++) {
if (p->len != dentry->d_name.len)
continue;
if (!memcmp(dentry->d_name.name, p->name, p->len)) {
@@ -2613,7 +2611,8 @@ static struct dentry *proc_attr_dir_lookup(struct inode *dir,
struct dentry *dentry, unsigned int flags)
{
return proc_pident_lookup(dir, dentry,
- attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff));
+ attr_dir_stuff,
+ attr_dir_stuff + ARRAY_SIZE(attr_dir_stuff));
}
static const struct inode_operations proc_attr_dir_inode_operations = {
@@ -3049,7 +3048,8 @@ static const struct file_operations proc_tgid_base_operations = {
static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
{
return proc_pident_lookup(dir, dentry,
- tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
+ tgid_base_stuff,
+ tgid_base_stuff + ARRAY_SIZE(tgid_base_stuff));
}
static const struct inode_operations proc_tgid_base_inode_operations = {
@@ -3421,7 +3421,8 @@ static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
{
return proc_pident_lookup(dir, dentry,
- tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
+ tid_base_stuff,
+ tid_base_stuff + ARRAY_SIZE(tid_base_stuff));
}
static const struct file_operations proc_tid_base_operations = {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] proc: calculate end pointer for /proc/*/* lookup at compile time
2019-01-14 20:04 [PATCH] proc: calculate end pointer for /proc/*/* lookup at compile time Alexey Dobriyan
@ 2019-01-29 22:18 ` Andrew Morton
2019-01-30 5:55 ` Alexey Dobriyan
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2019-01-29 22:18 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel
On Mon, 14 Jan 2019 23:04:23 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 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
>
> Note: this trick bloats readdir, so don't do it :-\
I don't understand the Note:. Can you please expand?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] proc: calculate end pointer for /proc/*/* lookup at compile time
2019-01-29 22:18 ` Andrew Morton
@ 2019-01-30 5:55 ` Alexey Dobriyan
0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2019-01-30 5:55 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
On Tue, Jan 29, 2019 at 02:18:48PM -0800, Andrew Morton wrote:
> On Mon, 14 Jan 2019 23:04:23 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> > 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
> >
> > Note: this trick bloats readdir, so don't do it :-\
>
> I don't understand the Note:. Can you please expand?
The same could be done to proc_pident_readdir(), but the code becomes
bigger for some reason.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-30 5:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 20:04 [PATCH] proc: calculate end pointer for /proc/*/* lookup at compile time Alexey Dobriyan
2019-01-29 22:18 ` Andrew Morton
2019-01-30 5:55 ` Alexey Dobriyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).