From patchwork Tue May 21 02:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668803 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 9613CC25B77 for ; Tue, 21 May 2024 02:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB0FB6B0088; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 620686B009D; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02B856B0083; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 90B996B0085 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 36501A0FFD for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.25.771B4A7 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 3CE2E120007 for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=AIUR1WPc; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=zfdbqoJ3Tmb1eSzL6LV7bRgLUYSKWEgUd90tmZag82SMsAdQBmJIZAKm4tiTLMiZ1tb0zd TBn++uPC0wybvynGHUk6Y8SGLAIv/2sD6siVghP4+fWc1G+oIWYS9cLYjokVDveb9oxVLT fZOcfEC60H8RQ0g6z+wz5IgA95Mp5RU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=AIUR1WPc; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716259213; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3CfHcPoy4LZXqF1JfuCe7exgO9FOdW12+9aW417X+QU=; b=QrL6IY9p0bCNzh/+7T4Y8ll32gcTy4sq5isW6iVIwHSY4PCjk2qESL4pNmuyt8Y1qYZumy P+XGOcnaPFjKHyyJphT3gUmi/KtWfXXKoh1RdQZCp4tU6S1QaphqX/OieqLhPALDy4FVO5 UYrGQT3E1+94YO0c8rtgsBg9aijHJ0M= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp048b54b35e8dd6786675a0a69b3c691030~RYKifkVgL1838018380epoutp04b for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240521024010epoutp048b54b35e8dd6786675a0a69b3c691030~RYKifkVgL1838018380epoutp04b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=3CfHcPoy4LZXqF1JfuCe7exgO9FOdW12+9aW417X+QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIUR1WPc/vUs4bOffPOm5oSZU1OsaPGBqgVt0bmib7J75/fHxavdA4WMIfdmNzeDu p6B03zN9aWEcmwz1BcfFcG16UOfTtY6IHwFvCh94Vl2AIn84zcE36rL4dUWuRvQlIO QDzQrOEQlaRYgKxq/oo1wTISnF7WUCavpNnZtCts= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p35a6821f1ae02a131f8d71e39773e8fd3~RYKiAz8Bn0314503145epcas1p3d; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.242]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn39p7z4x9QB; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id AE.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p3e80e90863a453053d5aac901ef644070~RYKhVkSAh0309203092epcas1p3t; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp276a000fb3675b0aa18a6053708976075~RYKhU_TN-2496124961epsmtrp2o; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-053ff700000025be-a7-664c09892ffc Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 55.D3.19234.8890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.104.99]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240521024008epsmtip279bc42a8e8f3048a6ffbd81990fd292b~RYKhMbR9s1233912339epsmtip2B; Tue, 21 May 2024 02:40:08 +0000 (GMT) From: Jaewon Kim To: rppt@kernel.org, vbabka@suse.cz, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [RESEND PATCH 02/10] memblock: detect hidden memory hole size Date: Tue, 21 May 2024 11:39:49 +0900 Message-Id: <20240521023957.2587005-3-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240521023957.2587005-1-jaewon31.kim@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkk+LIzCtJLcpLzFFi42LZdlhTX7eT0yfN4PMccYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzph37hZTwV7Zin8vt7A2MJ4X72Lk4JAQMJFovOfexcjFISSwg1Fi28y5 zBDOJ0aJvtd3mOCci3PWMHYxcoJ19G88xAaR2MkoMftoM5TzmVHi+eszYFVsAtoS7xdMYgWx RQTsJL7NPgBmMwuUSrx9c4IZxBYWcJO492sumM0ioCpx9PRisBpeAXuJ5zsWsEBsk5eYeek7 O4jNKeAgMX/KYnaIGkGJkzOfsEDMlJdo3job7G4JgY/sErvm9bFBNLtIzNqyggnCFpZ4dXwL O4QtJfH53V6omnyJCxdfMUECo0Zi4URDiLC9xK6vM1hBwswCmhLrd+lDrOKTePe1hxWimlei o00IolpNouXZV1YIW0bi779nULaHxKdTR1ghwTOZUaKn6z/jBEb5WUg+mIX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+fFFpTmpxYcYpTlYlMR5lXM6U4QE0hNLUrNTUwtSi2CyTBycUg1MUze+fncvd/YxZe/y 889sLr9h5AxM91gpzrL5+fVy54UZ6w21rddsDVyl9VT/Ua7juqtcRUKCN7OYb3Itf9qnHP7u 8ddr4TvDd/+cwDNnw3EtqznbMnZX7j8lYnJh+ZzGddq7HR/9zODwq/R61bGL43DyTsOyvayb NO+pJrOZNWRIvapQ+6V+TZpNK9OhbXutT0pUV/vL9SIfWYtmnDOQvOM5yeeuin6IV7t/64zW DdejRZbG3RB93Dr/7McNe9+Wyah5PK4IfhXeKzcp+sh075QIw4yHR2bEm9+ZlC20bqfOv3C3 CvnkCHse782tWs0uQsHcnBXrH5z7oCrsvJRLMKD3glOyf2XAGQHTeU1KLMUZiYZazEXFiQBz NwUD3wIAAA== X-CMS-MailID: 20240521024009epcas1p3e80e90863a453053d5aac901ef644070 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p3e80e90863a453053d5aac901ef644070 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspamd-Queue-Id: 3CE2E120007 X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 31s9jtodkatuao8yiod6az5z56r3tc6f X-HE-Tag: 1716259212-667004 X-HE-Meta: U2FsdGVkX19kp3M8QzqBaSk4WGN7ly0qVe13diDTozpbQOEA2pI1BOx5lm1+ykCNsyhGRwicn2F9nQLaPJMcTvv/+wOWZWfPCkcecgOzdKN6GjCN2KMJR17b5YkC/XGyQrPSSf4HCyxG3N3mp1+wNvbKYRhFNDoBS7HJDb5RsDsdZczvnpq7yzxKvRuAXkB6TwsEC/1klx3qcTIlim9Da4hCp2qKyFk4/0ajMFvoLuWMbZ9VUymO51yDUyJqI+ja6Q+uBSZ+dt7JyVselepW0xshfCKVEGhs7Zs8QQbN6kHKRhVqza1DHmlrl5cKGYgHB0BXpBajuKMlJIyDS/fg0eO9l+JxpD6ZkAPVpfSiDuiEl47xvCCKGL2cr7hFYBhTtShw+A7+hetd3qTNHWn1HdLHP0b8Mukvcpmvs6FAdi3pmnqLotDKoymBr96Hn4LvENgi9PLMm+SM2cz6b2Ywnkhjn/v6lx7qXATXifywQOO8yBUiCivlJwnC05f1OS2dZKVaCCJsqSQwWo+i1HH9qRqCPdLgiS4jLrZIDkQm3krWlP3EO+s8zEMWMyQAjtl1zQ84zqIt4uAdW3UH+lo6NwkKhkYnZnC/gV6f3PFDU2k0SagT1A2ARezKS6mytysKoq62ImxcFULtim3515uwoPNTsERMkXi1A1ZrXOtNL+iNXKUFLXI3DwNxNuXRd9gn8ta7HDlsiCyOp+nDKRAuB4ZffQIoAaskpAyVRnUpPni3FcGL1YZkWuBxvEaBCcmJJ1hxVEzD3YwxykL8R5RoNCVhJRMBT8zA5FSLoDQHoekQTV0ciO6YCuLm7xO2ldwWP5yPp+uxhkjsX1wzowyqZfuAAxzg2yFRtPz1tY8/+raCSgIYGpQ9+hlzDTCcrFqQUWTbUSJlK9eTZdW1zY/3bwFe9o5wiiBBFzNXAPj1Q4tXJQvxBNF6FU8S9MFXwVsWYkuSJTovXdgMbdQIwlC znrPL0m3 XDR0F73uwnUrsb+ER5rqRKwMOGKzkxqD3yxViZ/lNFC1KqjX3eSPkpCDRvhNm71lflCoksWsXid5U1iSrWif/uwZQLNv+MFbbjp1w0px2S4S0sPLXBDpX8YNMsS6MFTgTYcYhe9nx5jvP77yTUTOMPfFN/1KckDP8zm07 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: Bootloader knows the actual memory size, but bootloader may reserve some memory for a specific purpose and pass the only remaining memory region to kernel. Even though kernel does not know what it is, we need to detect those regions to sum up all reserved memory. Let me call it memory hole. To expect the hole size, this patch assume two things. One is that each physical memory has 1GB aligned size and address. And the hole is less than 1GB. For the hole, let it be shown as unknown in memsize logic. This is an example. 0x0bf000000-0x0c0000000 0x01000000 ( 16384 KB ) nomap unusable unknown Signed-off-by: Jaewon Kim --- drivers/of/fdt.c | 2 ++ include/linux/memblock.h | 2 ++ mm/memblock.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 605c7f471908..da82e5afed01 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1194,6 +1194,8 @@ void __init early_init_dt_scan_nodes(void) /* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range(); + + memblock_memsize_detect_hole(); } bool __init early_init_dt_scan(void *params) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 9ccba9bb20cb..049313871059 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -617,10 +617,12 @@ static inline void memtest_report_meminfo(struct seq_file *m) { } extern void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable); +extern void memblock_memsize_detect_hole(void); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { } +static inline void memblock_memsize_detect_hole(void) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/mm/memblock.c b/mm/memblock.c index f05e7df2f8e1..5204ee71ae29 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2084,6 +2084,51 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n", __func__, &base, &end, nomap, reusable); } + +/* This function will be called to by early_init_dt_scan_nodes */ +void __init memblock_memsize_detect_hole(void) +{ + phys_addr_t base, end; + phys_addr_t prev_end, hole_sz; + int idx; + struct memblock_region *rgn; + int memblock_cnt = (int)memblock.memory.cnt; + + /* assume that the hole size is less than 1 GB */ + for_each_memblock_type(idx, (&memblock.memory), rgn) { + prev_end = (idx == 0) ? round_down(rgn->base, SZ_1G) : end; + base = rgn->base; + end = rgn->base + rgn->size; + + /* only for the last region, check a hole after the region */ + if (idx + 1 == memblock_cnt) { + hole_sz = round_up(end, SZ_1G) - end; + if (hole_sz) + memblock_memsize_record(NULL, end, hole_sz, + true, false); + } + + /* for each region, check a hole prior to the region */ + hole_sz = base - prev_end; + if (!hole_sz) + continue; + if (hole_sz < SZ_1G) { + memblock_memsize_record(NULL, prev_end, hole_sz, true, + false); + } else { + phys_addr_t hole_sz1, hole_sz2; + + hole_sz1 = round_up(prev_end, SZ_1G) - prev_end; + if (hole_sz1) + memblock_memsize_record(NULL, prev_end, + hole_sz1, true, false); + hole_sz2 = base % SZ_1G; + if (hole_sz2) + memblock_memsize_record(NULL, base - hole_sz2, + hole_sz2, true, false); + } + } +} #endif /* MEMBLOCK_MEMSIZE */ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)