mm, thp: relax the VM_DENYWRITE constraint on file-backed THPs
[linux-block.git] / fs / open.c
index e53af13b5835f3459b2ce7eafdc3697e874e40c3..f76e960d10eaf394700ca57b7d0da3d9cb72bd99 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -852,8 +852,17 @@ static int do_dentry_open(struct file *f,
         * XXX: Huge page cache doesn't support writing yet. Drop all page
         * cache for this file before processing writes.
         */
-       if ((f->f_mode & FMODE_WRITE) && filemap_nr_thps(inode->i_mapping))
-               truncate_pagecache(inode, 0);
+       if (f->f_mode & FMODE_WRITE) {
+               /*
+                * Paired with smp_mb() in collapse_file() to ensure nr_thps
+                * is up to date and the update to i_writecount by
+                * get_write_access() is visible. Ensures subsequent insertion
+                * of THPs into the page cache will fail.
+                */
+               smp_mb();
+               if (filemap_nr_thps(inode->i_mapping))
+                       truncate_pagecache(inode, 0);
+       }
 
        return 0;