From patchwork Mon Jan 22 13:01:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13525475 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 B4FC8C4725D for ; Mon, 22 Jan 2024 13:02:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2579A8D000A; Mon, 22 Jan 2024 08:02:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2073C8D0001; Mon, 22 Jan 2024 08:02:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CFA48D000A; Mon, 22 Jan 2024 08:02:10 -0500 (EST) 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 EBF8A8D0001 for ; Mon, 22 Jan 2024 08:02:09 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7D639120975 for ; Mon, 22 Jan 2024 13:02:09 +0000 (UTC) X-FDA: 81706959978.25.0DFD24E Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf14.hostedemail.com (Postfix) with ESMTP id 273E510001A for ; Mon, 22 Jan 2024 13:02:05 +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.131 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=1705928527; a=rsa-sha256; cv=none; b=ix5DIZAHfw1Y7XyHgidzidSUw/LVxnbtVQXtM9LHMYA8CinI6/1OcLfXuOvFnXSx0OeNAx 848BfAyjRUuQi1UlByKPFj6ubWe2gRlA5a/TDM/95LYKIM4cNxWmaAT+JxxuIlcx1nJaOM vfc704MgMCMxItNMEFSv3rA17RLj3W8= 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.131 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=1705928527; 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=Awqm017N7vQFp4JrgKRCbTmtieueFVH0lrkzBTkrwqY=; b=gMw/pelHBTE/ujia6yt6gipTWpShqenbFGa/1GRsLGPJsDlgRsonByI5n9GSBizoxHv6v3 XABKVcuDRnbDMxTYFrDVTYfwq/kZj8wdOvpu4kK3kTXvo+VxhPwD7QyuB4zx3vyBXWO9EL MvHtHmuk6WTtcwfcNApPkQbdTN5YrTs= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R771e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W.9DBn2_1705928520; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W.9DBn2_1705928520) by smtp.aliyun-inc.com; Mon, 22 Jan 2024 21:02:01 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: compaction: limit the suitable target page order to be less than cc->order Date: Mon, 22 Jan 2024 21:01:53 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 273E510001A X-Stat-Signature: fy437ccpbbzeg9hqwq9afzai7sn4sgky X-HE-Tag: 1705928525-218526 X-HE-Meta: U2FsdGVkX19tOZjSQok5MWx/Qnh2KK1vJ+7iaC2xyfHVEa2VnLzOendzdPvpca6M6dIW26usR/cRx8be0sh2R5jGTlqRIPuCTYHviW8LaLrSSkbA+H5WIkqThcy2UKO5ADwWoX2aRW0eGKsQbxVJwyuJ3Tf1x+m40PiHDI60ik0TrKfzWyVh2GT0IIJNQqOliLuNetuTWDdxOhqrsg4zepnILWEkLM+4VFCYcmib1dPn4tgeNA+RkaADRNvZzgdz41lzwUsdRKpOq3xvFSaUkmGBmmfYaW/sPVc8n3b71gv+3IF3epmZTcIpj1XM8nu7dYbSZu+xdQE3UmsjumdKbgugjkYfa1cBLYledw7VpmrvkD3lao5UsOZV3Yo8xETW47ajKjJa1+0KyD+x6wbQYX/GoDrKNcwfH/jYK2KBAtBsjbQLRmCRaGDNHAXMHDmemyhyPp1iBeEJW7FQ5uUpljwyi/QBkL47fab19V9P2HbtTfSZrlXpKmJOk07HG8Db06vBVL0+euqNxOKQ8bN1crRxwIMrSBcbEA4HQS+g5tnmM4aQC22I+O0W0w3cL2zZmR+rlpBlPP8kuOtTp0nQU4L9qleNuUiKvePkEE3T+nxIwkb34CJ5+MAqcF8sGlqYEB23Rz3TZWN/U+2kmx3c5g1dKb4k9QoLhZWI96p805JTheLUDcO7QmTvTLVF9dvlMuFwE2yCccaKV0svgqPbaK9dC88ANe+IhiyraAjXrKs37LPjqkecfr+bDNZ598+frlTgIXvFJPq7LkzKvFWZYDjp0AxCpEVCrYCfTApkXiik/RbP8QX0UTHAge/oBj+ep1eqv5iHGeIihiEXdLxum6dsijgnG4IV/wXSA4FrUIiiXLnjtCc0Mtw7PGrQSAY05DHc3b0idx6eW9U9T0PKbryM4T8XWz/Yt0osU4Cr2rtbxDovAI7fJYNvCsU6NhfYERgxZfZTK1VjOXQW5eN zDEQn3t9 E6w3XN1kkozTLrhONY6gYuqTo094cFZWUQu0Mjw+YX3rRGztGEz8QxnV85iJsxKroLhivQb5JKOKjwjE= 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: List-Subscribe: List-Unsubscribe: It can not improve the fragmentation if we isolate the target free pages exceeding cc->order, especially when the cc->order is less than pageblock_order. For example, suppose the pageblock_order is MAX_ORDER (size is 4M) and cc->order is 2M THP size, we should not isolate other 2M free pages to be the migration target, which can not improve the fragmentation. Moreover this is also applicable for large folio compaction. Signed-off-by: Baolin Wang Acked-by: Mel Gorman --- mm/compaction.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 27ada42924d5..066b72b3471a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1346,12 +1346,14 @@ static bool suitable_migration_target(struct compact_control *cc, { /* If the page is a large free page, then disallow migration */ if (PageBuddy(page)) { + int order = cc->order > 0 ? cc->order : pageblock_order; + /* * We are checking page_order without zone->lock taken. But * the only small danger is that we skip a potentially suitable * pageblock, so it's not worth to check order for valid range. */ - if (buddy_order_unsafe(page) >= pageblock_order) + if (buddy_order_unsafe(page) >= order) return false; } From patchwork Mon Jan 22 13:01:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13525476 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 6469EC47DD9 for ; Mon, 22 Jan 2024 13:02:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB8A28D000B; Mon, 22 Jan 2024 08:02:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3C708D0001; Mon, 22 Jan 2024 08:02:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB6018D000B; Mon, 22 Jan 2024 08:02:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B7FEE8D0001 for ; Mon, 22 Jan 2024 08:02:10 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8F45E4096C for ; Mon, 22 Jan 2024 13:02:10 +0000 (UTC) X-FDA: 81706960020.09.E765F7F Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf11.hostedemail.com (Postfix) with ESMTP id 9C21340013 for ; Mon, 22 Jan 2024 13:02:08 +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.131 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=1705928529; 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=S4BwThlYZzBoyBJbt2aZkpSqomBx3jFmZiluhF6Lhjo=; b=t5D9PwTzOjCXj8Ad8pd2XIWCf5DuNEHQXV4XiuU3hZeCqZeehPjbfSV6hgKGkrwUdJnMIy 79z9eoFd4+W5hSfDaGImrC+5Nkgx5jav+A0TbA3galZkL6LDF/ZRHenV1w3F1Xx9bFNpOv ky0SVurvPVVgmcJ2xl7NrURWKhAT8BQ= 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.131 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=1705928529; a=rsa-sha256; cv=none; b=17LIz1eq5EiGUovVFEa3q5QwTiZn8F2Ep329Ip2Am2wnMgdG6SY1vxvIOwEpSnLet76k6R 1HDdbIj1UNdHDySKbjufEvVkZAiZFY9/U0WtreMImgzDOxZCQThTS7IL6sb6AJmxJ2aTjs 8ajZaC+rSOwQht+eUjtqcljbTnpstkc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W.9DBpR_1705928524; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W.9DBpR_1705928524) by smtp.aliyun-inc.com; Mon, 22 Jan 2024 21:02:05 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: compaction: update the cc->nr_migratepages when allocating or freeing the freepages Date: Mon, 22 Jan 2024 21:01:54 +0800 Message-Id: <0773058df022fa701b78f9a6dfe3c501a1a77351.1705928395.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 9C21340013 X-Rspam-User: X-Stat-Signature: won5m8wjy9gmbo98d9xiuhipe549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fPWHtUDPdPxkGzWluaBtgbYZ/9pbDtF2Ek9HWbOMkE/VEkd7+jCOChKbCTNOlqgaBbhVusBMxWF/9M7lSKgA0+YEBQgNFx8VEATSw8EaxuBI0mPOzh03xSX1gOV3ZJhUC3+J7 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: List-Subscribe: List-Unsubscribe: Currently we will use 'cc->nr_freepages >= cc->nr_migratepages' comparison to ensure that enough freepages are isolated in isolate_freepages(), however it just decreases the cc->nr_freepages without updating cc->nr_migratepages in compaction_alloc(), which will waste more CPU cycles and cause too many freepages to be isolated. So we should also update the cc->nr_migratepages when allocating or freeing the freepages to avoid isolating excess freepages. And I can see fewer free pages are scanned and isolated when running thpcompact on my Arm64 server: k6.7 k6.7_patched Ops Compaction pages isolated 120692036.00 118160797.00 Ops Compaction migrate scanned 131210329.00 154093268.00 Ops Compaction free scanned 1090587971.00 1080632536.00 Ops Compact scan efficiency 12.03 14.26 Moreover, I did not see an obvious latency improvements, this is likely because isolating freepages is not the bottleneck in the thpcompact test case. k6.7 k6.7_patched Amean fault-both-1 1089.76 ( 0.00%) 1080.16 * 0.88%* Amean fault-both-3 1616.48 ( 0.00%) 1636.65 * -1.25%* Amean fault-both-5 2266.66 ( 0.00%) 2219.20 * 2.09%* Amean fault-both-7 2909.84 ( 0.00%) 2801.90 * 3.71%* Amean fault-both-12 4861.26 ( 0.00%) 4733.25 * 2.63%* Amean fault-both-18 7351.11 ( 0.00%) 6950.51 * 5.45%* Amean fault-both-24 9059.30 ( 0.00%) 9159.99 * -1.11%* Amean fault-both-30 10685.68 ( 0.00%) 11399.02 * -6.68%* Signed-off-by: Baolin Wang Acked-by: Mel Gorman --- mm/compaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 066b72b3471a..6c84e3a5b32b 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1779,6 +1779,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) dst = list_entry(cc->freepages.next, struct folio, lru); list_del(&dst->lru); cc->nr_freepages--; + cc->nr_migratepages--; return dst; } @@ -1794,6 +1795,7 @@ static void compaction_free(struct folio *dst, unsigned long data) list_add(&dst->lru, &cc->freepages); cc->nr_freepages++; + cc->nr_migratepages++; } /* possible outcome of isolate_migratepages */