Browse Source

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>
pull/92793/head
Krzysztof Sychla 2 weeks ago committed by Daniel DeGrasse
parent
commit
a51d3c0f74
  1. 2
      lib/heap/heap.h
  2. 4
      samples/basic/sys_heap/sample.yaml

2
lib/heap/heap.h

@ -255,7 +255,7 @@ static inline chunksz_t min_chunk_size(struct z_heap *h)
static inline size_t chunksz_to_bytes(struct z_heap *h, chunksz_t chunksz_in) static inline size_t chunksz_to_bytes(struct z_heap *h, chunksz_t chunksz_in)
{ {
return chunksz_in * CHUNK_UNIT - chunk_header_bytes(h); return chunksz_in * CHUNK_UNIT;
} }
static inline int bucket_idx(struct z_heap *h, chunksz_t sz) static inline int bucket_idx(struct z_heap *h, chunksz_t sz)

4
samples/basic/sys_heap/sample.yaml

@ -9,8 +9,8 @@ common:
type: multi_line type: multi_line
ordered: true ordered: true
regex: regex:
- ".*allocated 15.,.*" - ".*allocated 16.,.*"
- ".*allocated 10.,.*" - ".*allocated 1..,.*"
- ".*allocated 0, free ..., max allocated ..., heap size 256.*" - ".*allocated 0, free ..., max allocated ..., heap size 256.*"
tests: tests:
sample.basic.sys_heap: sample.basic.sys_heap:

Loading…
Cancel
Save