aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>2018-03-22 19:17:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-03-22 20:07:01 -0400
commitb3cd54b257ad95d344d121dc563d943ca39b0921 (patch)
tree49b4df8b32b64f2bdbb00fc2737ff3819051c758
parentfa41b900c30b45fab03783724932dc30cd46a6be (diff)
mm/shmem: do not wait for lock_page() in shmem_unused_huge_shrink()
shmem_unused_huge_shrink() gets called from reclaim path. Waiting for page lock may lead to deadlock there. There was a bug report that may be attributed to this: http://lkml.kernel.org/r/alpine.LRH.2.11.1801242349220.30642@mail.ewheeler.net Replace lock_page() with trylock_page() and skip the page if we failed to lock it. We will get to the page on the next scan. We can test for the PageTransHuge() outside the page lock as we only need protection against splitting the page under us. Holding pin oni the page is enough for this. Link: http://lkml.kernel.org/r/20180316210830.43738-1-kirill.shutemov@linux.intel.com Fixes: 779750d20b93 ("shmem: split huge pages beyond i_size under memory pressure") Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Reported-by: Eric Wheeler <linux-mm@lists.ewheeler.net> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Hugh Dickins <hughd@google.com> Cc: <stable@vger.kernel.org> [4.8+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/shmem.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index 1907688b75ee..b85919243399 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -493,36 +493,45 @@ next:
493 info = list_entry(pos, struct shmem_inode_info, shrinklist); 493 info = list_entry(pos, struct shmem_inode_info, shrinklist);
494 inode = &info->vfs_inode; 494 inode = &info->vfs_inode;
495 495
496 if (nr_to_split && split >= nr_to_split) { 496 if (nr_to_split && split >= nr_to_split)
497 iput(inode); 497 goto leave;
498 continue;
499 }
500 498
501 page = find_lock_page(inode->i_mapping, 499 page = find_get_page(inode->i_mapping,
502 (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT); 500 (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT);
503 if (!page) 501 if (!page)
504 goto drop; 502 goto drop;
505 503
504 /* No huge page at the end of the file: nothing to split */
506 if (!PageTransHuge(page)) { 505 if (!PageTransHuge(page)) {
507 unlock_page(page);
508 put_page(page); 506 put_page(page);
509 goto drop; 507 goto drop;
510 } 508 }
511 509
510 /*
511 * Leave the inode on the list if we failed to lock
512 * the page at this time.
513 *
514 * Waiting for the lock may lead to deadlock in the
515 * reclaim path.
516 */
517 if (!trylock_page(page)) {
518 put_page(page);
519 goto leave;
520 }
521
512 ret = split_huge_page(page); 522 ret = split_huge_page(page);
513 unlock_page(page); 523 unlock_page(page);
514 put_page(page); 524 put_page(page);
515 525
516 if (ret) { 526 /* If split failed leave the inode on the list */
517 /* split failed: leave it on the list */ 527 if (ret)
518 iput(inode); 528 goto leave;
519 continue;
520 }
521 529
522 split++; 530 split++;
523drop: 531drop:
524 list_del_init(&info->shrinklist); 532 list_del_init(&info->shrinklist);
525 removed++; 533 removed++;
534leave:
526 iput(inode); 535 iput(inode);
527 } 536 }
528 537