sys_swapon: move setting of swapfilepages near use
authorCesar Eduardo Barros <[email protected]>
Tue, 22 Mar 2011 23:33:28 +0000 (16:33 -0700)
committerLinus Torvalds <[email protected]>
Wed, 23 Mar 2011 00:44:07 +0000 (17:44 -0700)
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 <[email protected]>
Tested-by: Eric B Munson <[email protected]>
Acked-by: Eric B Munson <[email protected]>
Reviewed-by: Jesper Juhl <[email protected]>
Reviewed-by: Pekka Enberg <[email protected]>
Reviewed-by: KAMEZAWA Hiroyuki <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/swapfile.c

index 61a604c12a9601b8e838ce8348782d45e4de2e65..4dade515b0861f605ca228491a5b5402e34abd3b 100644 (file)
@@ -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");