From patchwork Fri May 10 02:04:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13660809 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 12782C10F1A for ; Fri, 10 May 2024 02:04:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FA7F6B0082; Thu, 9 May 2024 22:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AA896B0083; Thu, 9 May 2024 22:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 698996B0087; Thu, 9 May 2024 22:04:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4D1976B0082 for ; Thu, 9 May 2024 22:04:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F0AD541660 for ; Fri, 10 May 2024 02:04:38 +0000 (UTC) X-FDA: 82100842236.18.9CEC15B Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf29.hostedemail.com (Postfix) with ESMTP id 51935120008 for ; Fri, 10 May 2024 02:04:37 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XF3exSkX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715306677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=BI5tyqymmN9gGbJ6fagCaRykBg1tbmyzeV+T0zeBy6M=; b=hZCc5k3yqb8FIG5NUqsb9HOT42bx0o9PohKo9Kan/oJhL6fvTKp01Pgm4GRBBGSTS4+HxE nFCb85YwZxprveOls92SL+nhDxruePtMyrWDOw4EONlw9AM7cSQzxHkDo0ce/RtxWghvft im5U7IcBfKZPugQcYxSca6e2BngUgnM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715306677; a=rsa-sha256; cv=none; b=dxEFa7kkrsgapg45lTjnGesmYLkGuvc91j90qr1dpDYG0Dc4u8LWiXmRWLrM+OOfEcNf7d eQgQM4zG71YGGlTSOKovxZO0CR22nOjONLb65G2BMatAo6WAUrRryXDA20UDhkbC9dIfK/ bfzlME6NHpA1JqK22WMmCK0W2eCvFAg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XF3exSkX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a59c0a6415fso422903066b.1 for ; Thu, 09 May 2024 19:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715306676; x=1715911476; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BI5tyqymmN9gGbJ6fagCaRykBg1tbmyzeV+T0zeBy6M=; b=XF3exSkXut9bPdf0x2+jvEmwFn2g8bx0H4fmrdtd3bGlYXFavmoRNAaOyjxmwvIHvQ khlbZ7PmZFSuujIgPbb8hDafMoRwr/HNUJoHQuUP+AOEU3yEuZvQbnhZhyB4NXdObetm w4js8/9Fkl6OQK5N62mIzVdDRyxibVWUgywFhHo28JApy761fQuHksA3OeiPvPSePjs6 ZshIa9e1WFJUXtrpbmNRaNqwFk+4CMVMYtOuxM9f+wpZEBd8jvMAjRl+RM4/AS79YbpA qvx5OhFXDUFTGTSd9CopBCMfHzPReeRHB2hJZn4qwNaCXLTZrOr0NqW+jJtJcWygSf2N QzlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715306676; x=1715911476; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BI5tyqymmN9gGbJ6fagCaRykBg1tbmyzeV+T0zeBy6M=; b=VUyrYET76tt+PxFLge1WXZ8nmQrVcyBpsYMJT7udFOlJ1uqimLBGKqYCEeirrm/E/B nkzgvFjgilZYjou8YSzmCcadZa5p6j/XvmuAsKeT4GBu8Z2jyxAnMqbhVx45XuejF2ja fvhWfKIBy2ZVhuuDWBu9EP5SNxx7ARGpV405tudV5li5iWSQQJyT5lxI2My7ewhG1HzN 98f7C0R/fHXbZIvadMMK/B1PamWn0U+khIxhnTA1CJoLO8cAPE0OH0O35af2gHbW+08s 3drL6/uilL/L1tBBbbZimFpSUsPo3E8XbirH4aQvTnSWhGBGYi276La3CXCJSBna0ulJ WUAQ== X-Forwarded-Encrypted: i=1; AJvYcCXe+p9aoGVrbuHI5cMuMsuIFjadvlOY5ya7N22H5kGMIhPLsPWpmOYE8NlSBTsCGYwfr2GVucC/gYi2LaFZnFUbnMo= X-Gm-Message-State: AOJu0YyUseQ1VOqvqk2GKvHoFITG7VDmOIoexEERJy8uhaBDpoMOyFV2 3K2z0LfbwBqhv2K7NYpWWP/+PPpGC40CC0XBNvkElm8X1qsWetuv X-Google-Smtp-Source: AGHT+IF2QDguCK8rTieenO0F4aGJLfLKKE/VD2hKk7gSUjMQEBdHmWN/fJPbugbyh1hN9Y/Vir1/Ug== X-Received: by 2002:a17:906:3c57:b0:a59:2e45:f528 with SMTP id a640c23a62f3a-a5a2d5c96b5mr71148666b.38.1715306675648; Thu, 09 May 2024 19:04:35 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a1781d553sm133706966b.43.2024.05.09.19.04.34 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 May 2024 19:04:34 -0700 (PDT) From: Wei Yang To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, arnd@arndb.de, rppt@kernel.org, anshuman.khandual@arm.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Wei Yang Subject: [Patch v2] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set Date: Fri, 10 May 2024 02:04:22 +0000 Message-Id: <20240510020422.8038-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 51935120008 X-Stat-Signature: sqbda37kwdk3opiokinbn9aofef1eabg X-Rspam-User: X-HE-Tag: 1715306677-880944 X-HE-Meta: U2FsdGVkX19wkztz8sLnnKYbuhG7tz557BnTCBA328GCm/cmrl/XiAt1yfP0mYDpoOanA3nRpgxkJXRGcJu3hUui2Mzl+D4zWCp8FWiw3rhIG7HDPUw/vVEcmGDGLqAQYM1FkdNbnKuQ2yYM3jFJcX2Fd7kzGkZYYBOGYTxk7Mi+kFSVwWIoRS0/0pgwa64F2bQ+uza0Cj9gFcpQRGKyjS89BtnZvcDYQ2vAkSYL4pmkHGSZNVV0Ut4nAXhnJpgteuVJ/9ZAOoaitWcFI9pdp10745NeFsCYObVVY9fHnuugdaaUsvGANCq76FISyC/txNa48rFfR7Acd7WAYakTV77UOVyUIG7FzTIblmKP8EYke4aFHy5BuBDg1XUUvLfKM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HzB1dLAIf3XgrO4zFQ/T3cFnnRUen5K8fVsktd1O9crPyHUKPJND6Q968HNIHByI81XM8EYLtYhFWlr/D0d0CYGvYew== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When CONFIG_ARCH_KEEP_MEMBLOCK not set, we expect to discard related code and data. But it doesn't until CONFIG_MEMORY_HOTPLUG not set neither. This patch puts memblock's .text/.data into its own section, so that it only depends on CONFIG_ARCH_KEEP_MEMBLOCK to discard related code and data. After this, from the log message in mem_init_print_info(), init size increase from 2420K to 2432K on arch x86. Signed-off-by: Wei Yang --- v2: fix orphan section for powerpc --- arch/powerpc/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- include/linux/memblock.h | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index f420df7888a7..d6d33bec597a 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -125,6 +125,7 @@ SECTIONS *(.text.asan.* .text.tsan.*) MEM_KEEP(init.text) MEM_KEEP(exit.text) + MEMBLOCK_KEEP(init.text) } :text . = ALIGN(PAGE_SIZE); diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index f7749d0f2562..775c5eedb9e6 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -147,6 +147,14 @@ #define MEM_DISCARD(sec) *(.mem##sec) #endif +#if defined(CONFIG_ARCH_KEEP_MEMBLOCK) +#define MEMBLOCK_KEEP(sec) *(.mb##sec) +#define MEMBLOCK_DISCARD(sec) +#else +#define MEMBLOCK_KEEP(sec) +#define MEMBLOCK_DISCARD(sec) *(.mb##sec) +#endif + #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries)) #define PATCHABLE_DISCARDS @@ -356,6 +364,7 @@ *(.ref.data) \ *(.data..shared_aligned) /* percpu related */ \ MEM_KEEP(init.data*) \ + MEMBLOCK_KEEP(init.data*) \ *(.data.unlikely) \ __start_once = .; \ *(.data.once) \ @@ -573,6 +582,7 @@ *(.ref.text) \ *(.text.asan.* .text.tsan.*) \ MEM_KEEP(init.text*) \ + MEMBLOCK_KEEP(init.text*) \ /* sched.text is aling to function alignment to secure we have same @@ -680,6 +690,7 @@ KEEP(*(SORT(___kentry+*))) \ *(.init.data .init.data.*) \ MEM_DISCARD(init.data*) \ + MEMBLOCK_DISCARD(init.data*) \ KERNEL_CTORS() \ MCOUNT_REC() \ *(.init.rodata .init.rodata.*) \ @@ -706,7 +717,8 @@ #define INIT_TEXT \ *(.init.text .init.text.*) \ *(.text.startup) \ - MEM_DISCARD(init.text*) + MEM_DISCARD(init.text*) \ + MEMBLOCK_DISCARD(init.text*) #define EXIT_DATA \ *(.exit.data .exit.data.*) \ diff --git a/include/linux/memblock.h b/include/linux/memblock.h index e2082240586d..3e1f1d42dde7 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -100,13 +100,13 @@ struct memblock { extern struct memblock memblock; +#define __init_memblock __section(".mbinit.text") __cold notrace \ + __latent_entropy +#define __initdata_memblock __section(".mbinit.data") + #ifndef CONFIG_ARCH_KEEP_MEMBLOCK -#define __init_memblock __meminit -#define __initdata_memblock __meminitdata void memblock_discard(void); #else -#define __init_memblock -#define __initdata_memblock static inline void memblock_discard(void) {} #endif