OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gregor Haas <gregorhaas1997@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v3 2/3] lib: sbi: Allocate from beginning of heap blocks
Date: Wed,  7 Aug 2024 11:17:18 -0700	[thread overview]
Message-ID: <20240807181719.244099-3-gregorhaas1997@gmail.com> (raw)
In-Reply-To: <20240807181719.244099-1-gregorhaas1997@gmail.com>

In the next commit, we'll add a new sbi_memalign() function. In order to
allocate aligned memory, we'll sometimes need to allocate from the middle of a
heap block, effectively splitting it in two. Allocating from the beginning of a
heap block in the nonaligned case more closely matches this behavior, reducing
the complexity of understanding the heap implementation.

Signed-off-by: Gregor Haas <gregorhaas1997@gmail.com>
---
 lib/sbi/sbi_heap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/sbi/sbi_heap.c b/lib/sbi/sbi_heap.c
index e43d77c..cc4893d 100644
--- a/lib/sbi/sbi_heap.c
+++ b/lib/sbi/sbi_heap.c
@@ -63,8 +63,9 @@ void *sbi_malloc_from(struct sbi_heap_control *hpctrl, size_t size)
 			n = sbi_list_first_entry(&hpctrl->free_node_list,
 						 struct heap_node, head);
 			sbi_list_del(&n->head);
-			n->addr = np->addr + np->size - size;
+			n->addr = np->addr;
 			n->size = size;
+			np->addr += size;
 			np->size -= size;
 			sbi_list_add_tail(&n->head, &hpctrl->used_space_list);
 			ret = (void *)n->addr;
-- 
2.45.2



  parent reply	other threads:[~2024-08-07 18:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 18:17 [PATCH v3 0/3] lib: sbi: Heap improvements for SMMTT Gregor Haas
2024-08-07 18:17 ` [PATCH v3 1/3] lib: sbi: Support multiple heaps Gregor Haas
2024-08-08  5:34   ` Anup Patel
2024-08-07 18:17 ` Gregor Haas [this message]
2024-08-08  5:33   ` [PATCH v3 2/3] lib: sbi: Allocate from beginning of heap blocks Anup Patel
2024-08-07 18:17 ` [PATCH v3 3/3] lib: sbi: Implement aligned memory allocators Gregor Haas
2024-08-08  5:33   ` Anup Patel
2024-08-08 17:47     ` Gregor Haas
2024-08-08 17:49       ` Jessica Clarke
2024-08-09  3:03       ` Anup Patel

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=20240807181719.244099-3-gregorhaas1997@gmail.com \
    --to=gregorhaas1997@gmail.com \
    --cc=opensbi@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