42_KFS/src/memory/virt/info.c

53 lines
1.5 KiB
C

#include "alloc.h"
#include "kprintf.h"
#include <stdint.h>
// FULL_INFO is to display (or not) both used and unused blocks
#define FULL_INFO 1
void show_valloc_mem(void)
{
char *const zones_name[3] = {"TINY", "SMALL", "LARGE"};
uint32_t total_size = 0;
for (block_type_t type = 0; type < 3; ++type) {
int count = 0;
for (Zone *zone_it = vzones[type]; zone_it != NULL;
zone_it = zone_it->next) {
if (zone_it->used)
kprintf("---------- IN_USE %s [n°%d - %p] "
"----------\n",
zones_name[type], count, zone_it);
for (Block *block_it = zone_it->used; block_it != NULL;
block_it = block_it->next_used) {
/* i++; */
/* if (i < 10) */
kprintf("%p - %p : %u bytes\n", block_it->ptr,
(uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block),
block_it->sub_size);
total_size += block_it->sub_size;
}
if (zone_it->used)
kprintf("\n");
count++;
#if FULL_INFO
if (zone_it->free)
kprintf("---------- AVAILABLE %s [n°%d - %p] "
"----------\n",
zones_name[type], count, zone_it);
for (Block *block_it = zone_it->free; block_it != NULL;
block_it = block_it->next_free) {
kprintf("%p - %p : %u bytes\n", block_it->ptr,
(uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block),
block_it->sub_size);
}
if (zone_it->free)
kprintf("\n");
#endif
}
}
kprintf("Total: %u\n", total_size);
}