Files
FAT-Allocator/dpdk/kernel/freebsd/Malloc/Malloc.c
2025-04-02 17:28:49 +01:00

79 lines
1.9 KiB
C

#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_page.h>
#include <vm/vm_kern.h>
#include <sys/param.h>
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/rwlock.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <sys/eventhandler.h>
#include <machine/bus.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_param.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
#include <vm/vm_phys.h>
#define HUGE_PAGE_SIZE (2 * 1024 * 1024) // 2MB Large Page
static void *hugepage_ptr = NULL;
static int load_handler(module_t mod, int event, void *arg) {
switch (event) {
case MOD_LOAD:
printf("Loading Huge Page Kernel Module...\n");
hugepage_ptr = kmem_alloc_contig(HUGE_PAGE_SIZE, M_WAITOK,
0, BUS_SPACE_MAXADDR,
HUGE_PAGE_SIZE, 0,
VM_MEMATTR_DEFAULT);
if (!hugepage_ptr) {
printf("Failed to allocate a huge page!\n");
return ENOMEM;
}
printf("Huge page allocated at %p\n", hugepage_ptr);
break;
case MOD_UNLOAD:
if (hugepage_ptr) {
kmem_free(hugepage_ptr, HUGE_PAGE_SIZE);
printf("Huge page freed.\n");
}
printf("Unloading module...\n");
break;
default:
return EOPNOTSUPP;
}
return 0;
}
static moduledata_t superpage_mod = {
"superpage",
load_handler,
NULL
};
DECLARE_MODULE(superpage, superpage_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);