small valid_swaphandles() optimization
Subsystems (2)
PATCH 1/1 small valid_swaphandles() optimization
Hi Andrew, Hugh,
The following patch, relative to valid_swaphandles(), moves the EOF check outside validity check loop, saving a few instructions.
mm/swapfile.c renamed from mm/swapfile.c.orig +4 -3
@@ -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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines · Marcelo Tosatti
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
Quoted 8 lines
mm/swapfile.c renamed from mm/swapfile.c.orig +2
-0@@ -1713,11 +1713,12 @@ toff++, i--; *offset = toff; +/* Don't read-ahead past the end of the swap area */ +if (toff+i >= swapdev->max)
mm/swapfile.c line 1724
Quoted 10 lines
mm/swapfile.c renamed from mm/swapfile.c.orig +2
-3+ 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Hugh Dickins
Quoted 3 lines · Marcelo Tosatti
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 :)
Quoted 2 lines
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.
Quoted 1 line
Easily fixed, but suggests your optimization not worth the obfuscation?
ok! probably not worth the trouble. Andrew, please drop it.
Quoted 8 lines
Hugh
Quoted 6 lines
mm/swapfile.c renamed from mm/swapfile.c.orig +0
-0@@ -1713,11 +1713,12 @@ toff++, i--; *offset = toff;
Quoted 12 lines
mm/swapfile.c line 1724
Quoted 12 lines
mm/swapfile.c renamed from mm/swapfile.c.orig +4
-3+/* 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>