Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp368263lqh; Tue, 7 May 2024 01:17:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzcTOqBs6CKYsVNZIi7ppSgbzUnyFuMlgVZtu0Qu/qP2y38dr9JyEESWa0O159VCfB1Llee3aOH6q25kKFzZdkhooie/mmY7ozULBQ9A== X-Google-Smtp-Source: AGHT+IFjkZnTu2DIEB+8F5Tt1FgwB8yFKV9aRDOxGI5HDiPpNAyvqIYdCTKa/GcVh+p1UlhBwjDF X-Received: by 2002:a17:906:4a8a:b0:a51:8672:66e4 with SMTP id a640c23a62f3a-a59e4cf82c9mr163442066b.22.1715069835990; Tue, 07 May 2024 01:17:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715069835; cv=pass; d=google.com; s=arc-20160816; b=BIgXTzJlJ7Ed2c3/ld5Yjm1e5I9RkXQTd62p9YsuNB+Pw/eqOTCyfFlOv7POPo2ftM 6Ic/2yGjDCLih6I56VlhCvk6fu4l7jLk6EYPwbRK1jqQXr+7YAfYMO1jVu44dOq0Cb7a 0epFlp3I4cxSYA0jh1d02nRdPzrLg2JteuOuEk/YxU5V1n6MxqG51J97kFscJRkXwuj4 n4AgoNig6AotgDRZdfAUqJkFb76/MFxZUl2nNkXMNLfkkqkcviao5c+DEBXuzbz5waqR K9ZaSVb5j/mBLeRrOyy7Bu4d7L5M5ERFvEs0UUb+ekloXGbGzWgxe1Xn42AtpAZuyzO0 5cIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=maPe74un1UQbFXNUNtNwtmyr5vBb7tDiWAcBESvmSQ4=; fh=Ez8KkKrLRKEJo/ygAjsWUuIBMzgTnCeyiX/0kZM14HQ=; b=fiqyNnI1i9oqc2YPTL+DpLF1WiNVUB0cMSl53ug49Hi2+lrHwGUr0aAKvuhLnicbwR ErQOmElOKQuFRytmkqLenlcM9tPQxEJphkJ5WSPtf455lhGsWnxw+IxTresE0C1FQmCr OTYYhhF0+2pFBGvaXAl6RrALPdhxfhv0Id1o70BTcbFd5jOXZsLUvT7a0dbBlWdHe9FD P6oahY/iZGiF+25PketvQiZ2shl9XJBAVpwx2E9xu/Kri7YxjTPnrqLsUB5fatnJ4PH0 snqjfsc6FjZTvuczRG4CLaJKqjqPcwJY7QQeSSi5DlYbh9KcuYKIIaBN3xisz5EdUIiB MSJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eZfKEVUD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-170859-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170859-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g18-20020a1709063b1200b00a59a310e133si3920465ejf.530.2024.05.07.01.17.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 01:17:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170859-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eZfKEVUD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-170859-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170859-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E78001F21DDB for ; Tue, 7 May 2024 08:17:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90E2513C903; Tue, 7 May 2024 08:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eZfKEVUD" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F194D73530; Tue, 7 May 2024 08:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715069812; cv=none; b=Ky1gwL0shFRN2GjKEJCEa0F62ofocmfAkquWIdnMC6qBJBpiLYKDmKznUmZxmt5ej7FJE1PFzpQ5ViG7THBbN7xqC9s5oGFskZASVZj50VX8aI6jJ+2EiJb4Gtzrj6nSrYYIhaznd2lWxYrKSDm6bUgcgScoLy/DFZXJmwvNh3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715069812; c=relaxed/simple; bh=TBYk1hqbWT/AZ3S/6TKTtK/W2HY/XNM/rZYM5H7/Tz0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f1PDKM3OUZ8iXk48YTiSutjg0LiZrBGucoxZUQ0PNL7jZSiGsIPWqvOyiMmNOPwL/fnmuWYa8FL3sK2+tvfwFbqQeYG8t+vGVWXYQnE2b9WjN65RdfUqjzYQLnODyqFed0w5BOOPHe3U/Q9Sq/dZCIy61TuQTlFt45mZo9RAfvw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eZfKEVUD; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a59ce1e8609so289436766b.0; Tue, 07 May 2024 01:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715069809; x=1715674609; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=maPe74un1UQbFXNUNtNwtmyr5vBb7tDiWAcBESvmSQ4=; b=eZfKEVUDO2pNYhb12pOShKDLJ6xFGD+3thA2oRHQiwj9PI9R1XvBxBS5ZT3PQ1ptao CW3VAnetszWKGeH8tNhTqsi8GNUFHUCpAuBIBwsxQtl2S1clNFJKu5oVPW9/4eq26Ll1 9zZdBnw+vLq/PqRZXvKjgYJWaBYoBBSa+J53VJ6l5+vaup1B+vg9xxFo2z9lC9s1ssj9 hAHclsJNJsvlwo8czIZUZ90kjNg/Df0FvnHg/C27hRRz47DLvXVBGvhoH0qKo6oIQiPH R7c6ddcSodf4avEs9jBR59Djw4+U9/EWt3Id6lNpgcDrVXmfl5F6yTS5x+0igWqgtlsp TMcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715069809; x=1715674609; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=maPe74un1UQbFXNUNtNwtmyr5vBb7tDiWAcBESvmSQ4=; b=Jsnb0IHu3Ftk03kbR9UzE8pdCw3ifOrWExyrKH4aMZ6dEYtH7cZSSi8WjzR6Zlqwrb pITVf60f7Q+8UMN1QeSzdn+4x1xzXfhKT2vetbOYxBA+qV75ChrJz7gh6XoG9cF02GYA kK4piDP/bLExDuPXdMZaRyczk0n8vqrCAcVx9x9g/OsY4GUAGRbYb3QGv3wFemorYCjN T+OJoGfvWF2JqNfd7dwX21TUyX2FhFgX4tzJ6Zm6EjQWmIDZk0lvOCqdFvnJrYQ074qc 0PenpwFf8snsW09Y3niss1A6MJ8tak+lUXQyZ8ugrNlMNzBV5WxbrfLzzH0RWCkFjMaE CxCw== X-Forwarded-Encrypted: i=1; AJvYcCVBjJgwVHkzX/OP3vFql9uwemdhejc9s/n0fjPb+FT3MZSCGtiGSpsdYOrQFdADBRUJ6FtlAA8AHiJF9tzEArgdd/hlN6F5X3M6wFjl5Gt7v1sXKhWa158lED8zwVhgr5E8gzw9yCtE8Q== X-Gm-Message-State: AOJu0YyiA7/7ZpIedtOVLriHlISc+iclyOj9U8a8FS68BLW21HatGaYh Tikas9YqbnAWnLJScZRP/5oLkREG8Tuq68surIFS0nSXv8Xf975G X-Received: by 2002:a17:906:2c49:b0:a55:b67c:bd04 with SMTP id a640c23a62f3a-a59e4cbc8femr160702266b.4.1715069809147; Tue, 07 May 2024 01:16:49 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id dx3-20020a170906a84300b00a58e8d08b40sm6062079ejb.21.2024.05.07.01.16.48 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2024 01:16:48 -0700 (PDT) Date: Tue, 7 May 2024 08:16:47 +0000 From: Wei Yang To: Anshuman Khandual Cc: Wei Yang , arnd@arndb.de, rppt@kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set Message-ID: <20240507081647.2x2l7fwjnyiud6ee@master> Reply-To: Wei Yang References: <20240506012104.10864-1-richard.weiyang@gmail.com> <5f9e5d19-8a38-4e98-8cbb-e5501c76f740@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5f9e5d19-8a38-4e98-8cbb-e5501c76f740@arm.com> User-Agent: NeoMutt/20170113 (1.7.2) On Mon, May 06, 2024 at 03:30:54PM +0530, Anshuman Khandual wrote: > >On 5/6/24 06:51, Wei Yang wrote: >> 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. > >When CONFIG_ARCH_KEEP_MEMBLOCK is not set memblock information both for >normal and reserved memory get freed up but should the memblock related >code and data also be freed up as well ? Then I would also believe such If not freed, those functions would access unpredictable area. >memory saving will be very minimal given CONFIG_ARCH_KEEP_MEMBLOCK code >is too limited scoped in the tree. Not very much, it shows 12K more in it. > >Also could you please explain how it is related to CONFIG_MEMORY_HOTPLUG >config being set or not. > This is in file include/asm-generic/vmlinux.lds.h. MEM_KEEP/MEM_DISCARD is conditionally defined by CONFIG_MEMORY_HOTPLUG. So even __init_memblock is defined as __meminit when CONFIG_ARCH_KEEP_MEMBLOCK not set, it is not discarded. >> >> 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, init size increase from 2420K to 2432K. > >Is not this memory size saving some what insignificant to warrant a code >change ? Also is this problem applicable only to CONFIG_ARCH_KEEP_MEMBLOCK Yes, this is not significant. >config. Could you also provide details on how did you measure these numbers ? > Kernel print related info in mem_init_print_info(). One of is it init size, which includes init_data and init_text. >> >> Signed-off-by: Wei Yang >> --- >> include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- >> include/linux/memblock.h | 8 ++++---- >> 2 files changed, 17 insertions(+), 5 deletions(-) >> >> 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 >> -- Wei Yang Help you, Help me