Skip to content

Commit fcdd283

Browse files
committed
update memory stats info
1 parent 2a8c7bd commit fcdd283

5 files changed

Lines changed: 45 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 2a8c7bd6d72bb355b9f3da45977664f31021925b
2+
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
3+
Date: Wed Feb 4 21:27:55 2026 +0700
4+
5+
update version
6+
17
commit 7104d72733c07ec0806dc54d9344eb072b68fa7e
28
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
39
Date: Wed Feb 4 21:27:29 2026 +0700

src/kernel/kernel/kernel.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ char** get_args(char* input) {
6262
arg_counter++;
6363
}
6464

65-
kfree(token);
66-
6765
return args;
6866
}
6967

src/kernel/kklibc/kklibc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
#include "stdio.h"
99
#include "stdlib.h"
1010

11-
#define VERSION "v0.3.0a-4-main 7104d72"
11+
#define VERSION "v0.3.0a-5-main 2a8c7bd"
1212

1313
#endif

src/kernel/kklibc/mem.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ u32 free_mem_addr = HEAP_START;
1717
static mem_block_t* free_blocks = NULL;
1818
u32 heap_current_end = HEAP_START + HEAP_SIZE;
1919

20+
static meminfo_t stats;
21+
2022
// инициализация кучи
2123
void heap_init() {
2224
free_blocks = (mem_block_t*)HEAP_START;
2325
free_blocks->size = HEAP_SIZE - sizeof(mem_block_t);
2426
free_blocks->next = NULL;
2527
free_blocks->is_free = 1;
2628
heap_current_end = HEAP_START + HEAP_SIZE;
29+
30+
stats.alloc_count = 0;
31+
stats.free_count = 0;
32+
stats.max_used = 0;
33+
stats.leak_count = 0;
2734
}
2835

2936
int expand_heap(u32 size) {
@@ -98,6 +105,8 @@ void* kmalloc(u32 size) {
98105
guard_end[i] = MAGIC_NUMBER;
99106
}
100107

108+
stats.alloc_count++;
109+
101110
return user_ptr;
102111
}
103112

@@ -185,6 +194,8 @@ void kfree(void* ptr) {
185194

186195
block->is_free = 1;
187196

197+
stats.free_count++;
198+
188199
if (block->next && block->next->is_free) {
189200
block->size += sizeof(mem_block_t) + block->next->size;
190201
block->next = block->next->next;
@@ -208,49 +219,55 @@ void kfree(void* ptr) {
208219
}
209220

210221
meminfo_t get_meminfo() {
211-
meminfo_t meminfo;
212222
mem_block_t* current = free_blocks;
213223
u32 total_used = 0;
214224
u32 total_free = 0;
215225
u32 block_count = 0;
226+
u32 used_blocks = 0;
216227

217228
while (current) {
218229
block_count++;
219230
if (current->is_free) {
220231
total_free += current->size;
221232
} else {
222233
total_used += current->size;
234+
used_blocks++;
223235
}
224236
current = current->next;
225237
}
226238

227-
meminfo.heap_start = HEAP_START;
228-
meminfo.heap_size = heap_current_end - HEAP_START;
229-
meminfo.heap_current_end = heap_current_end;
230-
meminfo.block_size = BLOCK_SIZE;
231-
meminfo.free_blocks = free_blocks;
232-
meminfo.total_used = total_used;
233-
meminfo.total_free = total_free;
234-
meminfo.block_count = block_count;
239+
stats.total_used = total_used;
240+
stats.total_free = total_free;
241+
stats.block_count = block_count;
242+
stats.leak_count = used_blocks;
243+
244+
stats.heap_start = HEAP_START;
245+
stats.heap_size = heap_current_end - HEAP_START;
246+
stats.heap_current_end = heap_current_end;
247+
stats.block_size = BLOCK_SIZE;
248+
stats.free_blocks = free_blocks;
235249

236-
return meminfo;
250+
return stats;
237251
}
238252

239253
void kmemdump() {
240254
meminfo_t info = get_meminfo();
241255
mem_block_t* current = info.free_blocks;
242256
u32 counter = 0;
243257

258+
printf("\nHeap: 0x%x - 0x%x (%d bytes)\n",
259+
HEAP_START,
260+
info.heap_current_end,
261+
info.heap_current_end - HEAP_START);
262+
printf("Block size: %d bytes, Guard: %d bytes\n", info.block_size, GUARD_SIZE);
263+
printf(
264+
"Allocations: %d, Frees: %d, Leaks: %d blocks\n", info.alloc_count, info.free_count, info.leak_count);
244265
printf(
245-
"Heap: %x - %x (%d bytes)\n", HEAP_START, info.heap_current_end, info.heap_current_end - HEAP_START);
246-
printf("Block size: %d bytes\n", info.block_size);
247-
printf("Total: USED=%d bytes, FREE=%d bytes, in %d blocks\n",
248-
info.total_used,
249-
info.total_free,
250-
info.block_count);
266+
"Max used: %d bytes, Current: USED=%d, FREE=%d\n", info.max_used, info.total_used, info.total_free);
267+
printf("Total blocks: %d\n", info.block_count);
251268

252269
while (current) {
253-
printf("Block %d: %x, Size=%d, %s\n",
270+
printf("Block %d: 0x%x, Size=%d, %s",
254271
counter++,
255272
(u32)current,
256273
current->size,

src/kernel/kklibc/mem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ typedef struct meminfo {
4141
u32 total_used;
4242
u32 total_free;
4343
u32 block_count;
44+
u32 alloc_count;
45+
u32 free_count;
46+
u32 max_used;
47+
u32 leak_count;
4448
} meminfo_t;
4549

4650
/**

0 commit comments

Comments
 (0)