From patchwork Mon Jun 14 19:47:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 12319705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6C9EC2B9F4 for ; Mon, 14 Jun 2021 19:47:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 489F1611C0 for ; Mon, 14 Jun 2021 19:47:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 489F1611C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DCF2C6B006C; Mon, 14 Jun 2021 15:47:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7EDE6B006E; Mon, 14 Jun 2021 15:47:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF8F66B0070; Mon, 14 Jun 2021 15:47:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0042.hostedemail.com [216.40.44.42]) by kanga.kvack.org (Postfix) with ESMTP id 8B9146B006C for ; Mon, 14 Jun 2021 15:47:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2BEBF8249980 for ; Mon, 14 Jun 2021 19:47:42 +0000 (UTC) X-FDA: 78253364364.15.20B1B05 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 1A4F540002C1 for ; Mon, 14 Jun 2021 19:47:36 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id 190-20020a3708c70000b02903aa60e6d8c1so19802466qki.19 for ; Mon, 14 Jun 2021 12:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=PuAKQxmhlgHZw3THznuQh4AVLeqKD59o91eYQohD1bs=; b=TffS5L9ju9FVt13wxarf2ywDW+hF1JDaPY4CFd2wPg8fsiIM7Ks3pugoBTWEgOPivU oqHK14/bfryiEZCF2uVmP30gCsz5i5RmRiVRezg+JiU+J3+pxmsWX1TgjSsx3t6hD+pc fBlQuVdshntJzNsJISQnshQ0DN5M8YEtN/fsJt8mGDPX3owtnqVKQRdog/2S/5RwMMZ7 vSbnsiz+41b+1sv2fhkXA/VkuTaO40PUZ9gEyMp1pNeDI37ot2cHsPUzRz+FVPDHZd1U nxjDkgEzmKx9OFSUNa08qpDA3Q/mybsS5KnOOFxVA60dpH4Of4pTnsgGBdYTxJIjSSob Q6Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=PuAKQxmhlgHZw3THznuQh4AVLeqKD59o91eYQohD1bs=; b=A2WqkJ36fSwaL6I+YelHf0O7t9uecqSqtE8BRBE10U8dzBIQB0TF/sRQAXSR9P734s JZlQCQGh5zrJAXZfK2YVn0ddk4FOr7D7olkGxsin47GBYeAxFs7V1jXpOPX8m9QqPP0x ReGJaz9GYQTFRGXHXCb11KQu7UbWFief6dxHzoYDS3PC+u0Y70cp06odlPAT9ScmLIjO 6Iyhbn8w1IkP8l6+EZNMmGbD47BVG7J7TD2UrL1LQcqWHpFpgq2gIkrQ8B3iIKwfFmCk goOtwSfOGXL0s3QYG/zhspRE0w2N+ZINqYMKkopHlB7kEMd7NpJr6875N5pjKncl2H5Q 3IGQ== X-Gm-Message-State: AOAM532OTc/wbjm1Y1VzoLjksgN6r5ItEU9f8NZuUCXYPdRnjwEnrnyA 3Cx6ri1U5/2YJq8rKZ4yRqApEd0f/PM= X-Google-Smtp-Source: ABdhPJw64deN+GppQOtP5mZ893IqwQmUl1sH7ZXzKkg9qzWbDCxWu5bLum0Kag6NEudF0FYvX/88KriIhTU= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:8922:59a6:1a7b:ac0d]) (user=yuzhao job=sendgmr) by 2002:a0c:ed46:: with SMTP id v6mr773266qvq.47.1623700061136; Mon, 14 Jun 2021 12:47:41 -0700 (PDT) Date: Mon, 14 Jun 2021 13:47:27 -0600 Message-Id: <20210614194727.2684053-1-yuzhao@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH] mm/vmscan.c: fix potential deadlock in reclaim_pages() From: Yu Zhao To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, Yu Zhao Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=TffS5L9j; spf=pass (imf02.hostedemail.com: domain of 3XbLHYAYKCOwminVOcUccUZS.QcaZWbil-aaYjOQY.cfU@flex--yuzhao.bounces.google.com designates 209.85.222.201 as permitted sender) smtp.mailfrom=3XbLHYAYKCOwminVOcUccUZS.QcaZWbil-aaYjOQY.cfU@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: ncaocnefuthzyd4kj648u9ogo1e7dhnj X-Rspamd-Queue-Id: 1A4F540002C1 X-Rspamd-Server: rspam06 X-HE-Tag: 1623700056-519234 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use memalloc_noreclaim_save()/memalloc_noreclaim_restore() in reclaim_pages() to prevent the page reclaim from going into the block I/O layer recursively and deadlock. Signed-off-by: Yu Zhao --- mm/vmscan.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 5199b9696bab..2a02739b20f4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1701,6 +1701,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, unsigned int nr_reclaimed; struct page *page, *next; LIST_HEAD(clean_pages); + unsigned int noreclaim_flag; list_for_each_entry_safe(page, next, page_list, lru) { if (!PageHuge(page) && page_is_file_lru(page) && @@ -1711,8 +1712,17 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, } } + /* + * We should be safe here since we are only dealing with file pages and + * we are not kswapd and therefore cannot write dirty file pages. But + * call memalloc_noreclaim_save() anyway, just in case these conditions + * change in the future. + */ + noreclaim_flag = memalloc_noreclaim_save(); nr_reclaimed = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, &stat, true); + memalloc_noreclaim_restore(noreclaim_flag); + list_splice(&clean_pages, page_list); mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -(long)nr_reclaimed); @@ -2306,6 +2316,7 @@ unsigned long reclaim_pages(struct list_head *page_list) LIST_HEAD(node_page_list); struct reclaim_stat dummy_stat; struct page *page; + unsigned int noreclaim_flag; struct scan_control sc = { .gfp_mask = GFP_KERNEL, .priority = DEF_PRIORITY, @@ -2314,6 +2325,8 @@ unsigned long reclaim_pages(struct list_head *page_list) .may_swap = 1, }; + noreclaim_flag = memalloc_noreclaim_save(); + while (!list_empty(page_list)) { page = lru_to_page(page_list); if (nid == NUMA_NO_NODE) { @@ -2350,6 +2363,8 @@ unsigned long reclaim_pages(struct list_head *page_list) } } + memalloc_noreclaim_restore(noreclaim_flag); + return nr_reclaimed; }