* [PATCH] small valid_swaphandles() optimization
@ 2005-05-25 13:42 Marcelo Tosatti
2005-05-26 2:15 ` Hugh Dickins
0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Tosatti @ 2005-05-25 13:42 UTC (permalink / raw)
To: Andrew Morton, Hugh Dickins; +Cc: linux-mm
Hi Andrew, Hugh,
The following patch, relative to valid_swaphandles(), moves the EOF
check outside validity check loop, saving a few instructions.
--- a/mm/swapfile.c.orig 2005-05-25 15:45:18.000000000 -0300
+++ b/mm/swapfile.c 2005-05-25 16:20:45.000000000 -0300
@@ -1713,11 +1713,12 @@
toff++, i--;
*offset = toff;
+ /* Don't read-ahead past the end of the swap area */
+ if (toff+i >= swapdev->max)
+ i = swapdev->max - toff - 1;
+
swap_device_lock(swapdev);
do {
- /* Don't read-ahead past the end of the swap area */
- if (toff >= swapdev->max)
- break;
/* Don't read in free or bad pages */
if (!swapdev->swap_map[toff])
break;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] small valid_swaphandles() optimization
2005-05-25 13:42 [PATCH] small valid_swaphandles() optimization Marcelo Tosatti
@ 2005-05-26 2:15 ` Hugh Dickins
2005-05-26 7:05 ` Marcelo Tosatti
0 siblings, 1 reply; 3+ messages in thread
From: Hugh Dickins @ 2005-05-26 2:15 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: Andrew Morton, linux-mm
On Wed, 25 May 2005, Marcelo Tosatti wrote:
>
> The following patch, relative to valid_swaphandles(), moves the EOF
> check outside validity check loop, saving a few instructions.
But increasing the function's footprint - though not very excitingly
either way. Any benchmarks in support of it ?-)
Hmmm. Doesn't it go wrong on the toff == swapdev->max - 1 case,
when i becomes 0 then is decremented negative at the end of the loop?
Easily fixed, but suggests your optimization not worth the obfuscation?
Hugh
> --- a/mm/swapfile.c.orig 2005-05-25 15:45:18.000000000 -0300
> +++ b/mm/swapfile.c 2005-05-25 16:20:45.000000000 -0300
> @@ -1713,11 +1713,12 @@
> toff++, i--;
> *offset = toff;
>
> + /* Don't read-ahead past the end of the swap area */
> + if (toff+i >= swapdev->max)
> + i = swapdev->max - toff - 1;
> +
> swap_device_lock(swapdev);
> do {
> - /* Don't read-ahead past the end of the swap area */
> - if (toff >= swapdev->max)
> - break;
> /* Don't read in free or bad pages */
> if (!swapdev->swap_map[toff])
> break;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] small valid_swaphandles() optimization
2005-05-26 2:15 ` Hugh Dickins
@ 2005-05-26 7:05 ` Marcelo Tosatti
0 siblings, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2005-05-26 7:05 UTC (permalink / raw)
To: Hugh Dickins; +Cc: Andrew Morton, linux-mm
On Thu, May 26, 2005 at 03:15:16AM +0100, Hugh Dickins wrote:
> On Wed, 25 May 2005, Marcelo Tosatti wrote:
> >
> > The following patch, relative to valid_swaphandles(), moves the EOF
> > check outside validity check loop, saving a few instructions.
>
> But increasing the function's footprint - though not very excitingly
> either way. Any benchmarks in support of it ?-)
It moves a comparison outside the loop. You do an add and a
comparison once, instead of 8 comparisons.
It seemed more readable to me, also :)
> Hmmm. Doesn't it go wrong on the toff == swapdev->max - 1 case,
> when i becomes 0 then is decremented negative at the end of the loop?
Yikes, indeed.
> Easily fixed, but suggests your optimization not worth the obfuscation?
ok! probably not worth the trouble. Andrew, please drop it.
> Hugh
>
> > --- a/mm/swapfile.c.orig 2005-05-25 15:45:18.000000000 -0300
> > +++ b/mm/swapfile.c 2005-05-25 16:20:45.000000000 -0300
> > @@ -1713,11 +1713,12 @@
> > toff++, i--;
> > *offset = toff;
> >
> > + /* Don't read-ahead past the end of the swap area */
> > + if (toff+i >= swapdev->max)
> > + i = swapdev->max - toff - 1;
> > +
> > swap_device_lock(swapdev);
> > do {
> > - /* Don't read-ahead past the end of the swap area */
> > - if (toff >= swapdev->max)
> > - break;
> > /* Don't read in free or bad pages */
> > if (!swapdev->swap_map[toff])
> > break;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-05-26 7:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-25 13:42 [PATCH] small valid_swaphandles() optimization Marcelo Tosatti
2005-05-26 2:15 ` Hugh Dickins
2005-05-26 7:05 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox