From patchwork Mon Dec 1 17:05:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 805 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608981; bh=2YTxqLji9d/utAwbdwJB6VHwxGXCZxLfjjUzJ7NDTtc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=eFkO8sZxi+pwqRB2vpz6JRxyl58STK8XgVOuaBHCPz71GmwwPM9dx7I+WPSMyxdIf fxU9szHl0HasP4i57npovtpC6WUM24tofH6+QuI8zcz5PO93x3bduSRSLKDL6/dh5c oEWcS/OU3Iz1pd6tAD/s2yGaKZ884+g/+fuRHg0/dwpHuN82Y2GfwRrQ8zpPOp8M0J 6C5WvONoaZiCFG8GxVcuw4GTq2kXMINcUubjKhAGxKUgR+4g3jWtq7EYO6TkG9Lsaq IqPUZSALGovv8GJltM3YjP3WX0NrcwcG30EWrjts5q73QEnjgPLWQSE2PYf1c9TOyD hbvfHmCPFYtww== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 81BE5688AE for ; Mon, 1 Dec 2025 10:09:41 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id IvB45m3MeZtL for ; Mon, 1 Dec 2025 10:09:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608981; bh=2YTxqLji9d/utAwbdwJB6VHwxGXCZxLfjjUzJ7NDTtc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=eFkO8sZxi+pwqRB2vpz6JRxyl58STK8XgVOuaBHCPz71GmwwPM9dx7I+WPSMyxdIf fxU9szHl0HasP4i57npovtpC6WUM24tofH6+QuI8zcz5PO93x3bduSRSLKDL6/dh5c oEWcS/OU3Iz1pd6tAD/s2yGaKZ884+g/+fuRHg0/dwpHuN82Y2GfwRrQ8zpPOp8M0J 6C5WvONoaZiCFG8GxVcuw4GTq2kXMINcUubjKhAGxKUgR+4g3jWtq7EYO6TkG9Lsaq IqPUZSALGovv8GJltM3YjP3WX0NrcwcG30EWrjts5q73QEnjgPLWQSE2PYf1c9TOyD hbvfHmCPFYtww== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6FB54688B6 for ; Mon, 1 Dec 2025 10:09:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608979; bh=fs1xWKmGF5YzEiTrS1Lw5yq8Qx4NwSWoXxXMR4LKSKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v1fnSQX0C2DANcDIHsZalPLxVln6D9ry2p4Fe7IdC7Ssj6F4KsEWKapyGn1/P38ZO ZjeKCk9orSseZz+k2GtsPIdQ9vdiAxBCdUoVtJBY+F51M1QNGRL9FG0pleAOGqk5hq 5grCIQ4rwsr7SUpRTariPp6Fd9fDlRnRXbp5hd5VxulLyZHhr1TuQ4kVJEs/d46RxY jXt5+Mj6ixSdJtbmMgILx6mc3glbYB6gv+IOYry6BK58C0t+yhuJAFW4xfYYwuuyYA lCzeUB1kvLZtAKKBYSAdaweGZaOi2eRgfpalfAFbcstBM7eG3bUMaCJwLWa62x9IzS uml7HsITaNkjg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4B5C66888B; Mon, 1 Dec 2025 10:09:39 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 67dexbwuiAWu; Mon, 1 Dec 2025 10:09:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608973; bh=W+z5D1NrWdPRVJZTRpg1pPiBbiY79YZCs6ItD9yeMtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTj/iqk9Ayaf/CjMY1lKQNB1TSYgS8LgRXhjyw6cGdPT3nIgxz+JRkGzAoeiLPyrn dfGG+wKRD1iiuExlf6dfQDlz4JBOqGy9ESy8L2/OJUnwHQqzo5VMPLIZLAw/r3Yoe+ 1naF+ka+ThiqmvHE54Nm+AsH+GEUWEMVfx6aW/MZUFlopV/mIXokC6sEEs9bPfBopZ XAwcIkAvQ66xgO6Vt0fivB3iuRF3phl5KWEeChxd0Nc04BDz6OJTBGcH4RsumvnTui nEyfbyLdEWcL8LN0ztqloBO25CNy5pKY0W4qHe1+ALzWuU5W+z1hAwTFJh8dQ/oZIh KU2Z8m+jj6V2A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 308CE688AE; Mon, 1 Dec 2025 10:09:33 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 1 Dec 2025 10:05:09 -0700 Message-ID: <20251201170529.3237986-31-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201170529.3237986-1-sjg@u-boot.org> References: <20251201170529.3237986-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JIARNWKNANWOGOGO77JE27SMN4XKKWEV X-Message-ID-Hash: JIARNWKNANWOGOGO77JE27SMN4XKKWEV X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 30/37] malloc: Add a way to control the size of dlmalloc List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass There are quite a few options available which can reduce code size. Most of them only make sense in SPL. Add a Kconfig option to enable a smaller dlmalloc for U-Boot proper and SPL. Signed-off-by: Simon Glass --- Kconfig | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Kconfig b/Kconfig index 357f027cc97..c4a65597035 100644 --- a/Kconfig +++ b/Kconfig @@ -464,6 +464,53 @@ config SYS_MALLOC_DEFAULT_TO_INIT If such a scenario is sought choose yes. +config SYS_MALLOC_SMALL + bool "Optimise malloc for code size" + help + Enable code-size optimisations for dlmalloc. This: + + - Disables tree bins for allocations >= 256 bytes, using simple + linked-list bins instead. This changes large-allocation performance + from O(log n) to O(n) but saves ~1.5-2KB. + + - Simplifies memalign() by removing fallback retry logic that attempts + multiple allocation strategies when initial over-allocation fails. + This saves ~100-150 bytes. + + - Disables in-place realloc optimisation, which resizes allocations + without copying if space permits. This saves ~200 bytes. + + - Uses static malloc parameters instead of runtime-configurable ones. + + These optimisations may increase fragmentation and reduce performance + for workloads with many large or aligned allocations, but are suitable + for most U-Boot use cases where code size is more important. + + If unsure, say N. + +config SPL_SYS_MALLOC_SMALL + bool "Optimise malloc for code size in SPL" + depends on SPL && !SPL_SYS_MALLOC_SIMPLE + default y + help + Enable code-size optimisations for dlmalloc in SPL. This: + + - Disables tree bins for allocations >= 256 bytes, using simple + linked-list bins instead. This changes large-allocation performance + from O(log n) to O(n) but saves ~1.5-2KB. + + - Simplifies memalign() by removing fallback retry logic. This saves + ~100-150 bytes. + + - Disables in-place realloc optimisation. This saves ~200 bytes. + + - Uses static malloc parameters instead of runtime-configurable ones. + + SPL typically has predictable memory usage where these optimisations + have minimal impact, making the code size savings worthwhile. + + If unsure, say Y to minimize SPL code size. + config TOOLS_DEBUG bool "Enable debug information for tools" help