From patchwork Mon Mar 13 10:37:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 68739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1112719wrd; Mon, 13 Mar 2023 03:59:09 -0700 (PDT) X-Google-Smtp-Source: AK7set+MrvuQ+eysC4ofVzBH+4SRVkbqBx2z0/hDbakdh4+FZE6bn6pAHxpKATrQ4/hwQbShW2sp X-Received: by 2002:a17:902:c20c:b0:19f:2dff:219b with SMTP id 12-20020a170902c20c00b0019f2dff219bmr5651862pll.5.1678705148762; Mon, 13 Mar 2023 03:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678705148; cv=none; d=google.com; s=arc-20160816; b=Exrw8JsNpdAj69uUlUlLqG88Q6HRQW/t5Xn9XCm5WPCtT8x8jVgzNSTmCAOH4GXNch sZkmrAcK1nnbsnO0KhjVJWaIVCx3KuXGEx4GZCcCVBV22ct8IDXUlRbpS4HaxEZ8D5K9 M6lTTfWRfRsKdydgL+6UmnoVM8cSwGPBMbRsCWBWT8dPm28c1f/YqKm/Nv3bVKehK/yP lAn8gWlqnPq546uqyRI9Iw7CV77q6eLoWj+DHX8p22zTvXMtPvYM0P3sOgn9JdgKa2h9 Flk4eBpOsDeVtxRAJIDnQdcQCDNH89+eAuvMSXVAjHzg4QJR0fMEjUpECjfBZFwLZjvM 29ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=JUJdIdlfoH2aAktXgHePaZ5e3iXrsTzhsI+cC+hM6+o=; b=wcUXCyYEVy21+EtsQ+vLHxslykC/1+D4L+L5ukTlyc1vFM+xj1/QrlDG8Q/o5f42Go l8qoQJ/ZPodz/OqrfyBVfgYyYJAIcXVCvRGemnjUZtECO0AUblydXLk9yCoueie9Jqmx FQ7GMIvX02y4oYRGSIbkc7M2CoViEuH72ZzPOcBGGvW6KhaKhZxSudh8M4/2CGXqrPkH gSWfMXR9SKENXaj15mu0KjWT1M5Zq3Mkt23aPvwn/BodBqfgimhlz3A6aJcJFGgpDAck SK8+FnLGNMPCkYTQiHCAVAjEeIUlpV4D339lXTFqD98nFsq6gdcg3nCqko7JKq1V6Gaa qcaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020a170902b40b00b0019a9834bb23si6258081plr.192.2023.03.13.03.58.53; Mon, 13 Mar 2023 03:59:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230055AbjCMKhy (ORCPT + 99 others); Mon, 13 Mar 2023 06:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjCMKhv (ORCPT ); Mon, 13 Mar 2023 06:37:51 -0400 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A8B5FA46 for ; Mon, 13 Mar 2023 03:37:29 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R921e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Vdl6q9P_1678703846; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vdl6q9P_1678703846) by smtp.aliyun-inc.com; Mon, 13 Mar 2023 18:37:26 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: compaction: consider the number of scanning compound pages in isolate fail path Date: Mon, 13 Mar 2023 18:37:16 +0800 Message-Id: <1bc1c955b03603c4e14f56dfbbef9f637f18dbbd.1678703534.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760249930219650806?= X-GMAIL-MSGID: =?utf-8?q?1760249930219650806?= The commit b717d6b93b54 ("mm: compaction: include compound page count for scanning in pageblock isolation") had added compound page statistics for scanning in pageblock isolation, to make sure the number of scanned pages are always larger than the number of isolated pages when isolating mirgratable or free pageblock. However, when failed to isolate the pages when scanning the mirgratable or free pageblock, the isolation failure path did not consider the scanning statistics of the compound pages, which can show the incorrect number of scanned pages in tracepoints or the vmstats to make people confusing about the page scanning pressure in memory compaction. Thus we should take into account the number of scanning pages when failed to isolate the compound pages to make the statistics accurate. Signed-off-by: Baolin Wang --- mm/compaction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 5a9501e0ae01..c9d9ad958e2a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -587,6 +587,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, blockpfn += (1UL << order) - 1; cursor += (1UL << order) - 1; } + nr_scanned += (1UL << order) - 1; goto isolate_fail; } @@ -873,9 +874,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, cond_resched(); } - nr_scanned++; - page = pfn_to_page(low_pfn); + nr_scanned += compound_nr(page); /* * Check if the pageblock has already been marked skipped. @@ -1077,6 +1077,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, */ if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; + nr_scanned += compound_nr(page) - 1; SetPageLRU(page); goto isolate_fail_put; } @@ -1097,7 +1098,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, isolate_success_no_list: cc->nr_migratepages += compound_nr(page); nr_isolated += compound_nr(page); - nr_scanned += compound_nr(page) - 1; /* * Avoid isolating too much unless this block is being From patchwork Mon Mar 13 10:37:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 68734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1109188wrd; Mon, 13 Mar 2023 03:48:33 -0700 (PDT) X-Google-Smtp-Source: AK7set+WBPq+lTU6XP4BDaUov7HUtTT0QFzbU5EL66rgnVnXAEeX1Pl3pr8fc7e5iGBvm7sJjKNs X-Received: by 2002:a05:6a21:6da7:b0:cc:c69b:f7f1 with SMTP id wl39-20020a056a216da700b000ccc69bf7f1mr45334417pzb.15.1678704513630; Mon, 13 Mar 2023 03:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678704513; cv=none; d=google.com; s=arc-20160816; b=oRvBEVW2pj32t4sPTYJL7MPjvZKRlu12g/Q7g03/qYtW9hguqPdZBBwng7oOra17fv r2XIZDWs9NlvGevBs99IlcqJEW2eeIRtakg0HJ/DsDkfVuMINhjy2DE1jy98nGAvKYDW ghQtghMV1qN7D8ial3K/u54U/54Kjc7yRV9Fg9jHglT7E2eieKubTgtNzuW4mJ0rFgTQ yKTO583FYC68oy836eTd+rPUFYgyg69SF+Z62Vf2gfaRSxzP4efkjoYQdi4kLs22Sfey +YAwfktB0twKu3u1ZepRdn9hQLATnYKt0lb4I08w3TMH/tehx+VD0n4+XbD/FtLceC8K 2LNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=W+6m/J5co4iV+tD4vjXf7uQYThOT2r/sspycShPNR4A=; b=kI6WoQQ6S2DJqU1FHT3GQJq2d+4aPiTB4dHqwhR5l7aRcqrtwDWC/y/DkqsY2rVNeE rkHyrqQURPmqQUtko9sStEMTvrKoCwF0nsATzVtQBtIB/qy/yB85QJJbYcl8j2Y1w3wQ LOi2TRo+FPqfX3pUtXr4YS7ZKnU99O+U+lZLgOMIdCd5a8TGJkwe4I2dsb21WZOajtnz HqX03BCxETL9H8LACZf3rl4aWqUMt0d6YIDSFhL9bFBukGhrbWCi5/olLUN5VWN3NnjD nxY4GiUifviCd671/Ll39uYQvIkBgCQNHGpxDhiNrGYpjIffsRfMTKXdE5aW6c/kGPj5 jYJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a19-20020aa794b3000000b00593a3cabd75si6196200pfl.313.2023.03.13.03.48.19; Mon, 13 Mar 2023 03:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbjCMKiF (ORCPT + 99 others); Mon, 13 Mar 2023 06:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjCMKh4 (ORCPT ); Mon, 13 Mar 2023 06:37:56 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 021B65F532 for ; Mon, 13 Mar 2023 03:37:30 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VdlJ.M3_1678703847; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VdlJ.M3_1678703847) by smtp.aliyun-inc.com; Mon, 13 Mar 2023 18:37:27 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: compaction: fix the possible deadlock when isolating hugetlb pages Date: Mon, 13 Mar 2023 18:37:17 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: <1bc1c955b03603c4e14f56dfbbef9f637f18dbbd.1678703534.git.baolin.wang@linux.alibaba.com> References: <1bc1c955b03603c4e14f56dfbbef9f637f18dbbd.1678703534.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760249264219268830?= X-GMAIL-MSGID: =?utf-8?q?1760249264219268830?= When trying to isolate a migratable pageblock, it can contain several normal pages or several hugetlb pages (e.g. CONT-PTE 64K hugetlb on arm64) in a pageblock. That means we may hold the lru lock of a normal page to continue to isolate the next hugetlb page by isolate_or_dissolve_huge_page() in the same migratable pageblock. However in the isolate_or_dissolve_huge_page(), it may allocate a new hugetlb page and dissolve the old one by alloc_and_dissolve_hugetlb_folio() if the hugetlb's refcount is zero. That means we can still enter the direct compaction path to allocate a new hugetlb page under the current lru lock, which may cause possible deadlock. To avoid this possible deadlock, we should release the lru lock when trying to isolate a hugetbl page. Moreover it does not make sense to take the lru lock to isolate a hugetlb, which is not in the lru list. Fixes: 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages") Signed-off-by: Baolin Wang Reviewed-by: Mike Kravetz Reviewed-by: Vlastimil Babka --- mm/compaction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index c9d9ad958e2a..ac8ff152421a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -893,6 +893,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } if (PageHuge(page) && cc->alloc_contig) { + if (locked) { + unlock_page_lruvec_irqrestore(locked, flags); + locked = NULL; + } + ret = isolate_or_dissolve_huge_page(page, &cc->migratepages); /*