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: 13172177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10F4FC6FD19 for ; Mon, 13 Mar 2023 10:37:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68C6B6B0071; Mon, 13 Mar 2023 06:37:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 615466B0072; Mon, 13 Mar 2023 06:37:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DF706B0074; Mon, 13 Mar 2023 06:37:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3B6756B0071 for ; Mon, 13 Mar 2023 06:37:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0E2068090B for ; Mon, 13 Mar 2023 10:37:33 +0000 (UTC) X-FDA: 80563523586.16.964EA30 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by imf20.hostedemail.com (Postfix) with ESMTP id 843CA1C0018 for ; Mon, 13 Mar 2023 10:37:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf20.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678703851; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=JUJdIdlfoH2aAktXgHePaZ5e3iXrsTzhsI+cC+hM6+o=; b=DIyhBg6TssOTTjmDxgBragX1kcctrrdSghXQAOn5nokAd9WGmy4xD626nlURP9HAQe6Hnc Pue5S47oMLD/5Y6Nq2adAhebvjEqz9MaAfUzbQsLWYtNL8D9LBqNLbSvawEtItW7XN0aER wx8tXIqi5dmGb6qhHeAIcAFYjx8b/Ho= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf20.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678703851; a=rsa-sha256; cv=none; b=wXrO0ex+UcR86T0F20sMjLJV7yupLm3/cJS7wAqdSb15t0ZbyRtJnz2ATNKpxC0vf/lT5Q PV21xTIX/o5NAEcocoIpBwBE8wtb0srcxGQM5lafU+1NcvOK214Qio8OrXxit2prnBC1iJ p/EQ41tcL5EEmcRdvvm+29JGmVYa/8A= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 843CA1C0018 X-Stat-Signature: wuahibye5pesri31eywp64oyoo1yr5by X-Rspam-User: X-HE-Tag: 1678703850-42098 X-HE-Meta: U2FsdGVkX1+Ix7kzX+lp1ZKd/kVSZAM7F9FCqy7pwdGLLtDggW38Lv2hQ3MEOl6nBVLKPGNpj9Z0bJkDFQMVTIgx/M9PDvjSS2oCTeGyDsmuG+DM0goG+tiL9GIajDDlkeK7MxyFvk1qowNmOYmMAsLYpTYl1l+vgxDhjPAKIuTMm89hQK0qegi1HkDxthiJF8uVGNoZ6ezrAq36lo1ZVgWSN+pvmbKmfrNo4kgzhqVe/p1T2UqrW759/f3maIv+ZnJRPbCjl1tJoYUY/JXPfEyuAgk4hvb/H7C9qgoD2PUEvYjiccnSJw/vWKDsOTGaq5oSbpVg7ycRAxe4rf0Nv/V619VMcKZ1oyAtZ9sknpaMzpSbpwOQ6JFj51ZFe3J28m8pVUhISOeR+wsSMBFIy56x1tC3w0G1+Nu28vNpsAAOzfHHd58Zw1Szz30D5LJYytLO4eWXArPuhjUMs4s1VDlsPUgdDuEDmUlQbz3EHViqyMdJHovSMZc07xa0f3lH4Tak1+onOMfoindAjT3cBIyqAeAOtqeMQKa520tCEAa3N4m2T56iTGYuKuOrjJ3rsC6H71Ut5aBFrnsjJFO/sgm2N1MynHRUBgKhP5adME1ZRYUfWOCPJMMRZKjjo+A7Luom8X1azoOqdAmlre6gHQ6e5XTBFc1OHVvEp5m5gFz4si5VRaVQOhhs7+Q1qVZAKWaCk9pj9FlPZ1mvJtFTCkB5YD5xQDZZY0M7CQ459IVQOtLyYSyFGU2ihKVxDEnja7B3fj/9AvODwPO9T94dJZWwrQdTCRBVIvLnrYNfmjj+mgepMfibOI1C3NeOMC2eJQafX+BVEQkxszBWdO0em34pmZOUwrWV+XHl65ohnmsazyajvIqDRZ25MKDI9fXjdC6SrX/x7jIr3ZflyHZaF/y6/eVDmIR6OteexZm2BH9zNwi6GJxPxKIcjB6r9cBqiwBtubO0evSQqFErFpn njYGT5aZ iEGKz2Rczqdb0hYaJpK4POW0XqsLiTL2ySzQrhebJO7eCRv3vABFBL7fCUnvYj7snrWFqW5A+M7eVkbVHN4wv/VvJ607FqZ1LMtXSsJMbJwnZtgQ= 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: 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: 13172178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BA70C74A4B for ; Mon, 13 Mar 2023 10:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9246A6B0072; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AE1A6B0074; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 728456B0075; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 62F976B0072 for ; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3E6091C624F for ; Mon, 13 Mar 2023 10:37:34 +0000 (UTC) X-FDA: 80563523628.12.D83C3E4 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf14.hostedemail.com (Postfix) with ESMTP id 2FD7B100018 for ; Mon, 13 Mar 2023 10:37:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678703852; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+6m/J5co4iV+tD4vjXf7uQYThOT2r/sspycShPNR4A=; b=FcNdFt8aNvJO/0+KI4fOLX56d6oZ0NRyCOTLD5kUEzfE/irTrM+NuzCMTZpNJbrno1P57a NblcrVnXFsqtuPiq+6ZpNZyIsjPE+26pKZ+CHcFi1GZRA0QtChGRjJMq0e/xf16MN3OHPU erBBAhkhNFcAB/IsauSRKB4p36vrjCI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678703852; a=rsa-sha256; cv=none; b=jMnNF9pic314E4XVur3UBnsGfb2kQQ0Ya0OHyBDIPsZloLNgcsK1AHXMbiqwWJy9sfwTyu Cp0TsZs4STeG2nGCx6w9CoDuAuEFXK+17dNNdW7iC51IQlzBHRLSq6x9R7d+ZIbxB17m+P f5rbCdjC1Wbwc5PUykXgTWoInGFMd4g= 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-Stat-Signature: bjuqsj1e1311qia7j8cxb7f1qzpfsnim X-Rspam-User: X-Rspamd-Queue-Id: 2FD7B100018 X-Rspamd-Server: rspam06 X-HE-Tag: 1678703851-543051 X-HE-Meta: U2FsdGVkX1+GNdlIxo4zv9BT0bxdWt68hDdz3W8f93nCbZ/XG2rHw119fVzVmehlDswmZ3FgciDu87pC5adYOYLlDTpB8ZPVAxvr6+XGUWhLhf4HYcZ2DHer8B2go9zxdrBwtXm/DclB9Fmmi8ixDn+oVjjEhcHcSB8U5jL6v0WqqzIJOCR4ouB2rMiKwqs6s7TMuAQTJPWzfB0mSy7vuHrojkXuioETNHei5wPCy1+fbhaefKIoW8Ozm6PuNG54uIemeVwUtAjDKrtsJiUVDeHmYehQXhVmOoza27d7VUGeYFChLUFv3UXVh4QhBhq+t1YON9Aw26FmXLOBp8/Z7+M5lM42H8E4WIpIcHA8EJ2nMqcKji2tQeUeW3uLvicQemlvO+94kFAZxZNGYLeHdl1hiocCFHLrakDrA0NKYN7uPZB0WZ9wT9aruLt3Bgqj4WaJ2T7VVDJVOJMC4CPdkDJ8ZWwUJIefV0xu+SLJfCRTI25zf2TMHdqNJDR+3hTZ5F+93aqju3KM1PyFIAVkPUTFC6uukSKxDQHwHR/Xdn6FwvvXvzrieiFRNfsU86zRHnXv7Z2zYVkKltp9XsGO4+QkF26oMFTrvWuPpXyBmZP+I4/D3dhVA0sxH6+yTG/VDzcZZ2GI+4pZJkhZa/CaSlLYsNbD5/GSGgpCirU4JLX3SXStECUA/7q7M8AZ+uyvq4wp0XXofQwhdlxVFb04qo9vJgVsjPHtVd4/vBtznnoFswAw6N/RsUSNW6UV8cHNx1SqRqBvb3+T0FEvTZjse0LewW2LhP37bSU8GbIKCTdu7nh/AKId3szI3iaDVVeBdXGrS+dp4zVI4zgydObM+n43TmS4Kq17+HInP26+mUIWmEtv2K3cCYrUzSFj2a6XvffdB+pPVju8k5HXX3HMyarA8c1754mxo6D70c9oqr5bfrh/bQ2eRehtJQbNDmabQif51h2vc2/ReNkA0Rh GwEycdtc P2XrGXA46af9cLQq2syghPv0agJXLpfXSk89SHbp+DYNd4JlLNV9hn7C61U+RCHB6sJ2zgFbESsxSr4Kt6WieBdAhiIMnJKf211Eg20XP2L85wzY= 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: 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); /*