Jesper Juhl | 11 Dec 06:40
Picon

[PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c

Here's a small patch to reduce the nr. of pointer dereferences in
fs/jffs2/summary.c

Benefits:
 - micro speed optimization due to fewer pointer derefs
 - generated code is slightly smaller
 - better readability

Please consider applying...

Signed-off-by: Jesper Juhl <jesper.juhl <at> gmail.com>
---

 fs/jffs2/summary.c |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)

orig:
   text    data     bss     dec     hex filename
   5033       0       0    5033    13a9 fs/jffs2/summary.o
patched:
   text    data     bss     dec     hex filename
   4935       0       0    4935    1347 fs/jffs2/summary.o

--- linux-2.6.15-rc5-git1-orig/fs/jffs2/summary.c	2005-12-04 18:48:38.000000000 +0100
+++ linux-2.6.15-rc5-git1/fs/jffs2/summary.c	2005-12-11 06:01:51.000000000 +0100
@@ -581,16 +581,17 @@ static int jffs2_sum_write_data(struct j
 	wpage = c->summary->sum_buf;

 	while (c->summary->sum_num) {
+		temp = c->summary->sum_list_head;
(Continue reading)

Adrian Bunk | 11 Dec 19:07
Picon
Favicon

[2.6 patch] remove fs/jffs2/ioctl.c

There doesn't seem to be any reason for keeping fs/jffs2/ioctl.c .

Signed-off-by: Adrian Bunk <bunk <at> stusta.de>

---

This patch was already sent on:
- 1 Nov 2005

 fs/jffs2/Makefile   |    2 +-
 fs/jffs2/dir.c      |    1 -
 fs/jffs2/file.c     |    1 -
 fs/jffs2/ioctl.c    |   23 -----------------------
 fs/jffs2/os-linux.h |    3 ---
 5 files changed, 1 insertion(+), 29 deletions(-)

--- linux-2.6.14-rc5-mm1-full/fs/jffs2/os-linux.h.old	2005-11-01 20:28:24.000000000 +0100
+++ linux-2.6.14-rc5-mm1-full/fs/jffs2/os-linux.h	2005-11-01 20:28:31.000000000 +0100
@@ -147,9 +147,6 @@
 int jffs2_fsync(struct file *, struct dentry *, int);
 int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg);

-/* ioctl.c */
-int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
-
 /* symlink.c */
 extern struct inode_operations jffs2_symlink_inode_operations;

--- linux-2.6.14-rc5-mm1-full/fs/jffs2/dir.c.old	2005-11-01 20:28:39.000000000 +0100
+++ linux-2.6.14-rc5-mm1-full/fs/jffs2/dir.c	2005-11-01 20:28:43.000000000 +0100
(Continue reading)

Josh Boyer | 11 Dec 23:13
Picon

Re: [2.6 patch] remove fs/jffs2/ioctl.c

On 12/11/05, Adrian Bunk <bunk <at> stusta.de> wrote:
> There doesn't seem to be any reason for keeping fs/jffs2/ioctl.c .
>
>
> Signed-off-by: Adrian Bunk <bunk <at> stusta.de>
>
> ---
>
> This patch was already sent on:
> - 1 Nov 2005

With ACKs by a couple people on the list whose opinion doesn't quite
carry as much weight as David's.

josh
Jan Engelhardt | 15 Dec 23:55
Picon

Re: [PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c


>Benefits:
> - micro speed optimization due to fewer pointer derefs
> - generated code is slightly smaller

Should not these two at best be done by the compiler?

Jan Engelhardt
--

-- 
Andy Isaacson | 16 Dec 04:34

Re: [PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c

On Thu, Dec 15, 2005 at 11:55:05PM +0100, Jan Engelhardt wrote:
> >Benefits:
> > - micro speed optimization due to fewer pointer derefs
> > - generated code is slightly smaller
> 
> Should not these two at best be done by the compiler?

The compiler cannot, in general, do CSE on pointer dereferences.
Consider the following snippet from fs/jffs2/summary.c, both before

 610    sdrnt_ptr->type = c->summary->sum_list_head->d.type;
 612    memcpy(sdrnt_ptr->name, c->summary->sum_list_head->d.name,
 613                            c->summary->sum_list_head->d.nsize);
 615    wpage += JFFS2_SUMMARY_DIRENT_SIZE(c->summary->sum_list_head->d.nsize);

and after Jesper's patch:

 611    sdrnt_ptr->type = temp->d.type;
 613    memcpy(sdrnt_ptr->name, temp->d.name,
 614                            temp->d.nsize);
 616    wpage += JFFS2_SUMMARY_DIRENT_SIZE(temp->d.nsize);

Assuming that memcpy is an out-of-line function, the compiler has to
handle the worst case, that it might modify c->summary->sum_list_head
and thus make the saved value stale.  (In the specific case of memcpy
the compiler can take advantage of special knowledge about the function,
and it's probably inline anyways, so this *particular* example is not
real; but it's a nice clean classroom example.)

But a human *can* make the obvious leap and tell the compiler that the
(Continue reading)

Jan Engelhardt | 16 Dec 23:05
Picon

Re: [PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c

>> >Benefits:
>> > - micro speed optimization due to fewer pointer derefs
>> > - generated code is slightly smaller
>> 
>> Should not these two at best be done by the compiler?
>
>[...]
>But a human *can* make the obvious leap and tell the compiler that the
>value can be computed once and then saved.  And besides, isn't the code
>just *much* nicer to look at, above?

The third point Jesper mentioned was about readability, but I never 
questioned that.

Jan Engelhardt
--

-- 

Gmane