vm-object can be used to demand-allocate non-contiguous physical memory, and will provide an api for userspace programs to do the same. unless a vm-object is created in-place (i.e. to represent a specific area of physical memory), its memory pages are only allocated when the object is mapped AND someone attempts to access the memory.
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include <limits.h>
|
|
#include <mango/machine/cpu.h>
|
|
#include <mango/memblock.h>
|
|
#include <mango/printk.h>
|
|
#include <mango/status.h>
|
|
#include <mango/vm-object.h>
|
|
#include <mango/vm.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* One struct vm_pg_data per NUMA node. */
|
|
static struct vm_pg_data *node_data = NULL;
|
|
|
|
kern_status_t vm_bootstrap(
|
|
const struct vm_zone_descriptor *zones,
|
|
size_t nr_zones)
|
|
{
|
|
int numa_count = 1;
|
|
|
|
/* we're only worrying about UMA systems for now */
|
|
node_data = memblock_alloc(sizeof(struct vm_pg_data) * numa_count, 8);
|
|
|
|
/* TODO select which memory model to use automatically, and add
|
|
a kernel boot parameter to override the choice */
|
|
vm_set_memory_model(VM_MODEL_SPARSE);
|
|
|
|
switch (vm_memory_model()) {
|
|
case VM_MODEL_SPARSE:
|
|
vm_sparse_init();
|
|
break;
|
|
case VM_MODEL_FLAT:
|
|
vm_flat_init();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
for (size_t i = 0; i < nr_zones; i++) {
|
|
vm_zone_init(&node_data->pg_zones[zones[i].zd_id], &zones[i]);
|
|
}
|
|
|
|
kmalloc_init();
|
|
vm_object_type_init();
|
|
return KERN_OK;
|
|
}
|
|
|
|
struct vm_pg_data *vm_pg_data_get(vm_node_id_t node)
|
|
{
|
|
if (node == 0) {
|
|
return node_data;
|
|
}
|
|
|
|
return NULL;
|
|
}
|