From patchwork Mon Jun 19 02:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13283940 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 0FF2DEB64DA for ; Mon, 19 Jun 2023 02:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 490C88D0002; Sun, 18 Jun 2023 22:22:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43FD58D0001; Sun, 18 Jun 2023 22:22:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32F678D0002; Sun, 18 Jun 2023 22:22:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2486B8D0001 for ; Sun, 18 Jun 2023 22:22:45 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E9BAE1C7CAE for ; Mon, 19 Jun 2023 02:22:44 +0000 (UTC) X-FDA: 80917899048.29.4214330 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf14.hostedemail.com (Postfix) with ESMTP id 1665C10000C for ; Mon, 19 Jun 2023 02:22:41 +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.97 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=1687141363; 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=CyT4S1kEknbc1R5ZtEH47oN7IljlC+lFmN4VH5e+5Cw=; b=raJ84w6d0xcZnzcnDBKS7dv4iVsF4owG1KMI8ZTcZIW3KoT2Zox68IXfUIBRINJI8AkoVL AwAayPWeOpQbc4OYNPzfrOlGIqhQDhZaX76441PbKi1VPe2whJq1sALpg4LQeAmi57ouKE CX3sRpySdu9SaDI7wg2dlGvrszH8sLA= 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.97 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=1687141363; a=rsa-sha256; cv=none; b=yBlkq1GK/rcwSGl86Dq/l7rJPBHJnZcyla2NXNOeWD3wVA9YDXIQzJ73iGRrvyoiDv5XN9 v1TJzDKMOoCqauEMP4UPnL41mwEkbAd1euzfamxarcgMcLvMXpDrd2qoJdzwlCeMMmA/cu DRoi0CYauwhbXlLKuj57Ofm3JvWMLRQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;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=8;SR=0;TI=SMTPD_---0VlNkAdD_1687141356; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VlNkAdD_1687141356) by smtp.aliyun-inc.com; Mon, 19 Jun 2023 10:22:37 +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 v4] mm: compaction: skip memory hole rapidly when isolating migratable pages Date: Mon, 19 Jun 2023 10:22:24 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 1665C10000C X-Rspam-User: X-Stat-Signature: dqbwufgqyc8t96pjo3ibzw7ymmepa8jw X-Rspamd-Server: rspam01 X-HE-Tag: 1687141361-920095 X-HE-Meta: U2FsdGVkX19Hj+1f4kzGh2FqjuBk5Yzi1u51RLib4O7gSOquZrBREx9yxb+edIZn9j+1T7xATcPIIGoL8oWvol96P3+M0UvKYrbfWzHOB9bgHXn9Kr0Rwd4yNVlFy3Q6GdZWg9l0Xi6+vqd0vi3wmWXKIIEdvEeThdzrZ1yuMAvidNXChWsIWMnLHeMCwB5Xj/L83+krebXyyXHa8oD8V2BlZvMD6Rj2Oly17cndLCrHBTI7RPiBDPRirxAjflFK9/H0SBWEeFyf0NaALqTmpgcXEo2ssq0wYTJp6Jwaj95lZ/yTvBPzy1DaJ+ZHTNMSiQcqyxpY360bZw/85Z4Cg1GtMq56fs1B1NbGZ3psAh9RPkn/V8DT3x34ZTyde8j2g4HM7efZtSgiesklTAWWGorP+UImpBfMwtbop+rO3E1RbWVf2ZRWCDdz5sW9nWRTj0sJWziqhsB9uGPW8D0hKffsin6zYYCGh/FbaXE4xjjnIxR11od8CWXVuGMjMDV4500gxVVALtmSEaDOs0XsXMEjp1++UFWy+UFcfh9SXwQ24NLhIRohfS+c1AUkNNW/R8wrgzN6ztUJUCJiJY2gWjBlHnryrXuHvVKAry2dGulOMYufgCOf8YvQZGexz9cUnLvAp3IK96rVwXsHcX7uzPZeP2JI3poJdTRGYf5rlktcC9EK/YycckQT1QgqNEAbvxL5c+GzkogJXf7fzrve+7rbxjs6h4O9Dz71QKaAKJ0yJ4YF6/kQSmL+G1QZZvkMMNAtC73WO2qQR/Lx6UmXEOUvHVyOcY4V7V9YCqBzqMoZuma3V+A4d5qpsX9k1tK2Hz4baDBgA+0vJNvcXY811CRgza2FvAQRKAw/E7XQ5YCp+gt6pSGDhTMVg3/7hK6nzgOf0sNFWNgL0xhyP6sNu9bLWWgGWDSoE5z+TfaXEWJejItndEtQP6qNMGJ/SgC9nPaV6DF+0K9v2YnKicV xdkxCc4Q V7lDdWLyel5wW2a8t1ERz8R1tdnluvQ0A+CrH8FFsmjlB5qlsGopDJ8fIsz3wbu8m3h/M72L278FQb9V0htkza1BwjDt8gal79LFGPbo4brhsPGyK9H88UD1MuB/kuprbibS0n7bLPc2eKL0Oa4a8RtJL5YPEcca9XKpZkt3yRlhZBAu4bcfq9D6h6Q== 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] Suggested-by: David Hildenbrand Signed-off-by: Baolin Wang Acked-by: David Hildenbrand Acked-by: "Huang, Ying" --- Changes from v3: - Limit next_ptn to not exceed cc->free_pfn. Changes from v2: - Simplify the function suggested by David. - Collect acked tag from David and Ying. Thanks. Changes from v1: - Fix building errors if CONFIG_SPARSEMEM is not selected. - Use NR_MEM_SECTIONS instead of '-1' per Huang Ying. --- mm/compaction.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 3398ef3a55fe..3dc3b804bcbb 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -229,6 +229,33 @@ static void reset_cached_positions(struct zone *zone) pageblock_start_pfn(zone_end_pfn(zone) - 1); } +#ifdef CONFIG_SPARSEMEM +/* + * If the PFN falls into an offline section, return the start PFN of the + * next online section. If the PFN falls into an online section or if + * there is no next online section, return 0. + */ +static unsigned long skip_offline_sections(unsigned long start_pfn) +{ + unsigned long start_nr = pfn_to_section_nr(start_pfn); + + if (online_section_nr(start_nr)) + return 0; + + while (++start_nr <= __highest_present_section_nr) { + if (online_section_nr(start_nr)) + return section_nr_to_pfn(start_nr); + } + + return 0; +} +#else +static unsigned long skip_offline_sections(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 +2018,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_offline_sections(block_start_pfn); + if (next_pfn) + block_end_pfn = min(next_pfn, cc->free_pfn); continue; + } /* * If isolation recently failed, do not retry. Only check the