From: chalianis1@gmail.com
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Chali Anis <chalianis1@gmail.com>,
Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v2 03/10] tlsf: support on-demand requesting memory from external store
Date: Mon, 6 Oct 2025 20:59:48 -0400 [thread overview]
Message-ID: <20251007005955.1427990-3-chalianis1@gmail.com> (raw)
In-Reply-To: <20251007005955.1427990-1-chalianis1@gmail.com>
From: Chali Anis <chalianis1@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@barebox.org>
Signed-off-by: Chali Anis <chalianis1@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);
+
+
/* Bitmaps for free lists. */
unsigned int fl_bitmap;
unsigned int sl_bitmap[FL_INDEX_COUNT];
@@ -568,7 +571,7 @@ static block_header_t* block_trim_free_leading(control_t* control, block_header_
return remaining_block;
}
-static block_header_t* block_locate_free(control_t* control, size_t size)
+static block_header_t* __block_locate_free(control_t* control, size_t size)
{
int fl = 0, sl = 0;
block_header_t* block = 0;
@@ -598,6 +601,23 @@ static block_header_t* block_locate_free(control_t* control, size_t size)
return block;
}
+static block_header_t* block_locate_free(control_t* control, size_t size)
+{
+ block_header_t *block;
+
+ block = __block_locate_free(control, size);
+ if (block)
+ return block;
+
+ if (!control->request_store || !size)
+ return NULL;
+
+ control->request_store(tlsf_cast(tlsf_t, control),
+ size + tlsf_pool_overhead());
+
+ return __block_locate_free(control, size);
+}
+
static void* block_prepare_used(control_t* control, block_header_t* block,
size_t size, size_t used)
{
@@ -934,6 +954,13 @@ tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
return tlsf;
}
+void tlsf_register_store(tlsf_t tlsf, void (*cb)(tlsf_t tlsf, size_t bytes))
+{
+ control_t* control = tlsf_cast(control_t*, tlsf);
+
+ control->request_store = cb;
+}
+
void tlsf_destroy(tlsf_t tlsf)
{
/* Nothing to do. */
diff --git a/include/tlsf.h b/include/tlsf.h
index e0dcdac1e7ab..ea86b0600c49 100644
--- a/include/tlsf.h
+++ b/include/tlsf.h
@@ -63,6 +63,7 @@ tlsf_t tlsf_create(void* mem);
tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
void tlsf_destroy(tlsf_t tlsf);
pool_t tlsf_get_pool(tlsf_t tlsf);
+void tlsf_register_store(tlsf_t tlsf, void (*cb)(tlsf_t tlsf, size_t bytes));
/* Add/remove memory pools. */
pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
--
2.34.1
next prev parent reply other threads:[~2025-10-07 1:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-07 0:59 [PATCH v2 01/10] efi: payload: split out payload Kconfig symbols chalianis1
2025-10-07 0:59 ` [PATCH v2 02/10] tlsf: move kasan_poison_shadow into tlsf_add_pool chalianis1
2025-10-07 0:59 ` chalianis1 [this message]
2025-10-07 0:59 ` [PATCH v2 04/10] efi: payload: add support for EFI initrd media protocol chalianis1
2025-10-07 0:59 ` [PATCH v2 05/10] efi: payload: earlymem: allocate only the barebox needs in term of memory chalianis1
2025-10-07 0:59 ` [PATCH v2 06/10] efi: payload: split image handling from legacy handover boot and add linux x86 image filetype chalianis1
2025-10-07 0:59 ` [PATCH v2 07/10] efi: payload: bootm: add support for efi stub boot chalianis1
2025-10-07 0:59 ` [PATCH v2 08/10] efi: payload: bootm: add support for fit image chalianis1
2025-10-07 0:59 ` [PATCH v2 09/10] efi: payload: make selectable without COMPILE_TEST chalianis1
2025-10-07 0:59 ` [PATCH v2 10/10] ARM: efi: add a generic defconfig for v8 efi payload chalianis1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251007005955.1427990-3-chalianis1@gmail.com \
--to=chalianis1@gmail.com \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox