From: Wei Yang <richard.weiyang@gmail.com>
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 <richard.weiyang@gmail.com>
Subject: [Patch v2] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
Date: Fri, 10 May 2024 02:04:22 +0000 [thread overview]
Message-ID: <20240510020422.8038-1-richard.weiyang@gmail.com> (raw)
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 <richard.weiyang@gmail.com>
---
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
--
2.34.1
next reply other threads:[~2024-05-10 2:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 2:04 Wei Yang [this message]
2024-05-21 7:21 ` [Patch v2] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240510020422.8038-1-richard.weiyang@gmail.com \
--to=richard.weiyang@gmail.com \
--cc=aneesh.kumar@kernel.org \
--cc=anshuman.khandual@arm.com \
--cc=arnd@arndb.de \
--cc=christophe.leroy@csgroup.eu \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).