Commit 335886a3689bb3be6bc37f6601006ee20ccd80a0

Authored by Hugh Dickins
Committed by Jiri Slaby
1 parent 9057c212b9

shmem: fix init_page_accessed use to stop !PageLRU bug

commit 66d2f4d28cd030220e7ea2a628993fcabcb956d1 upstream.

Under shmem swapping load, I sometimes hit the VM_BUG_ON_PAGE(!PageLRU)
in isolate_lru_pages() at mm/vmscan.c:1281!

Commit 2457aec63745 ("mm: non-atomically mark page accessed during page
cache allocation where possible") looks like interrupted work-in-progress.

mm/filemap.c's call to init_page_accessed() is fine, but not mm/shmem.c's
- shmem_write_begin() is clearly wrong to use it after shmem_getpage(),
when the page is always visible in radix_tree, and often already on LRU.

Revert change to shmem_write_begin(), and use init_page_accessed() or
mark_page_accessed() appropriately for SGP_WRITE in shmem_getpage_gfp().

SGP_WRITE also covers shmem_symlink(), which did not mark_page_accessed()
before; but since many other filesystems use [__]page_symlink(), which did
and does mark the page accessed, consider this as rectifying an oversight.

Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Prabhakar Lad <prabhakar.csengg@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>

Showing 1 changed file with 10 additions and 5 deletions Side-by-side Diff

... ... @@ -1037,6 +1037,9 @@
1037 1037 goto failed;
1038 1038 }
1039 1039  
  1040 + if (page && sgp == SGP_WRITE)
  1041 + mark_page_accessed(page);
  1042 +
1040 1043 /* fallocated page? */
1041 1044 if (page && !PageUptodate(page)) {
1042 1045 if (sgp != SGP_READ)
... ... @@ -1118,6 +1121,9 @@
1118 1121 shmem_recalc_inode(inode);
1119 1122 spin_unlock(&info->lock);
1120 1123  
  1124 + if (sgp == SGP_WRITE)
  1125 + mark_page_accessed(page);
  1126 +
1121 1127 delete_from_swap_cache(page);
1122 1128 set_page_dirty(page);
1123 1129 swap_free(swap);
... ... @@ -1144,6 +1150,9 @@
1144 1150  
1145 1151 __SetPageSwapBacked(page);
1146 1152 __set_page_locked(page);
  1153 + if (sgp == SGP_WRITE)
  1154 + init_page_accessed(page);
  1155 +
1147 1156 error = mem_cgroup_cache_charge(page, current->mm,
1148 1157 gfp & GFP_RECLAIM_MASK);
1149 1158 if (error)
1150 1159  
... ... @@ -1440,13 +1449,9 @@
1440 1449 loff_t pos, unsigned len, unsigned flags,
1441 1450 struct page **pagep, void **fsdata)
1442 1451 {
1443   - int ret;
1444 1452 struct inode *inode = mapping->host;
1445 1453 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1446   - ret = shmem_getpage(inode, index, pagep, SGP_WRITE, NULL);
1447   - if (ret == 0 && *pagep)
1448   - init_page_accessed(*pagep);
1449   - return ret;
  1454 + return shmem_getpage(inode, index, pagep, SGP_WRITE, NULL);
1450 1455 }
1451 1456  
1452 1457 static int