From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] fixup! tlsf: support on-demand requesting memory from external store
Date: Wed, 15 Oct 2025 10:26:39 +0200 [thread overview]
Message-ID: <20251015082640.4093689-1-a.fatoum@barebox.org> (raw)
tlsf: fix misaccounting in request_store feature
A TLSF pool itself has overhead in the form of tlsf_pool_overhead()
that's distinct from the struct pool_entry. Adding a helper that returns
this total overhead allows us also to use roundup_pow_of_two(), which
previously issues a warning on clang about sizeof(sizeof(...)) looking
strange.
Another issues is that request_store was not explicitly zeroed leading
to issues on OOM situations, which is remedied as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/tlsf.c | 1 +
common/tlsf_malloc.c | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/common/tlsf.c b/common/tlsf.c
index 3c72b41c0385..e7f1b8354f02 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -654,6 +654,7 @@ static void control_construct(control_t* control)
control->block_null.next_free = &control->block_null;
control->block_null.prev_free = &control->block_null;
+ control->request_store = NULL;
control->fl_bitmap = 0;
for (i = 0; i < FL_INDEX_COUNT; ++i)
{
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index d3b665a2fc40..9d55014117f0 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -27,6 +27,11 @@ struct pool_entry {
static LIST_HEAD(mem_pool_list);
+static inline size_t mem_pool_overhead(void)
+{
+ return sizeof(struct pool_entry) + tlsf_pool_overhead();
+}
+
void *malloc(size_t bytes)
{
void *mem;
@@ -132,7 +137,7 @@ static void tlsf_request_store(tlsf_t tlsf, size_t bytes)
{
size_t size;
- size = __roundup_pow_of_two(bytes + sizeof(struct pool_entry));
+ size = roundup_pow_of_two(bytes + mem_pool_overhead());
malloc_request_store(max_t(size_t, SZ_8M, size));
}
--
2.47.3
next reply other threads:[~2025-10-15 8:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 8:26 Ahmad Fatoum [this message]
2025-10-20 11:04 ` Sascha Hauer
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=20251015082640.4093689-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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