From patchwork Thu Mar 16 11:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13177386 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 5868CC6FD19 for ; Thu, 16 Mar 2023 11:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F342900007; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A0DA900002; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56887900007; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4A15F900002 for ; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 214D21C6D41 for ; Thu, 16 Mar 2023 11:07:03 +0000 (UTC) X-FDA: 80574484326.11.9C47553 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf07.hostedemail.com (Postfix) with ESMTP id 1D6F740025 for ; Thu, 16 Mar 2023 11:06:59 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 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=1678964821; 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=4iEwgEufw1E44AmNlaoOTCnL7OKSRMw6hxynyb6vNaE=; b=VkSMP+9CRZuIpqAFSeknXWwLEDkp5KwjfhhL9cLdx7hycasToWnomRtrP6TfpG35XV5/yz Xjh/gOmhX0Vi86uVymc/p2JUF4RAW5dK11AIOm73sHTGTvVvODoOsfYjYkBBPaqLTXFXKf 5eAHN1kkrngbsvtMI1XCPRTxaY7mfIY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678964821; a=rsa-sha256; cv=none; b=npPjnZyZ439OCEgdYxg9ObzxvwdIIbAPvNF1HmWrgfhGBD+CzwA9opbnebnUxBtbkJvFH7 Nn+M15EfnA5asyavLZ+eMd+YItdUlCmIvrCiie4MGfbW/fHBg4a6obAAYx9GfQdZ27aHTK a4JTYJX/rgle2IZ+A5inCkRL5MWVm+g= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Ve-NM83_1678964813; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Ve-NM83_1678964813) by smtp.aliyun-inc.com; Thu, 16 Mar 2023 19:06:54 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, mike.kravetz@oracle.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm: compaction: consider the number of scanning compound pages in isolate fail path Date: Thu, 16 Mar 2023 19:06:46 +0800 Message-Id: <73d6250a90707649cc010731aedc27f946d722ed.1678962352.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1D6F740025 X-Stat-Signature: aqqnn3wkonjxgdnq1gdn6ypwhw53355n X-HE-Tag: 1678964819-73558 X-HE-Meta: U2FsdGVkX1/xVr0LI0CRlFO5JfVegRbiLjeafJt9gKc6sqCG0TUZnGHd464ALUvVJqZqvZ/20M19r8C+1+JJi5lch2XACl7urtqooA7tN1GYd+H3GA0P0VbfxTs3iasSOLR7o7wHmTA7uptwb/QRTQ6SYrlH/rDGg4Pya0YaaG5NPq5u0gNP0HySw9YLW8mLNLslW7SiAJBubYgrhN1pUf0PpdBz0aZ0PE0v2GXeRL6tjgbT3mt7367hDXb4jZVY7CW4XXV56c7Wcb7Ttd9hpY8S4SXIAwGpV/4SK/Adhz3AsUsu8SRNZFU+xoKUUutvuy8Z10+8Z2HVPa2DSvc0KP34BnKamhL4WTypdgrohgyc7oJfoTEDxJW/qTzzs8yGH2r9HY5BAypmeM9hopDBjHEN+xcFcUyKOetH3W+mUANyXUsmcoUPi6mr+vDh7tUW7LMFJcp10J0FcQrZf3ne+cQYRazuXzGAT9tCd/qiLnRGneqCbeQtxKCorjP/HN0XJtrYuYNu8Jk0pGqNsGcyCYLgUWpJHv8x+RhGDnCkIVKE6AlKe+plrz/07MA/ra/XmVFbO5H94wT1LP1k/LpGB+VOKaP9fbumfuENd2DT7cOI/0vmutaILcabv2pAYVjLAYFuNW8H4Gl0aavrRPaiV9cnR39MkpkR7z4TJDJwgE09DK7CQg5LrsUHwnTpI92fkO/lvBIk6BGX10Bq6on3DoALnI6ODRkZRR8sM5gPRwAS3e6M+JtV8nVHw659DqtzsUbzDWyaSmX+NYmCG34Tujj4/7ZE2DeQ656eJj7cdxC1gq0uWqqxtokQqQkao8CzXEru1fLZX/4mRJ37OJD53xb6WauFmgVNoMDpHjANu3M1dBkwvn7areDb7XDXoazRNzeSaJ9NdVOyQzSZLsoSEr1yDoVzM6Atr+5BJbQBqEuhKSj697wHxQvPklB60BaXNyDl5+eVZfzIZK1knVh MOM4IkMD hfPRM6bVfET1vKOTjqSOIyfWzVQHV7xbsR//tHTVHNrYIbko8LemZs59PLdqJH80Y0MQRni3T05Kd62YqhhxfEG7AhfGkjllfX7lHzVCbW+lFUTA= 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 Reviewed-by: Vlastimil Babka Acked-by: Mel Gorman --- Changes from v1: - Move the compound pages statistics after sanity order checking. --- mm/compaction.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 5a9501e0ae01..7e645cdfc2e9 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -586,6 +586,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, if (likely(order < MAX_ORDER)) { blockpfn += (1UL << order) - 1; cursor += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; } goto isolate_fail; } @@ -904,6 +905,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (ret == -EBUSY) ret = 0; low_pfn += compound_nr(page) - 1; + nr_scanned += compound_nr(page) - 1; goto isolate_fail; } @@ -938,8 +940,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * a valid page order. Consider only values in the * valid order range to prevent low_pfn overflow. */ - if (freepage_order > 0 && freepage_order < MAX_ORDER) + if (freepage_order > 0 && freepage_order < MAX_ORDER) { low_pfn += (1UL << freepage_order) - 1; + nr_scanned += (1UL << freepage_order) - 1; + } continue; } @@ -954,8 +958,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); - if (likely(order < MAX_ORDER)) + if (likely(order < MAX_ORDER)) { low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } goto isolate_fail; } @@ -1077,6 +1083,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; } From patchwork Thu Mar 16 11:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13177385 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 91DF8C6FD1F for ; Thu, 16 Mar 2023 11:07:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03A4E900006; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2C62900002; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF551900006; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CF276900002 for ; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9B9F11A045C for ; Thu, 16 Mar 2023 11:07:02 +0000 (UTC) X-FDA: 80574484284.15.A72543A Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf11.hostedemail.com (Postfix) with ESMTP id B837B40015 for ; Thu, 16 Mar 2023 11:06:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1678964821; 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=ajTuW8kXGv5xD4rOn8n789tZBhdCK8u+OH6D44lmjYQ=; b=6l0nqRvzq70D525fedEbA/X3Mi7xaReUu75WnqtOLmYhFPGG2qoi4ndmpt3ZV/NeCUM1JK 7GiYP48bLhi0TnbrkF1kGklwHZsMppSXx8SurvDUs7QPCD3ZVZKP44zGV5W+UKdL7qxjzg 8vL41D8sFI5NQTbmQN2WOTFUKuSmuCc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1678964821; a=rsa-sha256; cv=none; b=HEdJ4sVKwIRhQBm64lWbtFwBGY5XejV9JgXPe9Nl0McTe4y2KBbCT1WWfO6nlZHlkubiSN txVDqxV2BSOBwXD+KNq8RPXVKdYU4es7h6fmFvpwSQhaYgvoCt0OpGvWJjIMyV6qaw6U+6 N1s+FpLQ8oVlijlIqEjTgTTWdPaiL4w= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Ve-MbmV_1678964815; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Ve-MbmV_1678964815) by smtp.aliyun-inc.com; Thu, 16 Mar 2023 19:06:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, mike.kravetz@oracle.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm: compaction: fix the possible deadlock when isolating hugetlb pages Date: Thu, 16 Mar 2023 19:06:47 +0800 Message-Id: <7ab3bffebe59fb419234a68dec1e4572a2518563.1678962352.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <73d6250a90707649cc010731aedc27f946d722ed.1678962352.git.baolin.wang@linux.alibaba.com> References: <73d6250a90707649cc010731aedc27f946d722ed.1678962352.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: jmbmbyw5atin783ohiu1wi697hknfe87 X-Rspamd-Queue-Id: B837B40015 X-HE-Tag: 1678964819-495346 X-HE-Meta: U2FsdGVkX1/KyZkcDkGwIKTFSPSFVtxadL9Bj5+YZFIjPpSU9dUbL/J8Ucv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I= 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: Vlastimil Babka Reviewed-by: Mike Kravetz Acked-by: Mel Gorman --- Changes from v1: - Collect reviewed tags. Thanks Mike and Vlastimil. --- mm/compaction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 7e645cdfc2e9..3df076716691 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -894,6 +894,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); /*