]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/swapfile.c
mm: thp: make deferred split shrinker memcg aware
[linux.git] / mm / swapfile.c
index a53b7c49b40e3c8363ebf55df842d53a2d12ddcc..dab43523afdd351426ef5c92e5306a04a9820b36 100644 (file)
@@ -3275,6 +3275,17 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
        if (error)
                goto bad_swap;
 
+       /*
+        * Flush any pending IO and dirty mappings before we start using this
+        * swap device.
+        */
+       inode->i_flags |= S_SWAPFILE;
+       error = inode_drain_writes(inode);
+       if (error) {
+               inode->i_flags &= ~S_SWAPFILE;
+               goto bad_swap;
+       }
+
        mutex_lock(&swapon_mutex);
        prio = -1;
        if (swap_flags & SWAP_FLAG_PREFER)
@@ -3295,7 +3306,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
        atomic_inc(&proc_poll_event);
        wake_up_interruptible(&proc_poll_wait);
 
-       inode->i_flags |= S_SWAPFILE;
        error = 0;
        goto out;
 bad_swap: