diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2005-05-20 19:15:41 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2005-05-20 19:15:41 +0000 |
commit | 80f2885b70bca394c002241c119a0fca7add2a42 (patch) | |
tree | 59dfc9a04bbf39cd637826ade7fc51e2a5c8a37f /cpukit/rtems/include | |
parent | 2005-05-20 Joel Sherrill <joel@OARcorp.com> (diff) | |
download | rtems-80f2885b70bca394c002241c119a0fca7add2a42.tar.bz2 |
2005-05-14 Sergei Organov <osv@topconrd.ru>
PR 746/rtems
Optimize realloc(). The problem is that realloc() can neither grow
nor shrink efficiently the current memory region without support
from underlying heap/region modules. The patch introduces one new
routine for each of heap and region modules, _Heap_Resize_block(),
and rtems_region_resize_segment(), respectively, and uses the
latter to optimize realloc().
The implementation of _Heap_Resize_block() lead to changing of the
heap allocation strategy: now the heap manager, when splits larger
free block into used and new free parts, makes the first part of
the block used, not the last one as it was before. Due to this new
strategy, _Heap_Resize_block() never needs to change the user
pointer.
Caveat: unlike previous heap implementation, first few bytes of
the contents of the memory allocated from the heap are now almost
never all zero. This can trigger bugs in client code that have not
been visible before this patch.
* libcsupport/src/malloc.c (realloc): try to resize segment in
place using new rtems_region_resize_segment() routine before
falling back to the malloc()/free() method.
* score/src/heap.c:
(_Heap_Initialize): change initial heap layout to reflect new
allocation strategy of using of the lower part of a previously
free block when splitting it for the purpose of allocation.
(_Heap_Block_allocate): when split, make the lower part used, and
leave the upper part free. Return type changed from Heap_Block* to
uint32_t.
* score/include/rtems/score/heap.h:
(Heap_Statistics): added 'resizes' field.
(Heap_Resize_status): new enum.
(_Heap_Resize_block): new routine.
(_Heap_Block_allocate): return type changed from Heap_Block* to
uint32_t.
* score/src/heapwalk.c: reflect new heap layout in checks.
* score/src/heapsizeofuserarea.c: more assertions added.
* score/src/heapresizeblock.c: new file.
(_Heap_Resize_block): new routine.
* score/src/heapfree.c: reverse the checks _Heap_Is_block_in() and
_Heap_Is_prev_used() on entry to be in this order.
* score/src/heapallocate.c, score/src/heapallocatealigned.c:
ignore return value of _Heap_Block_allocate().
* score/Makefile.am (HEAP_C_FILES): added src/heapresizeblock.c.
* rtems/include/rtems/rtems/region.h:
(rtems_region_resize_segment): new interface routine.
(_Region_Process_queue): new internal routine called from
rtems_region_resize_segment() and rtems_region_return_segment().
* rtems/src/regionreturnsegment.c: move queue management code into
the new internal routine _Region_Process_queue() and call it.
* rtems/src/regionresizesegment.c: new file.
(rtems_region_resize_segment): new interface routine.
* rtems/src/regionprocessqueue.c: new file.
(_Region_Process_queue): new internal routine containing queue
management code factored out from 'regionreturnsegment.c'.
* rtems/Makefile.am (REGION_C_FILES): Added
src/regionresizesegment.c, and src/regionprocessqueue.c.
* ada/rtems.adb, ada/rtems.ads: Added Region_Resize_Segment.
Diffstat (limited to 'cpukit/rtems/include')
-rw-r--r-- | cpukit/rtems/include/rtems/rtems/region.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cpukit/rtems/include/rtems/rtems/region.h b/cpukit/rtems/include/rtems/rtems/region.h index a27dd7879b..9c8a0cffa9 100644 --- a/cpukit/rtems/include/rtems/rtems/region.h +++ b/cpukit/rtems/include/rtems/rtems/region.h @@ -232,8 +232,39 @@ rtems_status_code rtems_region_return_segment( void *segment ); +/* + * rtems_region_resize_segment + * + * DESCRIPTION: + * + * This routine implements the rtems_region_resize_segment directive. It + * tries to resize segment in the region associated with 'id' to the new size + * 'size' in place. The first 'size' or old size bytes of the segment + * (whatever is less) are guaranteed to remain unmodified. The segment must + * have been previously allocated from the same region. If resizing the + * segment results in enough memory being available to satisfy the + * rtems_region_get_segment of the first blocked task, then that task and as + * many subsequent tasks as possible will be unblocked with their requests + * satisfied. + * Returns: + * RTEMS_SUCCESSFUL - operation successful + * RTEMS_UNSATISFIED - the segment can't be resized in place + * any other code - failure. + * On RTEMS_SUCCESSFUL or RTEMS_UNSATISFIED exit it returns into the + * 'old_size' the old size in bytes of the user memory area of the specified + * segment. + */ + +rtems_status_code rtems_region_resize_segment( + Objects_Id id, + void *segment, + size_t size, + size_t *old_size +); + #ifndef __RTEMS_APPLICATION__ #include <rtems/rtems/region.inl> +extern void _Region_Process_queue(Region_Control *the_region); #endif #if defined(RTEMS_MULTIPROCESSING) #include <rtems/rtems/regionmp.h> |