* [PATCHv2 8/10] xfs: avoid repeated pointer dereferences
@ 2010-04-09 22:30 Alex Elder
2010-04-12 6:56 ` Dave Chinner
0 siblings, 1 reply; 3+ messages in thread
From: Alex Elder @ 2010-04-09 22:30 UTC (permalink / raw)
To: xfs
In xlog_find_cycle_start() use a local variable for some repeated
operations rather than constantly updating the memory location
whose address is passed in.
Signed-off-by: Alex Elder <aelder@sgi.com>
---
fs/xfs/xfs_log_recover.c | 83 ++++++++++++++++++++++++-----------------------
fs/xfs/xfs_log_recover.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
Index: b/fs/xfs/xfs_log_recover.c
===================================================================
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -354,26 +354,28 @@ xlog_find_cycle_start(
{
xfs_caddr_t offset;
xfs_daddr_t mid_blk;
+ xfs_daddr_t end_blk;
uint mid_cycle;
int error;
- mid_blk = BLK_AVG(first_blk, *last_blk);
- while (mid_blk != first_blk && mid_blk != *last_blk) {
+ ASSERT(last_blk != NULL);
+ end_blk = *last_blk;
+ mid_blk = BLK_AVG(first_blk, end_blk);
+ while (mid_blk != first_blk && mid_blk != end_blk) {
error = xlog_bread(log, mid_blk, 1, bp, &offset);
if (error)
return error;
mid_cycle = xlog_get_cycle(offset);
- if (mid_cycle == cycle) {
- *last_blk = mid_blk;
- /* last_half_cycle == mid_cycle */
- } else {
- first_blk = mid_blk;
- /* first_half_cycle == mid_cycle */
- }
- mid_blk = BLK_AVG(first_blk, *last_blk);
+ if (mid_cycle == cycle)
+ end_blk = mid_blk; /* last_half_cycle == mid_cycle */
+ else
+ first_blk = mid_blk; /* first_half_cycle == mid_cycle */
+ mid_blk = BLK_AVG(first_blk, end_blk);
}
- ASSERT((mid_blk == first_blk && mid_blk+1 == *last_blk) ||
- (mid_blk == *last_blk && mid_blk-1 == first_blk));
+ ASSERT((mid_blk == first_blk && mid_blk+1 == end_blk) ||
+ (mid_blk == end_blk && mid_blk-1 == first_blk));
+
+ *last_blk = end_blk;
return 0;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv2 8/10] xfs: avoid repeated pointer dereferences
2010-04-09 22:30 [PATCHv2 8/10] xfs: avoid repeated pointer dereferences Alex Elder
@ 2010-04-12 6:56 ` Dave Chinner
2010-04-14 21:02 ` Alex Elder
0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2010-04-12 6:56 UTC (permalink / raw)
To: Alex Elder; +Cc: xfs
On Fri, Apr 09, 2010 at 05:30:42PM -0500, Alex Elder wrote:
> In xlog_find_cycle_start() use a local variable for some repeated
> operations rather than constantly updating the memory location
> whose address is passed in.
Won't the compiler optimise that out for us? i.e. does the dissassembly
of the function look any better before and after this change?
> Signed-off-by: Alex Elder <aelder@sgi.com>
>
> ---
> fs/xfs/xfs_log_recover.c | 83 ++++++++++++++++++++++++-----------------------
> fs/xfs/xfs_log_recover.c | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> Index: b/fs/xfs/xfs_log_recover.c
> ===================================================================
> --- a/fs/xfs/xfs_log_recover.c
> +++ b/fs/xfs/xfs_log_recover.c
> @@ -354,26 +354,28 @@ xlog_find_cycle_start(
> {
> xfs_caddr_t offset;
> xfs_daddr_t mid_blk;
> + xfs_daddr_t end_blk;
> uint mid_cycle;
> int error;
>
> - mid_blk = BLK_AVG(first_blk, *last_blk);
> - while (mid_blk != first_blk && mid_blk != *last_blk) {
> + ASSERT(last_blk != NULL);
> + end_blk = *last_blk;
FWIW, there is no need for that ASSERT there - the machine will
panic on the very next line, anyway....
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv2 8/10] xfs: avoid repeated pointer dereferences
2010-04-12 6:56 ` Dave Chinner
@ 2010-04-14 21:02 ` Alex Elder
0 siblings, 0 replies; 3+ messages in thread
From: Alex Elder @ 2010-04-14 21:02 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs
On Mon, 2010-04-12 at 16:56 +1000, Dave Chinner wrote:
> On Fri, Apr 09, 2010 at 05:30:42PM -0500, Alex Elder wrote:
> > In xlog_find_cycle_start() use a local variable for some repeated
> > operations rather than constantly updating the memory location
> > whose address is passed in.
>
> Won't the compiler optimise that out for us? i.e. does the dissassembly
> of the function look any better before and after this change?
I doubt it *can* optimize that. Doing so would change
the way the function interacts semantically with the
pointed-to memory. Still, I performed a quick check
to be sure (on an x86_64) and the compiled code really
does de-reference the pointer for both reads from and
writes to memory.
> > Signed-off-by: Alex Elder <aelder@sgi.com>
> >
> > ---
> > fs/xfs/xfs_log_recover.c | 83 ++++++++++++++++++++++++-----------------------
> > fs/xfs/xfs_log_recover.c | 26 ++++++++++++++------------
> > 1 file changed, 14 insertions(+), 12 deletions(-)
> >
> > Index: b/fs/xfs/xfs_log_recover.c
> > ===================================================================
> > --- a/fs/xfs/xfs_log_recover.c
> > +++ b/fs/xfs/xfs_log_recover.c
> > @@ -354,26 +354,28 @@ xlog_find_cycle_start(
> > {
> > xfs_caddr_t offset;
> > xfs_daddr_t mid_blk;
> > + xfs_daddr_t end_blk;
> > uint mid_cycle;
> > int error;
> >
> > - mid_blk = BLK_AVG(first_blk, *last_blk);
> > - while (mid_blk != first_blk && mid_blk != *last_blk) {
> > + ASSERT(last_blk != NULL);
> > + end_blk = *last_blk;
>
> FWIW, there is no need for that ASSERT there - the machine will
> panic on the very next line, anyway....
Agreed. I make a habit of stating assumptions about
passed-in arguments via assertions. Not a big deal,
I'll take it out.
Still soliciting a reviewed-by on this one.
-Alex
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-14 21:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-09 22:30 [PATCHv2 8/10] xfs: avoid repeated pointer dereferences Alex Elder
2010-04-12 6:56 ` Dave Chinner
2010-04-14 21:02 ` Alex Elder
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.