Skip to content

Commit a51d3c0

Browse files
ksychladanieldegrasse
authored andcommitted
kernel: heap: Add allocation metadata to allocated_bytes
The allocated_bytes were missing the allocation metadata. Because of that the sum of free_bytes and allocated_bytes doesn't remain constant after each allocation. This convention doesn't match glibc's behavior. This commit changes the chunksz_to_bytes function to include the metadata in the calculation. The analysis of the mallinfo2 function from glibc has been done in #92392 Pull Request. Signed-off-by: Krzysztof Sychla <ksychla@antmicro.com>
1 parent b478cd8 commit a51d3c0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/heap/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static inline chunksz_t min_chunk_size(struct z_heap *h)
255255

256256
static inline size_t chunksz_to_bytes(struct z_heap *h, chunksz_t chunksz_in)
257257
{
258-
return chunksz_in * CHUNK_UNIT - chunk_header_bytes(h);
258+
return chunksz_in * CHUNK_UNIT;
259259
}
260260

261261
static inline int bucket_idx(struct z_heap *h, chunksz_t sz)

samples/basic/sys_heap/sample.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ common:
99
type: multi_line
1010
ordered: true
1111
regex:
12-
- ".*allocated 15.,.*"
13-
- ".*allocated 10.,.*"
12+
- ".*allocated 16.,.*"
13+
- ".*allocated 1..,.*"
1414
- ".*allocated 0, free ..., max allocated ..., heap size 256.*"
1515
tests:
1616
sample.basic.sys_heap:

0 commit comments

Comments
 (0)