diff options
-rw-r--r-- | ChangeLog | 33 | ||||
-rw-r--r-- | device/dev_lookup.c | 2 | ||||
-rw-r--r-- | device/dev_pager.c | 2 | ||||
-rw-r--r-- | device/ds_routines.c | 4 | ||||
-rw-r--r-- | device/net_io.c | 2 | ||||
-rw-r--r-- | i386/i386/fpu.c | 2 | ||||
-rw-r--r-- | i386/i386/pcb.c | 2 | ||||
-rw-r--r-- | i386/intel/pmap.c | 4 | ||||
-rw-r--r-- | ipc/ipc_init.c | 8 | ||||
-rw-r--r-- | ipc/ipc_marequest.c | 2 | ||||
-rw-r--r-- | kern/act.c | 2 | ||||
-rw-r--r-- | kern/kalloc.c | 2 | ||||
-rw-r--r-- | kern/processor.c | 2 | ||||
-rw-r--r-- | kern/task.c | 2 | ||||
-rw-r--r-- | kern/thread.c | 2 | ||||
-rw-r--r-- | kern/zalloc.c | 29 | ||||
-rw-r--r-- | kern/zalloc.h | 5 | ||||
-rw-r--r-- | vm/vm_external.c | 6 | ||||
-rw-r--r-- | vm/vm_fault.c | 2 | ||||
-rw-r--r-- | vm/vm_map.c | 8 | ||||
-rw-r--r-- | vm/vm_object.c | 2 | ||||
-rw-r--r-- | vm/vm_resident.c | 2 |
22 files changed, 89 insertions, 36 deletions
@@ -1,3 +1,36 @@ +2006-12-30 Richard Braun <syn@hurdfr.org> + + Add alignment support in the zone allocator. + * kern/zalloc.c (ALIGN_SIZE_UP): New macro. + (zinit): New `align' parameter. + (zget_space): Likewise. + (zalloc): Updated call to zget_space() with the zone alignment. + * kern/zalloc.h (zone): New member `align'. + (zinit): Declaration updated as required. + * device/dev_lookup.c (dev_lookup_init): Updated call to zinit() with + alignment of 0. + * device/dev_pager.c (dev_pager_hash_init): Likewise. + (device_pager_init): Likewise. + * device/ds_routines.c (ds_init): Likewise. + (ds_trap_init): Likewise. + * device/net_io.c (net_io_init): Likewise. + * i386/i386/fpu.c (fpu_module_init): Likewise. + * i386/i386/pcb.c (pcb_module_init): Likewise. + * i386/intel/pmap.c (pmap_init): Likewise. + * ipc/ipc_init.c (ipc_bootstrap): Likewise. + * ipc/ipc_marequest.c (ipc_marequest_init): Likewise. + * kern/act.c (global_act_init): Likewise. + * kern/kalloc.c (kalloc_init): Likewise. + * kern/processor.c (pset_sys_init): Likewise. + * kern/task.c (task_init): Likewise. + * kern/thread.c (thread_init): Likewise. + * kern/zalloc.c (zone_bootstrap): Likewise. + * vm/vm_external.c (vm_external_module_initialize): Likewise. + * vm/vm_fault.c (vm_fault_init): Likewise. + * vm/vm_map.c (vm_map_init): Likewise. + * vm/vm_object.c (vm_object_bootstrap): Likewise. + * vm/vm_resident.c (vm_page_module_init): Likewise. + 2007-01-02 Samuel Thibault <samuel.thibault@ens-lyon.org> Fix translation of port into device in the "no sender" notification. diff --git a/device/dev_lookup.c b/device/dev_lookup.c index 746c394..3243a2c 100644 --- a/device/dev_lookup.c +++ b/device/dev_lookup.c @@ -401,7 +401,7 @@ dev_lookup_init() simple_lock_init(&dev_port_lock); - dev_hdr_zone = zinit(sizeof(struct mach_device), + dev_hdr_zone = zinit(sizeof(struct mach_device), 0, sizeof(struct mach_device) * NDEVICES, PAGE_SIZE, FALSE, diff --git a/device/dev_pager.c b/device/dev_pager.c index 2626330..6779d8e 100644 --- a/device/dev_pager.c +++ b/device/dev_pager.c @@ -174,6 +174,7 @@ void dev_pager_hash_init(void) size = sizeof(struct dev_pager_entry); dev_pager_hash_zone = zinit( size, + 0, size * 1000, PAGE_SIZE, FALSE, @@ -727,6 +728,7 @@ void device_pager_init(void) */ size = sizeof(struct dev_pager); dev_pager_zone = zinit(size, + 0, (vm_size_t) size * 1000, PAGE_SIZE, FALSE, diff --git a/device/ds_routines.c b/device/ds_routines.c index 303d6f7..0abd75b 100644 --- a/device/ds_routines.c +++ b/device/ds_routines.c @@ -1471,7 +1471,7 @@ void ds_init() */ device_io_map->wait_for_space = TRUE; - io_inband_zone = zinit(sizeof(io_buf_ptr_inband_t), + io_inband_zone = zinit(sizeof(io_buf_ptr_inband_t), 0, 1000 * sizeof(io_buf_ptr_inband_t), 10 * sizeof(io_buf_ptr_inband_t), FALSE, @@ -1519,7 +1519,7 @@ zone_t io_trap_zone; void ds_trap_init(void) { - io_trap_zone = zinit(IOTRAP_REQSIZE, + io_trap_zone = zinit(IOTRAP_REQSIZE, 0, 256 * IOTRAP_REQSIZE, 16 * IOTRAP_REQSIZE, FALSE, diff --git a/device/net_io.c b/device/net_io.c index 71d92b4..b565aa3 100644 --- a/device/net_io.c +++ b/device/net_io.c @@ -1494,6 +1494,7 @@ net_io_init() size = sizeof(struct net_rcv_port); net_rcv_zone = zinit(size, + 0, size * 1000, PAGE_SIZE, FALSE, @@ -1501,6 +1502,7 @@ net_io_init() size = sizeof(struct net_hash_entry); net_hash_entry_zone = zinit(size, + 0, size * 100, PAGE_SIZE, FALSE, diff --git a/i386/i386/fpu.c b/i386/i386/fpu.c index ad88a5d..d5824f8 100644 --- a/i386/i386/fpu.c +++ b/i386/i386/fpu.c @@ -152,7 +152,7 @@ init_fpu() void fpu_module_init() { - ifps_zone = zinit(sizeof(struct i386_fpsave_state), + ifps_zone = zinit(sizeof(struct i386_fpsave_state), 0, THREAD_MAX * sizeof(struct i386_fpsave_state), THREAD_CHUNK * sizeof(struct i386_fpsave_state), 0, "i386 fpsave state"); diff --git a/i386/i386/pcb.c b/i386/i386/pcb.c index f431e89..1b24557 100644 --- a/i386/i386/pcb.c +++ b/i386/i386/pcb.c @@ -311,7 +311,7 @@ thread_t switch_context(old, continuation, new) void pcb_module_init() { - pcb_zone = zinit(sizeof(struct pcb), + pcb_zone = zinit(sizeof(struct pcb), 0, THREAD_MAX * sizeof(struct pcb), THREAD_CHUNK * sizeof(struct pcb), 0, "i386 pcb state"); diff --git a/i386/intel/pmap.c b/i386/intel/pmap.c index aa89aa5..de65ac8 100644 --- a/i386/intel/pmap.c +++ b/i386/intel/pmap.c @@ -697,9 +697,9 @@ void pmap_init() * and of the physical-to-virtual entries. */ s = (vm_size_t) sizeof(struct pmap); - pmap_zone = zinit(s, 400*s, 4096, 0, "pmap"); /* XXX */ + pmap_zone = zinit(s, 0, 400*s, 4096, 0, "pmap"); /* XXX */ s = (vm_size_t) sizeof(struct pv_entry); - pv_list_zone = zinit(s, 10000*s, 4096, 0, "pv_list"); /* XXX */ + pv_list_zone = zinit(s, 0, 10000*s, 4096, 0, "pv_list"); /* XXX */ #if NCPUS > 1 /* diff --git a/ipc/ipc_init.c b/ipc/ipc_init.c index 561e3a9..464e0e3 100644 --- a/ipc/ipc_init.c +++ b/ipc/ipc_init.c @@ -77,25 +77,25 @@ ipc_bootstrap(void) ipc_port_timestamp_lock_init(); ipc_port_timestamp_data = 0; - ipc_space_zone = zinit(sizeof(struct ipc_space), + ipc_space_zone = zinit(sizeof(struct ipc_space), 0, ipc_space_max * sizeof(struct ipc_space), sizeof(struct ipc_space), IPC_ZONE_TYPE, "ipc spaces"); ipc_tree_entry_zone = - zinit(sizeof(struct ipc_tree_entry), + zinit(sizeof(struct ipc_tree_entry), 0, ipc_tree_entry_max * sizeof(struct ipc_tree_entry), sizeof(struct ipc_tree_entry), IPC_ZONE_TYPE, "ipc tree entries"); ipc_object_zones[IOT_PORT] = - zinit(sizeof(struct ipc_port), + zinit(sizeof(struct ipc_port), 0, ipc_port_max * sizeof(struct ipc_port), sizeof(struct ipc_port), 0, "ipc ports"); ipc_object_zones[IOT_PORT_SET] = - zinit(sizeof(struct ipc_pset), + zinit(sizeof(struct ipc_pset), 0, ipc_pset_max * sizeof(struct ipc_pset), sizeof(struct ipc_pset), IPC_ZONE_TYPE, "ipc port sets"); diff --git a/ipc/ipc_marequest.c b/ipc/ipc_marequest.c index e62001e..16c6a5f 100644 --- a/ipc/ipc_marequest.c +++ b/ipc/ipc_marequest.c @@ -143,7 +143,7 @@ ipc_marequest_init() } ipc_marequest_zone = - zinit(sizeof(struct ipc_marequest), + zinit(sizeof(struct ipc_marequest), 0, ipc_marequest_max * sizeof(struct ipc_marequest), sizeof(struct ipc_marequest), IPC_ZONE_TYPE, "ipc msg-accepted requests"); @@ -69,7 +69,7 @@ global_act_init() { #ifndef ACT_STATIC_KLUDGE act_zone = zinit( - sizeof(struct Act), + sizeof(struct Act), 0, ACT_MAX * sizeof(struct Act), /* XXX */ ACT_CHUNK * sizeof(struct Act), 0, "activations"); diff --git a/kern/kalloc.c b/kern/kalloc.c index b24eaa3..4460d59 100644 --- a/kern/kalloc.c +++ b/kern/kalloc.c @@ -145,7 +145,7 @@ void kalloc_init() if (size == MINSIZE) { first_k_zone = i; } - k_zone[i] = zinit(size, k_zone_max[i] * size, size, + k_zone[i] = zinit(size, 0, k_zone_max[i] * size, size, size >= PAGE_SIZE ? ZONE_COLLECTABLE : 0, k_zone_name[i]); } diff --git a/kern/processor.c b/kern/processor.c index 4035ad9..d645051 100644 --- a/kern/processor.c +++ b/kern/processor.c @@ -113,7 +113,7 @@ void pset_sys_init(void) /* * Allocate the zone for processor sets. */ - pset_zone = zinit(sizeof(struct processor_set), 128*PAGE_SIZE, + pset_zone = zinit(sizeof(struct processor_set), 0, 128*PAGE_SIZE, PAGE_SIZE, 0, "processor sets"); /* diff --git a/kern/task.c b/kern/task.c index db61522..1c4c673 100644 --- a/kern/task.c +++ b/kern/task.c @@ -61,7 +61,7 @@ extern void eml_task_deallocate(task_t); void task_init(void) { task_zone = zinit( - sizeof(struct task), + sizeof(struct task), 0, TASK_MAX * sizeof(struct task), TASK_CHUNK * sizeof(struct task), 0, "tasks"); diff --git a/kern/thread.c b/kern/thread.c index 8c08dc4..6ca91a7 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -299,7 +299,7 @@ void stack_privilege( void thread_init(void) { thread_zone = zinit( - sizeof(struct thread), + sizeof(struct thread), 0, THREAD_MAX * sizeof(struct thread), THREAD_CHUNK * sizeof(struct thread), 0, "threads"); diff --git a/kern/zalloc.c b/kern/zalloc.c index dba6190..1f415f7 100644 --- a/kern/zalloc.c +++ b/kern/zalloc.c @@ -72,6 +72,9 @@ MACRO_BEGIN \ } \ MACRO_END +#define ALIGN_SIZE_UP(size, align) \ +((size) = (((size) + ((align) - 1)) & ~((align) - 1))) + /* * Support for garbage collection of unused zone pages: */ @@ -146,7 +149,7 @@ MACRO_BEGIN \ } \ MACRO_END -static vm_offset_t zget_space(); +static vm_offset_t zget_space(vm_offset_t size, vm_size_t align); decl_simple_lock_data(,zget_space_lock) vm_offset_t zalloc_next_space; @@ -182,8 +185,9 @@ int num_zones; * are stored in a zone, which is initially a static structure that * is initialized by zone_init. */ -zone_t zinit(size, max, alloc, memtype, name) +zone_t zinit(size, align, max, alloc, memtype, name) vm_size_t size; /* the size of an element */ + vm_size_t align; /* alignment of elements */ vm_size_t max; /* maximum memory to use */ vm_size_t alloc; /* allocation size */ unsigned int memtype; /* flags specifying type of memory */ @@ -192,12 +196,11 @@ zone_t zinit(size, max, alloc, memtype, name) register zone_t z; if (zone_zone == ZONE_NULL) - z = (zone_t) zget_space(sizeof(struct zone)); + z = (zone_t) zget_space(sizeof(struct zone), 0); else z = (zone_t) zalloc(zone_zone); if (z == ZONE_NULL) panic("zinit"); - if (alloc == 0) alloc = PAGE_SIZE; @@ -210,11 +213,18 @@ zone_t zinit(size, max, alloc, memtype, name) if ((max = round_page(max)) < (alloc = round_page(alloc))) max = alloc; + if (align > 0) { + if (align >= PAGE_SIZE) + panic("zinit"); + ALIGN_SIZE_UP(size, align); + } + z->free_elements = 0; z->cur_size = 0; z->max_size = max; z->elem_size = ((size-1) + sizeof(z->free_elements)) - ((size-1) % sizeof(z->free_elements)); + z->align = align; z->alloc_size = alloc; z->type = memtype; @@ -268,13 +278,18 @@ void zcram(zone_t zone, vm_offset_t newmem, vm_size_t size) * of memory from zone_map. */ -static vm_offset_t zget_space(vm_offset_t size) +static vm_offset_t zget_space(vm_offset_t size, vm_size_t align) { vm_offset_t new_space = 0; vm_offset_t result; vm_size_t space_to_add = 0; /*'=0' to quiet gcc warnings */ simple_lock(&zget_space_lock); + if (align > 0) { + assert(align < PAGE_SIZE); + ALIGN_SIZE_UP(zalloc_next_space, align); + } + while ((zalloc_next_space + size) > zalloc_end_of_space) { /* * Add at least one page to allocation area. @@ -359,7 +374,7 @@ void zone_bootstrap() zalloc_wasted_space = 0; zone_zone = ZONE_NULL; - zone_zone = zinit(sizeof(struct zone), 128 * sizeof(struct zone), + zone_zone = zinit(sizeof(struct zone), 0, 128 * sizeof(struct zone), sizeof(struct zone), 0, "zones"); } @@ -487,7 +502,7 @@ vm_offset_t zalloc(zone_t zone) zone_lock(zone); REMOVE_FROM_ZONE(zone, addr, vm_offset_t); } else { - addr = zget_space(zone->elem_size); + addr = zget_space(zone->elem_size, zone->align); if (addr == 0) panic("zalloc: zone %s exhausted", zone->zone_name); diff --git a/kern/zalloc.h b/kern/zalloc.h index 9e44a6d..3f9bf21 100644 --- a/kern/zalloc.h +++ b/kern/zalloc.h @@ -59,6 +59,7 @@ struct zone { vm_size_t cur_size; /* current memory utilization */ vm_size_t max_size; /* how large can this zone grow */ vm_size_t elem_size; /* size of an element */ + vm_size_t align; /* alignment of elements */ vm_size_t alloc_size; /* size used for more memory */ boolean_t doing_alloc; /* is zone expanding now? */ char *zone_name; /* a name for the zone */ @@ -71,8 +72,8 @@ typedef struct zone *zone_t; #define ZONE_NULL ((zone_t) 0) /* Exported to everyone */ -zone_t zinit(vm_size_t size, vm_size_t max, vm_size_t alloc, - unsigned int memtype, char *name); +zone_t zinit(vm_size_t size, vm_size_t align, vm_size_t max, + vm_size_t alloc, unsigned int memtype, char *name); vm_offset_t zalloc(zone_t zone); vm_offset_t zget(zone_t zone); void zfree(zone_t zone, vm_offset_t elem); diff --git a/vm/vm_external.c b/vm/vm_external.c index da59137..c8079c5 100644 --- a/vm/vm_external.c +++ b/vm/vm_external.c @@ -142,16 +142,16 @@ void vm_external_module_initialize() { vm_size_t size = (vm_size_t) sizeof(struct vm_external); - vm_external_zone = zinit(size, 16*1024*size, size, + vm_external_zone = zinit(size, 0, 16*1024*size, size, 0, "external page bitmaps"); - vm_object_small_existence_map_zone = zinit(SMALL_SIZE, + vm_object_small_existence_map_zone = zinit(SMALL_SIZE, 0, round_page(LARGE_SIZE * SMALL_SIZE), round_page(SMALL_SIZE), ZONE_EXHAUSTIBLE, "object small existence maps"); - vm_object_large_existence_map_zone = zinit(LARGE_SIZE, + vm_object_large_existence_map_zone = zinit(LARGE_SIZE, 0, round_page(8 * LARGE_SIZE), round_page(LARGE_SIZE), ZONE_EXHAUSTIBLE, diff --git a/vm/vm_fault.c b/vm/vm_fault.c index f2e5d9c..a09750f 100644 --- a/vm/vm_fault.c +++ b/vm/vm_fault.c @@ -107,7 +107,7 @@ extern struct db_watchpoint *db_watchpoint_list; */ void vm_fault_init() { - vm_fault_state_zone = zinit(sizeof(vm_fault_state_t), + vm_fault_state_zone = zinit(sizeof(vm_fault_state_t), 0, THREAD_MAX * sizeof(vm_fault_state_t), sizeof(vm_fault_state_t), 0, "vm fault state"); diff --git a/vm/vm_map.c b/vm/vm_map.c index 6f8fb34..79b1283 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -158,17 +158,17 @@ int kentry_count = 256; /* to init kentry_data_size */ void vm_map_init() { - vm_map_zone = zinit((vm_size_t) sizeof(struct vm_map), 40*1024, + vm_map_zone = zinit((vm_size_t) sizeof(struct vm_map), 0, 40*1024, PAGE_SIZE, 0, "maps"); vm_map_entry_zone = zinit((vm_size_t) sizeof(struct vm_map_entry), - 1024*1024, PAGE_SIZE*5, + 0, 1024*1024, PAGE_SIZE*5, 0, "non-kernel map entries"); - vm_map_kentry_zone = zinit((vm_size_t) sizeof(struct vm_map_entry), + vm_map_kentry_zone = zinit((vm_size_t) sizeof(struct vm_map_entry), 0, kentry_data_size, kentry_data_size, ZONE_FIXED /* XXX */, "kernel map entries"); vm_map_copy_zone = zinit((vm_size_t) sizeof(struct vm_map_copy), - 16*1024, PAGE_SIZE, 0, + 0, 16*1024, PAGE_SIZE, 0, "map copies"); /* diff --git a/vm/vm_object.c b/vm/vm_object.c index b2a72e1..5ffa021 100644 --- a/vm/vm_object.c +++ b/vm/vm_object.c @@ -244,7 +244,7 @@ vm_object_t vm_object_allocate( */ void vm_object_bootstrap(void) { - vm_object_zone = zinit((vm_size_t) sizeof(struct vm_object), + vm_object_zone = zinit((vm_size_t) sizeof(struct vm_object), 0, round_page(512*1024), round_page(12*1024), 0, "objects"); diff --git a/vm/vm_resident.c b/vm/vm_resident.c index 1440a0b..ef13145 100644 --- a/vm/vm_resident.c +++ b/vm/vm_resident.c @@ -425,7 +425,7 @@ void pmap_startup( */ void vm_page_module_init(void) { - vm_page_zone = zinit((vm_size_t) sizeof(struct vm_page), + vm_page_zone = zinit((vm_size_t) sizeof(struct vm_page), 0, VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS, PAGE_SIZE, 0, "vm pages"); |