From patchwork Tue Jun 13 08:55:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13278167 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 09ACAC7EE29 for ; Tue, 13 Jun 2023 08:55:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 869D68E0003; Tue, 13 Jun 2023 04:55:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 819948E0002; Tue, 13 Jun 2023 04:55:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 708628E0003; Tue, 13 Jun 2023 04:55:21 -0400 (EDT) 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 6156F8E0002 for ; Tue, 13 Jun 2023 04:55:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F533403C6 for ; Tue, 13 Jun 2023 08:55:21 +0000 (UTC) X-FDA: 80897115642.03.7FA7083 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf07.hostedemail.com (Postfix) with ESMTP id AD37940015 for ; Tue, 13 Jun 2023 08:55:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1686646519; a=rsa-sha256; cv=none; b=oTmycWnJO3spFsTMn6EW+qgR+j5AaKjjViDd9lnkLpHPtTuo6h3n0KJaqkhJugb4mmSZVI YraxaYq/7b886ltzPRrrcjPRNh01+iwaCCaUuYIqHFV2cv+DR4JnO9BhDyfGgwk9okAh/X enLhw8EwU3UuIeqrG2ouS4QNFq24VXo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1686646519; 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=wMcBRFqfTE0STr9JCRRLkDjxGqHSrWjNxvDD1SWW8XA=; b=xYZGrh7RMLSEU39pdt5y+345MZL7rE4uZnYrc8rssRbRXRtQmv9jqzhd/rPmjlv/0NevTY jxY57FrVtg7Q9pBIKCEbj/ufBEbiPpigpiffPoWxqmuO64Pe7AtAWsdixDo1rohKjEijIZ t2SCeUKNnhfZdA1hDe7BXud2YAuYM2Y= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R961e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Vl1OoaE_1686646513; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vl1OoaE_1686646513) by smtp.aliyun-inc.com; Tue, 13 Jun 2023 16:55:13 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, david@redhat.com, ying.huang@intel.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm: compaction: skip memory hole rapidly when isolating migratable pages Date: Tue, 13 Jun 2023 16:55:04 +0800 Message-Id: <770f9f61472b24b6bc89adbd71a77d9cf62bb54f.1686646361.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AD37940015 X-Stat-Signature: j8ac6frhw65b8xoxzpj5khxaq9zkotw3 X-HE-Tag: 1686646517-159180 X-HE-Meta: U2FsdGVkX19msD0fiUky4F3gczCnE4Uyw0VX2XNKfkNEoBFsBiC9Mrxi+iOaxkLRi0WyLJd1FVyiGWwEqXxjkmZwUfCLrAJ3XYZWE+mq+ERSOnnZcHTaaBUUhzyNfCPDpzPZ5m+nBDlRtPMaSU9I/Fkepeol1s8tmM8GL4ycyQiKPYjuHVKE4kmxjB3D28UgcVYyZfDkUXZeTcHrGyyQw6HPNtr0VSvuFLP/VMZnNQXbaJEWE8M2O/aamxcO8p73JgzAkMIavNLUl95Dl6/4IwbRClrP6HrGsf/VrkG3ql+2SYGlJAKYzAofztps5yxiScAPR1Vu7RQiQjtKNrDdDz1kvNIoRLhv+b1qkbARH1LzTRj5/JEXC050zjg/jeGKzPdEe7+2hsONyPLuc4YISD+2HxleyzWf3jW1z4dnqsYlsLJTHDM9HlXZ2zbj6/mR9NQ5irSLTGQS5qa+tVcTsgvNWH5OFWcc6ktKsxB08zaf8mT+y+l/KuiY7hCmdSZa5QwJEmaarQuY4f/WCiCXe8qy5/BtmtAYPmqDD500336yHswGkzc60uEBRevJRt/MJTazSgajeGif4CsYk8zwL7JvVvs6vuWrOCGXzxKj1xMXM2q84bSvoDS1NKX7iB/KbQJq62wPLRaHEs+rBZUICUdqmxbpYpFW5MtUioEe8EhQmKXlPd3H/lvYkn/WJg/IaqYg8giEkbkwlM/w280jHVwmebx1kONQmrZysInw63YWDcY4YWiwcb63pP7jPOUj5OxSCeFZpOlV3nh80pS3knO6W1pZzsLPS2MKvgc3MBXahQWqcO0Gw/SEcNiHSLWvp5a1Zocv4Ekzz8LbJaEX+R3CCCqPnLBrY0nAL0SXi+Sr88nB91UlVM85ah0q6Kz+xSWSKcbNAYWIv107PMVriP+E8JZmryu4U4HT9uU3CvzHM9f7oFxOSfB7tQxA3Xwu2dvFpSKDHlkkRQ7X9qv 22+iEMmc KJpWSptcKU+JMTRI2WGVBUScpOhzTJAF7xo0sbF+CNYoSPr2bZEcfzHYEX1IUN6S7TVZw0kK69qjuFRrefqDgpl++UfMNYACrCmq8SZUOgkzwYC1kWHcCclrddHO9JOJ6LqSNiNRCdcm2rTM= 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: On some machines, the normal zone can have a large memory hole like below memory layout, and we can see the range from 0x100000000 to 0x1800000000 is a hole. So when isolating some migratable pages, the scanner can meet the hole and it will take more time to skip the large hole. From my measurement, I can see the isolation scanner will take 80us ~ 100us to skip the large hole [0x100000000 - 0x1800000000]. So adding a new helper to fast search next online memory section to skip the large hole can help to find next suitable pageblock efficiently. With this patch, I can see the large hole scanning only takes < 1us. [ 0.000000] Zone ranges: [ 0.000000] DMA [mem 0x0000000040000000-0x00000000ffffffff] [ 0.000000] DMA32 empty [ 0.000000] Normal [mem 0x0000000100000000-0x0000001fa7ffffff] [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x0000000040000000-0x0000000fffffffff] [ 0.000000] node 0: [mem 0x0000001800000000-0x0000001fa3c7ffff] [ 0.000000] node 0: [mem 0x0000001fa3c80000-0x0000001fa3ffffff] [ 0.000000] node 0: [mem 0x0000001fa4000000-0x0000001fa402ffff] [ 0.000000] node 0: [mem 0x0000001fa4030000-0x0000001fa40effff] [ 0.000000] node 0: [mem 0x0000001fa40f0000-0x0000001fa73cffff] [ 0.000000] node 0: [mem 0x0000001fa73d0000-0x0000001fa745ffff] [ 0.000000] node 0: [mem 0x0000001fa7460000-0x0000001fa746ffff] [ 0.000000] node 0: [mem 0x0000001fa7470000-0x0000001fa758ffff] [ 0.000000] node 0: [mem 0x0000001fa7590000-0x0000001fa7ffffff] Signed-off-by: Baolin Wang Acked-by: David Hildenbrand Acked-by: "Huang, Ying" --- Changes from v1: - Fix building errors if CONFIG_SPARSEMEM is not selected. - Use NR_MEM_SECTIONS instead of '-1' per Huang Ying. --- include/linux/mmzone.h | 10 ++++++++++ mm/compaction.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 5a7ada0413da..5ff1fa2efe28 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2000,6 +2000,16 @@ static inline unsigned long next_present_section_nr(unsigned long section_nr) return -1; } +static inline unsigned long next_online_section_nr(unsigned long section_nr) +{ + while (++section_nr <= __highest_present_section_nr) { + if (online_section_nr(section_nr)) + return section_nr; + } + + return NR_MEM_SECTIONS; +} + /* * These are _only_ used during initialisation, therefore they * can use __initdata ... They could have names to indicate diff --git a/mm/compaction.c b/mm/compaction.c index 3398ef3a55fe..c31ff6123891 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -229,6 +229,28 @@ static void reset_cached_positions(struct zone *zone) pageblock_start_pfn(zone_end_pfn(zone) - 1); } +#ifdef CONFIG_SPARSEMEM +static unsigned long skip_hole_pageblock(unsigned long start_pfn) +{ + unsigned long next_online_nr; + unsigned long start_nr = pfn_to_section_nr(start_pfn); + + if (online_section_nr(start_nr)) + return 0; + + next_online_nr = next_online_section_nr(start_nr); + if (next_online_nr < NR_MEM_SECTIONS) + return section_nr_to_pfn(next_online_nr); + + return 0; +} +#else +static unsigned long skip_hole_pageblock(unsigned long start_pfn) +{ + return 0; +} +#endif + /* * Compound pages of >= pageblock_order should consistently be skipped until * released. It is always pointless to compact pages of such order (if they are @@ -1991,8 +2013,14 @@ static isolate_migrate_t isolate_migratepages(struct compact_control *cc) page = pageblock_pfn_to_page(block_start_pfn, block_end_pfn, cc->zone); - if (!page) + if (!page) { + unsigned long next_pfn; + + next_pfn = skip_hole_pageblock(block_start_pfn); + if (next_pfn != 0) + block_end_pfn = next_pfn; continue; + } /* * If isolation recently failed, do not retry. Only check the