From patchwork Tue Aug 8 22:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1819077 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.a=rsa-sha256 header.s=selector1 header.b=wfxQv6Vk; dkim=pass (2048-bit key) header.d=seco.com header.i=@seco.com header.a=rsa-sha256 header.s=selector1 header.b=wfxQv6Vk; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RL7mR24QYz1yfB for ; Wed, 9 Aug 2023 08:54:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 977BE8683A; Wed, 9 Aug 2023 00:53:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="wfxQv6Vk"; dkim=pass (2048-bit key) header.d=seco.com header.i=@seco.com header.b="wfxQv6Vk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B55086688; Wed, 9 Aug 2023 00:53:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20615.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::615]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 167C686672 for ; Wed, 9 Aug 2023 00:53:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rs15dwgzax/AgSExzFL2rZkJFx8N5DkEmMNAse43PaM=; b=wfxQv6VkuEwldXbCN7AcITfLU4GYMwn6TXY6K3je2vmnxue0JGW6UrOVDJSx+z+SUINeYOB1iAH3uGWvKN5osT0OVzdLZQ68DPlLA0446VjYbPdiYZvRIAlMN3xMmQtKariqqWxg/Qt+eeqfk+xQSg/U+xLlfNrWkbYkHDv9jrfKF+E6k7Q7UZ9B3f34lXGHavDRsdQlPxXG9ZYo3oQogiDIbs3Xj+S503qgeZMVbnYL8dh218VwqD+Gfd8W++ZdWmm+4ZEqPasOhJNBXlUYrTf/1SPiMQTtXh2CvQWoKXbjATd1fXgnZ1pu/BxbMftQeqsWbmxw7Oj3H1Zjb4k7iQ== Received: from DUZPR01CA0323.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::24) by AS8PR03MB7570.eurprd03.prod.outlook.com (2603:10a6:20b:349::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.27; Tue, 8 Aug 2023 22:53:45 +0000 Received: from DB8EUR05FT042.eop-eur05.prod.protection.outlook.com (2603:10a6:10:4ba:cafe::a8) by DUZPR01CA0323.outlook.office365.com (2603:10a6:10:4ba::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28 via Frontend Transport; Tue, 8 Aug 2023 22:53:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 20.160.56.86) smtp.mailfrom=seco.com; dkim=pass (signature was verified) header.d=seco.com;dmarc=pass action=none header.from=seco.com; Received-SPF: Pass (protection.outlook.com: domain of seco.com designates 20.160.56.86 as permitted sender) receiver=protection.outlook.com; client-ip=20.160.56.86; helo=inpost-eu.tmcas.trendmicro.com; pr=C Received: from inpost-eu.tmcas.trendmicro.com (20.160.56.86) by DB8EUR05FT042.mail.protection.outlook.com (10.233.239.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.18 via Frontend Transport; Tue, 8 Aug 2023 22:53:44 +0000 Received: from outmta (unknown [192.168.82.135]) by inpost-eu.tmcas.trendmicro.com (Trend Micro CAS) with ESMTP id 507A720086FA0; Tue, 8 Aug 2023 22:53:44 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [104.47.14.57]) by repre.tmcas.trendmicro.com (Trend Micro CAS) with ESMTPS id 8A4672008006E; Tue, 8 Aug 2023 22:53:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SmNm5l0ETyKeIpPlIYdkvcthm4ouWCM5JvVAMPuKae2Ts3mNXBnshG2VwZCPh8qWhRcg7PD10VAXzGkTXIe1xdJYNu9fNdywaHVL1n/T1NygnYQ05yBTcp7oZOGhDX65WtZqJDFkEs/afA8Svz/kUNVbS6SPP8RL2Zlx29SOCOriG22H4ocpjCYerSyYtXNVC6xvgLCi+KGxAiTln173Bp8myngE2L95uGQpBeJq7abJ4ZLbP3Nd2rztOT2A23f+TsWYGjTVphxoqQvag3FbmQYpES7KF9sWYWObwzx9jiqMCwHdnEbl8knRaTtlcxb9IWA7aCiPGQwjXWpNhMWCuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Rs15dwgzax/AgSExzFL2rZkJFx8N5DkEmMNAse43PaM=; b=a63+UHk67hNTfnsWKEmuIaPo4DklWYp6ADEbSOKL6G/VsXxVaB3B/R0FR8C9uODQ/T1+teGQa4X8tfhtfruUgxS1o9GYILS6saxxZDFhb/fXBDU4vevxxSO0o+8H51pokrr0sy698v09++I2ZRn6wHoeBhVTn7+nd3dQuoA+R/22bv0TKHLoS0BEU6h5ZyoY8D9R+LjyyWtxC5SMONncKDZI34SvGki6+X2BUcmwMy6e1SBKOJmHKu7B+FF5JitbyWIodhI9N2ljuTx6BWTKjrMD1L6QLosuQMAOW+8gV1kkCaGqatGhJ8J1e6guKlp8wxPyDflfn6rLSlV8fkbqnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rs15dwgzax/AgSExzFL2rZkJFx8N5DkEmMNAse43PaM=; b=wfxQv6VkuEwldXbCN7AcITfLU4GYMwn6TXY6K3je2vmnxue0JGW6UrOVDJSx+z+SUINeYOB1iAH3uGWvKN5osT0OVzdLZQ68DPlLA0446VjYbPdiYZvRIAlMN3xMmQtKariqqWxg/Qt+eeqfk+xQSg/U+xLlfNrWkbYkHDv9jrfKF+E6k7Q7UZ9B3f34lXGHavDRsdQlPxXG9ZYo3oQogiDIbs3Xj+S503qgeZMVbnYL8dh218VwqD+Gfd8W++ZdWmm+4ZEqPasOhJNBXlUYrTf/1SPiMQTtXh2CvQWoKXbjATd1fXgnZ1pu/BxbMftQeqsWbmxw7Oj3H1Zjb4k7iQ== Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) by PR3PR03MB6634.eurprd03.prod.outlook.com (2603:10a6:102:7d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.27; Tue, 8 Aug 2023 22:53:35 +0000 Received: from DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::65d7:d7d8:711b:2514]) by DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::65d7:d7d8:711b:2514%5]) with mapi id 15.20.6652.025; Tue, 8 Aug 2023 22:53:35 +0000 From: Sean Anderson To: Tom Rini , u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson Subject: [PATCH v2 3/4] malloc: Don't statically initialize av_ if using malloc_init Date: Tue, 8 Aug 2023 18:53:19 -0400 Message-Id: <20230808225320.310926-4-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230808225320.310926-1-sean.anderson@seco.com> References: <20230808225320.310926-1-sean.anderson@seco.com> X-ClientProxiedBy: MN2PR05CA0036.namprd05.prod.outlook.com (2603:10b6:208:c0::49) To DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DB9PR03MB8847:EE_|PR3PR03MB6634:EE_|DB8EUR05FT042:EE_|AS8PR03MB7570:EE_ X-MS-Office365-Filtering-Correlation-Id: 342f56a4-3604-46c1-284d-08db986251c5 X-TrendMicro-CAS-OUT-LOOP-IDENTIFIER: 656f966764b7fb185830381c646b41a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: jMzpvFXuVyA4Ij8seDyAlS8Q2/PEUBvhrFTe/FR0X5HIcLYFo9XJottxG7FN7X0Czo3FnYHaa1TGEubUdNgwYc2dCWmPwy2SjpKStQ0OkIvx6X8yeWmA9QhHgYubYo18/GemUPg/mP2oPzqH21NMjVnnNDj0EHQLeHaqCWRucVPXe3jCSk87S58Ic3TiXZrffCd9YelJ1nKU8/GNaY3zOmHY0pPLlLfTKvr6PUkha90scq/jv1c4gXc+8KxQej+o+DII1kCEtEH9Ccw+bvBHZoAt+KS4ZifBYFVrw0oF06WjQ50YG4JCgJFpwIlLF+mhDnBoUE1BLX0oF/pSAH/h1FTBNVhdBIHovn90rE1gxCbOII9oz8gGysFzE3mrnx08EKjXeaRWcV8UdcE7INrl4Ksdi8wvNuc3yrpe77xfrpEVSIhj/NLX+FOzHNPBsI5Bovv9r+CdUETu30xRmRylgMYbi4aCXoren8dHefIloPpsssZ2DtQoLGR5CuHqO7LMvQ7J6i99KUDc3odA4UBPuppirzTswNbvdKiYn94H6eTzUi5ZeUqW5ZvuLkfhnufqPOt+eJjFI0RS54Vr+UYm6ZVn5c0bkzej7SUtCmhrMYihVprHegiOi+AyHMbkzn/Y X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR03MB8847.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(346002)(366004)(39850400004)(396003)(136003)(376002)(186006)(1800799006)(451199021)(2616005)(36756003)(1076003)(26005)(52116002)(6506007)(107886003)(6486002)(6512007)(6666004)(478600001)(38350700002)(38100700002)(54906003)(66476007)(66946007)(66556008)(4326008)(316002)(41300700001)(8936002)(5660300002)(44832011)(8676002)(2906002)(83380400001)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR03MB6634 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB8EUR05FT042.eop-eur05.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 35c271f7-fa4a-410c-2e45-08db98624c21 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1VbbsNJJKsfgffzUywSZQdsmksw47veVfc3Gs3VVOFJUIbbByGaLQmHuXJGdwZCPCRQjM3IiW5wm2kBuPVOOEuKtmETtXFFKtE8fo7Pg2XWFwU/fgdOnWorhBOPqWcq+/dASXzhM6Q0m6cbhY6zSiK9LBIORZrwWkXQN/wQYZmmauzuSwR5RQNJhRvli5sfykuU5UxzAr7T0oW5VHtRNO0K8k63Bi9NcAMMdI01WrthsNeOO2FdLe0WaMEX7lfYsR6D9KcLVQJyPoO7E9inzM1XsYWMtvEXhFP5O7At+DJZCaLEZhEdNg63E0Q3oyQqnfby7GXi+YZSpeeCdb3XWeI1T8pjwaBPSmXZvXwecXZfLmVQrWlQEXkU0tiJXLcaMcJV3kmaTW5W1/oZyMhOu+X5bHLBkXfzAcOzAeavUgYJEKDJc4Pp+8CIo49iqCTA6oCTJpqGbMUDXVeBF7w1z+7poJ72wRRUG+s4MTACNFvCFxXMI4nVcebXAVNUOS+EdL1Nv1O3/KtTcti+Ra7viEyeqjvxDYwc3y4GBIjLjjxE7tpG3gurolKGewcMLnJKndfBP5P9qDLKSuYAWbMWhDq1bV+UTAkDWTdx5p53lwqRv+0QjCrUCZK1rSqzi5UM5XODghVwvn56yf5BQIhi/lO5qyStqngaNUJuW4R0cufE4wKO1TS/lPwg98Nr65Z0OInMB4jjwXsr3wn8z02RHkFOAe+bbWPWEpj303ztzKTOEM7DLB0nEmNkcGNOzV7YSMTA58bglmvpJ+BvifvVw4w== X-Forefront-Antispam-Report: CIP:20.160.56.86; CTRY:NL; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:inpost-eu.tmcas.trendmicro.com; PTR:inpost-eu.tmcas.trendmicro.com; CAT:NONE; SFS:(13230028)(376002)(396003)(39850400004)(136003)(346002)(82310400008)(451199021)(186006)(1800799006)(46966006)(36840700001)(40470700004)(8676002)(8936002)(5660300002)(70586007)(316002)(4326008)(6666004)(40480700001)(70206006)(2906002)(44832011)(41300700001)(54906003)(40460700003)(478600001)(6486002)(6512007)(36756003)(83380400001)(336012)(26005)(1076003)(6506007)(107886003)(2616005)(47076005)(86362001)(36860700001)(7636003)(356005)(34070700002)(7596003)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2023 22:53:44.8524 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 342f56a4-3604-46c1-284d-08db986251c5 X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=bebe97c3-6438-442e-ade3-ff17aa50e733; Ip=[20.160.56.86]; Helo=[inpost-eu.tmcas.trendmicro.com] X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT042.eop-eur05.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7570 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean When we enable malloc_init, there is no need to statically initialize av_, since we are going to do it manually. This lets us move av_ to .bss, saving around 1-2k of data (depending on the pointer size). cALLOc must be adjusted to not access top before malloc_init. While we're at it, rename/reword the Kconfig to better describe what this option does. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Fix cALLOc condition Kconfig | 18 +++++++----------- common/dlmalloc.c | 9 +++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Kconfig b/Kconfig index 70efb41cc66..4b32286b69d 100644 --- a/Kconfig +++ b/Kconfig @@ -372,18 +372,14 @@ if EXPERT When disabling this, please check if malloc calls, maybe should be replaced by calloc - if one expects zeroed memory. -config SYS_MALLOC_DEFAULT_TO_INIT - bool "Default malloc to init while reserving the memory for it" +config SYS_MALLOC_RUNTIME_INIT + bool "Initialize malloc's internal data at runtime" help - It may happen that one needs to move the dynamic allocation - from one to another memory range, eg. when moving the malloc - from the limited static to a potentially large dynamic (DDR) - memory. - - If so then on top of setting the updated memory aside one - needs to bring the malloc init. - - If such a scenario is sought choose yes. + Initialize malloc's internal data structures at runtime, rather than + at compile-time. This is necessary if relocating the malloc arena + from a smaller static memory to a large DDR memory. It can also + reduce the size of U-Boot by letting malloc's data reside in .bss + instead of .data. config TOOLS_DEBUG bool "Enable debug information for tools" diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 30c78ae976b..0985fd8de2a 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -556,6 +556,7 @@ typedef struct malloc_chunk* mbinptr; #define IAV(i) bin_at(i), bin_at(i) static mbinptr av_[NAV * 2 + 2] = { +#if !CONFIG_IS_ENABLED(SYS_MALLOC_RUNTIME_INIT) NULL, NULL, IAV(0), IAV(1), IAV(2), IAV(3), IAV(4), IAV(5), IAV(6), IAV(7), IAV(8), IAV(9), IAV(10), IAV(11), IAV(12), IAV(13), IAV(14), IAV(15), @@ -573,6 +574,7 @@ static mbinptr av_[NAV * 2 + 2] = { IAV(104), IAV(105), IAV(106), IAV(107), IAV(108), IAV(109), IAV(110), IAV(111), IAV(112), IAV(113), IAV(114), IAV(115), IAV(116), IAV(117), IAV(118), IAV(119), IAV(120), IAV(121), IAV(122), IAV(123), IAV(124), IAV(125), IAV(126), IAV(127) +#endif }; #ifdef CONFIG_NEEDS_MANUAL_RELOC @@ -623,7 +625,7 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_end = start + size; mem_malloc_brk = start; - if (CONFIG_IS_ENABLED(SYS_MALLOC_DEFAULT_TO_INIT)) + if (CONFIG_IS_ENABLED(SYS_MALLOC_RUNTIME_INIT)) malloc_init(); debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start, @@ -2151,7 +2153,10 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; #ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT #if MORECORE_CLEARS mchunkptr oldtop = top; - INTERNAL_SIZE_T oldtopsize = chunksize(top); + INTERNAL_SIZE_T oldtopsize; + if (!CONFIG_VAL(SYS_MALLOC_F_LEN) || + (gd->flags & GD_FLG_FULL_MALLOC_INIT)) + oldtopsize = chunksize(top); #endif #endif Void_t* mem = mALLOc (sz);