sandbox: vm: encode vm_page zone id within p_flags

This commit is contained in:
2023-02-01 12:26:49 +00:00
parent a0d1fee01e
commit 2147837e9e
5 changed files with 62 additions and 23 deletions

View File

@@ -1,3 +1,4 @@
#include "socks/queue.h"
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
@@ -7,6 +8,7 @@
#include <assert.h>
#include <sys/mman.h>
#include <socks/types.h>
#include <socks/util.h>
#include <socks/memblock.h>
#include <socks/vm.h>
@@ -42,16 +44,19 @@ static struct mem_map_region mem_map[] = {
/* virtual address of where system memory is mapped */
static void *system_memory = NULL;
static void print_zone_pages(vm_zone_t *z)
static void print_free_pages(vm_zone_t *z)
{
printf(" * %s:\n", z->z_info.zd_name);
for (int i = VM_PAGE_MIN_ORDER; i <= VM_PAGE_MAX_ORDER; i++) {
queue_foreach (vm_page_t, pg, &z->z_free_pages[i], p_free_list) {
printf(" * %08zx (%s, order %u, 0x%zx bytes)\n",
vm_page_get_paddr(pg),
z->z_info.zd_name,
pg->p_order,
vm_page_order_to_bytes(pg->p_order));
if (queue_length(&z->z_free_pages[i]) == 0) {
continue;
}
char size_str[64];
data_size_to_string(vm_page_order_to_bytes(i), size_str, sizeof size_str);
printf(" - %u pages with size %s (order-%u)\n", queue_length(&z->z_free_pages[i]), size_str, i);
}
}
@@ -63,9 +68,10 @@ static void print_all_pages(void)
break;
}
vm_zone_t *z = vm_page_get_zone(pg);
printf(" * %08" PRIxPTR ": %s order-%u (%zu bytes) %s\n",
i,
pg->p_zone ? pg->p_zone->z_info.zd_name : "[none]",
z ? z->z_info.zd_name : "[none]",
pg->p_order,
vm_page_order_to_bytes(pg->p_order),
pg->p_flags & VM_PAGE_RESERVED ? "reserved" : "free");
@@ -162,7 +168,7 @@ int memory_test(void)
vm_pg_data_t *pg_data = vm_pg_data_get(0);
printf("free pages:\n");
for (int i = VM_ZONE_MIN; i <= VM_ZONE_MAX; i++) {
print_zone_pages(&pg_data->pg_zones[i]);
print_free_pages(&pg_data->pg_zones[i]);
}
printf("all pages:\n");