diff options
-rw-r--r-- | libhurd-cap-server/ChangeLog | 9 | ||||
-rw-r--r-- | libhurd-cap-server/class-init.c | 4 | ||||
-rw-r--r-- | libhurd-cap-server/client-create.c | 4 | ||||
-rw-r--r-- | libhurd-cap-server/obj-entry-space.c | 4 | ||||
-rw-r--r-- | libhurd-cap/ChangeLog | 6 | ||||
-rw-r--r-- | libhurd-cap/cap.c | 4 | ||||
-rw-r--r-- | libhurd-slab/ChangeLog | 22 | ||||
-rw-r--r-- | libhurd-slab/README | 4 | ||||
-rw-r--r-- | libhurd-slab/slab.c | 63 | ||||
-rw-r--r-- | libhurd-slab/slab.h | 46 | ||||
-rw-r--r-- | task/ChangeLog | 6 | ||||
-rw-r--r-- | task/thread.c | 6 |
12 files changed, 148 insertions, 30 deletions
diff --git a/libhurd-cap-server/ChangeLog b/libhurd-cap-server/ChangeLog index 738c626..c9dba84 100644 --- a/libhurd-cap-server/ChangeLog +++ b/libhurd-cap-server/ChangeLog @@ -1,3 +1,12 @@ +2005-01-07 Neal H. Walfield <neal@gnu.org> + + * class-init.c (hurd_cap_class_init_untyped): Supply the + allocate_buffer and deallocate_buffer arguments to + hurd_slab_create to conform with the new semantics. + * obj-entry-space.c (_hurd_cap_obj_entry_space): Likewise for + HURD_SLAB_SPACE_INITIALIZER. + * client-create.c (_hurd_cap_client_space): Likewise. + 2004-12-01 Neal H. Walfield <neal@gnu.org> * cap-server-intern.h (struct _hurd_cap_client): Fold the struct diff --git a/libhurd-cap-server/class-init.c b/libhurd-cap-server/class-init.c index cdbb7db..aad5015 100644 --- a/libhurd-cap-server/class-init.c +++ b/libhurd-cap-server/class-init.c @@ -1,5 +1,5 @@ /* class-init.c - Initialize a capability class. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann <marcus@gnu.org> This file is part of the GNU Hurd. @@ -116,7 +116,7 @@ hurd_cap_class_init_untyped (hurd_cap_class_t cap_class, cap_class->obj_reinit = obj_reinit; cap_class->obj_destroy = obj_destroy; - err = hurd_slab_init (&cap_class->obj_space, size, alignment, + err = hurd_slab_init (&cap_class->obj_space, size, alignment, NULL, NULL, _hurd_cap_obj_constructor, _hurd_cap_obj_destructor, cap_class); if (err) diff --git a/libhurd-cap-server/client-create.c b/libhurd-cap-server/client-create.c index 1fa8996..ac8c54a 100644 --- a/libhurd-cap-server/client-create.c +++ b/libhurd-cap-server/client-create.c @@ -1,5 +1,5 @@ /* client-create.c - Create a capability client. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann <marcus@gnu.org> This file is part of the GNU Hurd. @@ -79,7 +79,7 @@ _hurd_cap_client_destructor (void *hook, void *buffer) /* The global slab for all capability clients. */ struct hurd_slab_space _hurd_cap_client_space - = HURD_SLAB_SPACE_INITIALIZER (struct _hurd_cap_client, + = HURD_SLAB_SPACE_INITIALIZER (struct _hurd_cap_client, NULL, NULL, _hurd_cap_client_constructor, _hurd_cap_client_destructor, NULL); diff --git a/libhurd-cap-server/obj-entry-space.c b/libhurd-cap-server/obj-entry-space.c index 91b6894..5eb33ba 100644 --- a/libhurd-cap-server/obj-entry-space.c +++ b/libhurd-cap-server/obj-entry-space.c @@ -1,5 +1,5 @@ /* obj-entry-space.c - The capability object entry slab space. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann <marcus@gnu.org> This file is part of the GNU Hurd. @@ -48,5 +48,5 @@ _hurd_cap_obj_entry_constructor (void *hook, void *buffer) /* The global slab for all capability entries. */ struct hurd_slab_space _hurd_cap_obj_entry_space - = HURD_SLAB_SPACE_INITIALIZER (struct _hurd_cap_obj_entry, + = HURD_SLAB_SPACE_INITIALIZER (struct _hurd_cap_obj_entry, NULL, NULL, _hurd_cap_obj_entry_constructor, NULL, NULL); diff --git a/libhurd-cap/ChangeLog b/libhurd-cap/ChangeLog new file mode 100644 index 0000000..e23fa49 --- /dev/null +++ b/libhurd-cap/ChangeLog @@ -0,0 +1,6 @@ +2005-01-07 Neal H. Walfield <neal@gnu.org> + + * cap.c (hurd_cap_init): Supply the allocate_buffer and + deallocate_buffer arguments to hurd_slab_create to conform with + the new semantics. + diff --git a/libhurd-cap/cap.c b/libhurd-cap/cap.c index 54505f3..c5ed161 100644 --- a/libhurd-cap/cap.c +++ b/libhurd-cap/cap.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann <marcus@gnu.org> This file is part of the GNU Hurd. @@ -75,7 +75,7 @@ cap_destructor (void *hook, void *buffer) error_t hurd_cap_init (void) { - return hurd_slab_create (sizeof (struct hurd_cap), 0, + return hurd_slab_create (sizeof (struct hurd_cap), 0, NULL, NULL, cap_constructor, cap_destructor, NULL, &cap_space); } diff --git a/libhurd-slab/ChangeLog b/libhurd-slab/ChangeLog index b1acb7e..378834f 100644 --- a/libhurd-slab/ChangeLog +++ b/libhurd-slab/ChangeLog @@ -1,3 +1,25 @@ +2005-01-06 Neal H. Walfield <neal@gnu.org> + + * slab.h (hurd_slab_allocate_buffer_t): New type. + (hurd_slab_deallocate_buffer_t): Likewise. + (struct hurd_slab_space): New fields allocate_buffer and + deallocate_buffer. + (HURD_SLAB_SPACE_INITIALIZER): Add new arguments ALLOC and DEALLOC + and take them into account when creating the slab. + (hurd_slab_create): New parameters ALLOCATE_BUFFER and + DEALLOCATE_BUFFER. + (hurd_slab_init): Likewise. + + * slab.c (allocate_buffer): New function. + (deallocate_buffer): Likewise. + (reap): When deallocating a buffer, use allocate_buffer. + (grow): When allocating or deallocating a buffer, call + allocate_buffer or deallocate_buffer as appropriate. + (hurd_slab_init): Add new arguments ALLOCATE_BUFFER and + DEALLOCATE_BUFFER and take them into account when setting up + SPACE. + (hurd_slab_create): Likewise. + 2004-11-01 Marcus Brinkmann <marcus@gnu.org> * slab.c (hurd_slab_destroy): Remove unused variable PREVP. diff --git a/libhurd-slab/README b/libhurd-slab/README index 4d6e6d4..d171a73 100644 --- a/libhurd-slab/README +++ b/libhurd-slab/README @@ -7,8 +7,8 @@ purpose allocation strategy like malloc(), but a special arena (or other backing memory) and a special purpose allocator that can take advantage of the fact that all objects are of the same size. -In addition, such objects usually have an initial stage that is -naturally returned to when the object is not needed anymore. For +In addition, such objects usually have an initial stage that they +naturally return to when the objects are no longer needed. For example locks are unlocked, reference counters are zero, etc. In such a situation, performance can be further increased by caching the unused objects, instead of destroying them. diff --git a/libhurd-slab/slab.c b/libhurd-slab/slab.c index c0a717c..b6e3f51 100644 --- a/libhurd-slab/slab.c +++ b/libhurd-slab/slab.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2005 Free Software Foundation, Inc. Written by Johan Rydberg. This file is part of the GNU Hurd. @@ -65,6 +65,40 @@ struct hurd_slab union hurd_bufctl *free_list; }; +/* Allocate a buffer in *PTR of size SIZE which must be a power of 2 + and self aligned (i.e. aligned on a SIZE byte boundary) for slab + space SPACE. Return 0 on success, an error code on failure. */ +static error_t +allocate_buffer (struct hurd_slab_space *space, size_t size, void **ptr) +{ + if (space->allocate_buffer) + return space->allocate_buffer (space->hook, getpagesize (), ptr); + else + { + *ptr = mmap (NULL, getpagesize (), PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); + if (*ptr == MAP_FAILED) + return errno; + else + return 0; + } +} + +/* Deallocate buffer BUFFER of size SIZE which was allocated for slab + space SPACE. Return 0 on success, an error code on failure. */ +static error_t +deallocate_buffer (struct hurd_slab_space *space, void *buffer, size_t size) +{ + if (space->deallocate_buffer) + return space->deallocate_buffer (space->hook, buffer, size); + else + { + if (munmap (buffer, size) == -1) + return errno; + else + return 0; + } +} /* Insert SLAB into the list of slabs in SPACE. SLAB is expected to be complete (so it will be inserted at the end). */ @@ -143,9 +177,9 @@ reap (struct hurd_slab_space *space) in front of it), get address by masking with page size. This frees the slab and all its buffers, since they live on the same page. */ - err = munmap - ((void *) (((uintptr_t) s) & ~(getpagesize () - 1)), - getpagesize ()); + err = deallocate_buffer (space, (void *) (((uintptr_t) s) + & ~(getpagesize () - 1)), + getpagesize ()); if (err) break; __hurd_slab_nr_pages--; @@ -200,6 +234,7 @@ init_space (hurd_slab_space_t space) static error_t grow (struct hurd_slab_space *space) { + error_t err; struct hurd_slab *new_slab; union hurd_bufctl *bufctl; int nr_objs, i; @@ -211,10 +246,10 @@ grow (struct hurd_slab_space *space) if (!space->initialized) init_space (space); - p = mmap (NULL, getpagesize (), PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - if (p == MAP_FAILED) - return errno; + err = allocate_buffer (space, getpagesize (), &p); + if (err) + return err; + __hurd_slab_nr_pages++; new_slab = (p + getpagesize () - sizeof (struct hurd_slab)); @@ -244,7 +279,7 @@ grow (struct hurd_slab_space *space) (*space->destructor) (space->hook, buffer); } - munmap (p, getpagesize ()); + deallocate_buffer (space, p, getpagesize ()); return err; } } @@ -270,6 +305,8 @@ grow (struct hurd_slab_space *space) /* Initialize the slab space SPACE. */ error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, + hurd_slab_allocate_buffer_t allocate_buffer, + hurd_slab_deallocate_buffer_t deallocate_buffer, hurd_slab_constructor_t constructor, hurd_slab_destructor_t destructor, void *hook) @@ -299,6 +336,8 @@ hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, if (err) return err; + space->allocate_buffer = allocate_buffer; + space->deallocate_buffer = deallocate_buffer; space->constructor = constructor; space->destructor = destructor; space->hook = hook; @@ -312,6 +351,8 @@ hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, constructor and destructor. ALIGNMENT can be zero. */ error_t hurd_slab_create (size_t size, size_t alignment, + hurd_slab_allocate_buffer_t allocate_buffer, + hurd_slab_deallocate_buffer_t deallocate_buffer, hurd_slab_constructor_t constructor, hurd_slab_destructor_t destructor, void *hook, @@ -324,7 +365,9 @@ hurd_slab_create (size_t size, size_t alignment, if (!space) return ENOMEM; - err = hurd_slab_init (space, size, alignment, constructor, destructor, hook); + err = hurd_slab_init (space, size, alignment, + allocate_buffer, deallocate_buffer, + constructor, destructor, hook); if (err) { free (space); diff --git a/libhurd-slab/slab.h b/libhurd-slab/slab.h index 5154943..3fa854c 100644 --- a/libhurd-slab/slab.h +++ b/libhurd-slab/slab.h @@ -1,5 +1,5 @@ /* slab.h - The GNU Hurd slab allocator interface. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann <marcus@gnu.org> This file is part of the GNU Hurd. @@ -27,6 +27,18 @@ #include <pthread.h> +/* Allocate a buffer in *PTR of size SIZE which must be a power of 2 + and self aligned (i.e. aligned on a SIZE byte boundary). HOOK is + as provided to hurd_slab_create. Return 0 on success, an error + code on failure. */ +typedef error_t (*hurd_slab_allocate_buffer_t) (void *hook, size_t size, + void **ptr); + +/* Deallocate buffer BUFFER of size SIZE. HOOK is as provided to + hurd_slab_create. */ +typedef error_t (*hurd_slab_deallocate_buffer_t) (void *hook, void *buffer, + size_t size); + /* Initialize the slab object pointed to by BUFFER. HOOK is as provided to hurd_slab_create. */ typedef error_t (*hurd_slab_constructor_t) (void *hook, void *buffer); @@ -63,6 +75,12 @@ struct hurd_slab_space size_t requested_size; size_t requested_align; + /* The buffer allocator. */ + hurd_slab_allocate_buffer_t allocate_buffer; + + /* The buffer deallocator. */ + hurd_slab_deallocate_buffer_t deallocate_buffer; + /* The constructor. */ hurd_slab_constructor_t constructor; @@ -94,15 +112,21 @@ struct hurd_slab_space /* Static initializer. TYPE is used to get size and alignment of - objects the slab space will be used to allocate. CTOR and DTOR is - constructor and destructor, respectivly. HOOK is passed as user - data to the constructor and destructor. */ -#define HURD_SLAB_SPACE_INITIALIZER(TYPE, CTOR, DTOR, HOOK) \ + objects the slab space will be used to allocate. ALLOCATE_BUFFER + may be NULL in which case mmap is called. DEALLOCATE_BUFFER may be + NULL in which case munmap is called. CTOR and DTOR are the slab's + object constructor and destructor, respectivly and may be NULL if + not required. HOOK is passed as user data to the constructor and + destructor. */ +#define HURD_SLAB_SPACE_INITIALIZER(TYPE, ALLOC, DEALLOC, CTOR, \ + DTOR, HOOK) \ { \ false, \ PTHREAD_MUTEX_INITIALIZER, \ sizeof (TYPE), \ __alignof__ (TYPE), \ + ALLOC, \ + DEALLOC, \ CTOR, \ DTOR, \ HOOK \ @@ -112,9 +136,15 @@ struct hurd_slab_space /* Create a new slab space with the given object size, alignment, - constructor and destructor. ALIGNMENT can be zero. HOOK is passed - as the first argument to the constructor and destructor. */ + constructor and destructor. ALIGNMENT can be zero. + ALLOCATE_BUFFER may be NULL in which case mmap is called. + DEALLOCATE_BUFFER may be NULL in which case munmap is called. CTOR + and DTOR are the slabs object constructor and destructor, + respectivly and may be NULL if not required. HOOK is passed as the + first argument to the constructor and destructor. */ error_t hurd_slab_create (size_t size, size_t alignment, + hurd_slab_allocate_buffer_t allocate_buffer, + hurd_slab_deallocate_buffer_t deallocate_buffer, hurd_slab_constructor_t constructor, hurd_slab_destructor_t destructor, void *hook, @@ -122,6 +152,8 @@ error_t hurd_slab_create (size_t size, size_t alignment, /* Like hurd_slab_create, but does not allocate storage for the slab. */ error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, + hurd_slab_allocate_buffer_t allocate_buffer, + hurd_slab_deallocate_buffer_t deallocate_buffer, hurd_slab_constructor_t constructor, hurd_slab_destructor_t destructor, void *hook); diff --git a/task/ChangeLog b/task/ChangeLog index b24feaa..5bbd0bf 100644 --- a/task/ChangeLog +++ b/task/ChangeLog @@ -1,3 +1,9 @@ +2005-01-07 Neal H. Walfield <neal@gnu.org> + + * thread.c (threads): Supply the allocate_buffer and + deallocate_buffer arguments to HURD_SLAB_SPACE_INITIALIZER to + conform with the new semantics. + 2004-12-01 Neal H. Walfield <neal@gnu.org> * physmem-user.h (physmem_map): Change CONT from a hurd_cap_id_t diff --git a/task/thread.c b/task/thread.c index a720854..b2b4e0e 100644 --- a/task/thread.c +++ b/task/thread.c @@ -1,5 +1,5 @@ /* thread.c - Manage threads. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. Written by Marcus Brinkmann. This file is part of the GNU Hurd. @@ -49,8 +49,8 @@ thread_constructor (void *hook, void *buffer) place where we keep track of used and free thread IDs, it must never be reaped (so no destructor is needed). */ static struct hurd_slab_space threads - = HURD_SLAB_SPACE_INITIALIZER (struct thread, thread_constructor, - NULL, NULL); + = HURD_SLAB_SPACE_INITIALIZER (struct thread, NULL, NULL, + thread_constructor, NULL, NULL); /* The lock protecting the threads slab. */ static pthread_mutex_t threads_lock = PTHREAD_MUTEX_INITIALIZER; |