[PATCH v2 03/10] tlsf: support on-demand requesting memory from external store

Sascha Hauer s.hauer at pengutronix.de
Tue Oct 7 06:42:57 PDT 2025


On Mon, Oct 06, 2025 at 08:59:48PM -0400, chalianis1 at gmail.com wrote:
> From: Chali Anis <chalianis1 at gmail.com>
> 
> barebox running under an operating system (or nearly one like UEFI) does
> not have control over all the memory and should not hog too much memory
> upfront as that can interfere with other applications, e.g. EFI drivers
> or the EFI firmware itself.
> 
> To accommodate this use case, allow TLSF to dynamically request more
> memory from an external store via tlsf_register_store().
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
> Signed-off-by: Chali Anis <chalianis1 at gmail.com>
> ---
>  common/tlsf.c  | 29 ++++++++++++++++++++++++++++-
>  include/tlsf.h |  1 +
>  2 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/common/tlsf.c b/common/tlsf.c
> index 4ee53a9b2f20..636b57b1c642 100644
> --- a/common/tlsf.c
> +++ b/common/tlsf.c
> @@ -159,6 +159,9 @@ typedef struct control_t
>  	/* Empty lists point at this block to indicate they are free. */
>  	block_header_t block_null;
>  
> +	void (*request_store)(tlsf_t, size_t);
> +
> +

This breaks compilation on 32bit platforms.

The reason is we have this directly under the definition of control_t:

tlsf_static_assert(sizeof(control_t) % ALIGN_SIZE == 0);

I fixed it up as follows.

It looks odd to me that we have to manually align the struct size each
time we add a field to this struct. Isn't there something better?

Sascha

---------------------------8<------------------------------
>From 11fcc69bbc41954d5e28a3b082dc39171bd6cdc0 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Tue, 7 Oct 2025 15:39:38 +0200
Subject: [PATCH] fixup! tlsf: support on-demand requesting memory from
 external store

---
 common/tlsf.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/common/tlsf.c b/common/tlsf.c
index 636b57b1c6..c4ba8259b2 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -161,11 +161,9 @@ typedef struct control_t
 
 	void (*request_store)(tlsf_t, size_t);
 
-
 	/* Bitmaps for free lists. */
 	unsigned int fl_bitmap;
 	unsigned int sl_bitmap[FL_INDEX_COUNT];
-	u32 : BYTES_TO_BITS(ALIGN_SIZE - sizeof(size_t));
 
 	/* Head of free lists. */
 	block_header_t* blocks[FL_INDEX_COUNT][SL_INDEX_COUNT];
-- 
2.47.3


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list