From patchwork Mon Dec 1 17:05:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 810 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=1764608994; bh=D4tma5FiaUR1MP8u+xmfmf5cDqUtyCxbmzVOsA0XJsA=; 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=uIhngk/96rBKAonYj+xmi//wV1vvkuSw4OXMi1yGdUQY4No1q19ixdi8hiIbWyf1w +jVPeYnQ/mObepyXWtMZPdfCJOdzhOr/ATdxXIbqormrRFJp5vb3AHVkySp3jr5L9E zTiOKk5jJ/0Kfy7WY8PNdSFQXZKp7q60m2VSBVP6oNyT6pLfnc3hMJXi8wEr62B36a Idz7hTp3nC35s8CXy3QZovgzn3Fk10uEQueKeB4ycnCTi+Il7ILeUl83V/8lzk1gyc hC4Vpni3NsjNKkryLiRjbODG89WNX+PCxHye/9wo6F68DAhWchdaiOihStTNHo9P8+ /6OkxwYJmX2qA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E9258688AE for ; Mon, 1 Dec 2025 10:09:54 -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 FiNtooUogSsv for ; Mon, 1 Dec 2025 10:09:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608994; bh=D4tma5FiaUR1MP8u+xmfmf5cDqUtyCxbmzVOsA0XJsA=; 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=uIhngk/96rBKAonYj+xmi//wV1vvkuSw4OXMi1yGdUQY4No1q19ixdi8hiIbWyf1w +jVPeYnQ/mObepyXWtMZPdfCJOdzhOr/ATdxXIbqormrRFJp5vb3AHVkySp3jr5L9E zTiOKk5jJ/0Kfy7WY8PNdSFQXZKp7q60m2VSBVP6oNyT6pLfnc3hMJXi8wEr62B36a Idz7hTp3nC35s8CXy3QZovgzn3Fk10uEQueKeB4ycnCTi+Il7ILeUl83V/8lzk1gyc hC4Vpni3NsjNKkryLiRjbODG89WNX+PCxHye/9wo6F68DAhWchdaiOihStTNHo9P8+ /6OkxwYJmX2qA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D64946888B for ; Mon, 1 Dec 2025 10:09:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608992; bh=yqtSDOJapp+0eyZItdv9zXe0lO8OZhqUwEIl/UejDmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Opu2VVgbcsa+hu/aRVU2qp3pk8ZVhOPYqIWTiIJNAKpNRTPfRTkoR077+v7ZU2XKh 0zkMb+BiAgyEcfl8fCJ69MoNHiMV/yHlddUXPrHblsawSt4TDfSo75ihUy+usK9UmC xyIM/+d342y+hpBy2OKrQ3Sjn54gqMPeESQt5oJT/wCKnB/mXWJ/26wy1qultk0iVU E8ZMWnM/zTBvcZ9bXmTsv38m+ltDpytNEh1V6ksyJxZvOXypA88B685ISZksyijdSx e4JWaYO6Yid/QXXkDZH+907aRDvjMYukG2CnEXvBeNAvaa24CDslP5lfss4iaiXQaN Wmdr5dQgNOYhQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C6A4B68821; Mon, 1 Dec 2025 10:09:52 -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 PH1VH7g7ZBpz; Mon, 1 Dec 2025 10:09:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608990; bh=9IgR2S4Ytv33dgWDweIx4Zbc6GHcz4xyz0jqX6Tp6yY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZaQnKB8OFKZYW8NgK0Uviw1e7pvagvvGO/N460UlKZBKK+WpZE50uXNWuWM4GmWFh 6hDzquUe5j7/hoKpbo4JTkvPAH7m0cwD7ZX7h4EKEPWO8ANjDkngD1GvZ0iotse1re /mNKfP/y1+5VeZ/dnO4pgboBMflJfD6d8U81mJ5Emj6oNCwX0BPFCjI/URb+eQ22pp 18FzLeKnM42jcclEHUxksI6d30L8CGFhd4JYSw1XuVKzqeTmkPa2VOePSuTd7dBDWb ESJdJJCvZabZSHHLQ9B5z0OhtaeZrVeoI8ijimQ/fZJ7clfRLBoGnbKxRRGWpfbOBI gqhdfq57qVulQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 34704688A4; Mon, 1 Dec 2025 10:09:50 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 1 Dec 2025 10:05:15 -0700 Message-ID: <20251201170529.3237986-37-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: LX7QHR7UUIZMBPBVZUKRTYWRWSVUXG5C X-Message-ID-Hash: LX7QHR7UUIZMBPBVZUKRTYWRWSVUXG5C 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 36/37] malloc: Switch to the new malloc() implementation 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 Add CONFIG_SYS_MALLOC_LEGACY to select the current allocator and adjust the header-file and Makefile rule to use the new dlmalloc implementation. Co-developed-by: Claude Signed-off-by: Simon Glass --- Kconfig | 16 ++++++++++++++++ common/Makefile | 4 ++++ include/malloc.h | 19 +++++++------------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Kconfig b/Kconfig index c4a65597035..378ecfb1867 100644 --- a/Kconfig +++ b/Kconfig @@ -511,6 +511,22 @@ config SPL_SYS_MALLOC_SMALL If unsure, say Y to minimize SPL code size. +config SYS_MALLOC_LEGACY + bool "Use legacy dlmalloc 2.6.6 instead of dlmalloc 2.8.6" + help + Select this option to use the older dlmalloc 2.6.6 implementation + instead of the newer 2.8.6 version. The legacy allocator uses a + simpler bin system, has larger code size in most cases and uses more + static data. + + The legacy allocator may have slightly worse fragmentation behavior + for some workloads but has been well-tested over many years in U-Boot. + + This option is provided for compatibility and testing. New boards + should use the default dlmalloc 2.8.6. + + If unsure, say N to use the modern allocator. + config TOOLS_DEBUG bool "Enable debug information for tools" help diff --git a/common/Makefile b/common/Makefile index ffa46ce5e06..fdf4cff94f4 100644 --- a/common/Makefile +++ b/common/Makefile @@ -71,7 +71,11 @@ obj-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o obj-$(CONFIG_$(PHASE_)SERIAL) += console.o obj-$(CONFIG_CROS_EC) += cros_ec.o +ifdef CONFIG_SYS_MALLOC_LEGACY obj-y += dlmalloc_old.o +else +obj-y += dlmalloc.o +endif obj-$(CONFIG_$(PHASE_)SYS_MALLOC_F) += malloc_simple.o obj-$(CONFIG_$(PHASE_)CYCLIC) += cyclic.o diff --git a/include/malloc.h b/include/malloc.h index 997651e5c9c..73b2da0c383 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -1,15 +1,4 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Stub header to include the old malloc header - * - * This allows the old malloc implementation to be preserved while - * preparing for a new dlmalloc version. - */ - -#include - -#if 0 /* not active yet */ - /* Default header file for malloc-2.8.x, written by Doug Lea and released to the public domain, as explained at @@ -32,6 +21,12 @@ * If MSPACES is defined, declarations for mspace versions are included. */ +#ifdef CONFIG_SYS_MALLOC_LEGACY + +#include + +#else + #ifndef MALLOC_280_H #define MALLOC_280_H @@ -748,4 +743,4 @@ int initf_malloc(void); #endif /* MALLOC_280_H */ -#endif /* not active yet */ +#endif /* !CONFIG_SYS_MALLOC_LEGACY */