From 7331bdefda78d817f0724f19f989f6debd08fc70 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 2 Feb 2023 16:54:48 +0000 Subject: [PATCH] sandbox: vm: reduce vm_page order field size to 4 bits --- sandbox/vm/include/socks/vm.h | 27 ++++++++++++++++++++------- sandbox/vm/page.c | 6 ++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/sandbox/vm/include/socks/vm.h b/sandbox/vm/include/socks/vm.h index 23db87f..cc44b16 100644 --- a/sandbox/vm/include/socks/vm.h +++ b/sandbox/vm/include/socks/vm.h @@ -60,9 +60,15 @@ typedef enum vm_page_order { VM_PAGE_32M, VM_PAGE_64M, VM_PAGE_128M, +#if 0 + /* vm_page_t only has 4 bits to store the page order with. + the maximum order that can be stored in 4 bits is 15 (VM_PAGE_128M) + to use any of the page orders listed here, this field + will have to be expanded. */ VM_PAGE_256M, VM_PAGE_512M, VM_PAGE_1G, +#endif VM_PAGE_MIN_ORDER = VM_PAGE_4K, VM_PAGE_MAX_ORDER = VM_PAGE_8M, } vm_page_order_t; @@ -110,18 +116,25 @@ typedef enum vm_page_flags { } vm_page_flags_t; typedef struct vm_page { + /* order of the page block that this page belongs too */ + uint16_t p_order : 4; /* the id of the NUMA node that this page belongs to */ - uint32_t p_node : 6; + uint16_t p_node : 6; /* the id of the memory zone that this page belongs to */ - uint32_t p_zone : 2; - /* vm_page_flags_t bitfields. */ - uint32_t p_flags : 24; + uint16_t p_zone : 3; + /* some unused bits */ + uint16_t p_reserved : 3; - /* buddy allocator free page list head (vm_zone_t->z_free_pages[p_order]) */ + /* vm_page_flags_t bitfields. */ + uint32_t p_flags; + + /* multi-purpose list. + the owner of the page can decide what to do with this. + some examples: + - the buddy allocator uses this to maintain its per-zone free-page lists. + */ queue_entry_t p_free_list; - /* order of the page block that this page belongs too */ - unsigned char p_order; } __attribute__((aligned(2 * sizeof(unsigned long)))) vm_page_t; extern kern_status_t vm_bootstrap(const vm_zone_descriptor_t *zones, size_t nr_zones); diff --git a/sandbox/vm/page.c b/sandbox/vm/page.c index 40f402c..51ba4cf 100644 --- a/sandbox/vm/page.c +++ b/sandbox/vm/page.c @@ -28,9 +28,15 @@ static size_t page_order_bytes[] = { [VM_PAGE_32M] = 0x2000000, [VM_PAGE_64M] = 0x4000000, [VM_PAGE_128M] = 0x8000000, +#if 0 + /* vm can support pages of this size, but + vm_page_t only has 4 bits with which to store + the page order, which cannot accomodate these + larger order numbers */ [VM_PAGE_256M] = 0x10000000, [VM_PAGE_512M] = 0x20000000, [VM_PAGE_1G] = 0x40000000, +#endif }; void vm_page_init_array()