[PATCHv2 15/24] sys_swapon: move setting of swapfilepages near use

From: Cesar Eduardo Barros
Date: Sat Mar 05 2011 - 11:52:40 EST


There is no reason I can see to read inode->i_size long before it is
needed. Move its read to just before it is needed, to reduce the
variable lifetime.

Signed-off-by: Cesar Eduardo Barros <cesarb@xxxxxxxxxx>
Tested-by: Eric B Munson <emunson@xxxxxxxxx>
Acked-by: Eric B Munson <emunson@xxxxxxxxx>
---
mm/swapfile.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 058cf1b..f3f413b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1975,8 +1975,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
if (unlikely(error))
goto bad_swap;

- swapfilepages = i_size_read(inode) >> PAGE_SHIFT;
-
/*
* Read the swap header.
*/
@@ -2045,6 +2043,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
error = -EINVAL;
if (!maxpages)
goto bad_swap;
+ swapfilepages = i_size_read(inode) >> PAGE_SHIFT;
if (swapfilepages && maxpages > swapfilepages) {
printk(KERN_WARNING
"Swap area shorter than signature indicates\n");
--
1.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/