Check-in Number:
|
5166 | |
Date: |
2005-Sep-02 21:50:34 (local)
2005-Sep-02 19:50:34 (UTC) |
User: | rse |
Branch: | |
Comment: |
Optimize insertion of free memory chunks by merging with
the spare area if possible to decrease memory fragmentation. |
Tickets: |
#63 | |
Fragmentation of memory could be avoided by merging with spare block |
|
Inspections: |
|
Files: |
|
ossp-pkg/mm/ChangeLog 1.48 -> 1.49
--- ChangeLog 2004/11/15 16:48:06 1.48
+++ ChangeLog 2005/09/02 19:50:34 1.49
@@ -11,6 +11,10 @@
Changes between 1.3.1 and 1.3.2 (12-Sep-2003 to xx-Nov-2004)
+ *) Optimize insertion of free memory chunks by merging with
+ the spare area if possible to decrease memory fragmentation.
+ [<gennadyd@yahoo.com>]
+
*) Fix mm_realloc() function: If the memory chunk passed to mm_realloc()
can't be extended and a new chunk must be allocated, the old memory
is copied into the new chunk with a call to memcpy(3). However, the
|
|
ossp-pkg/mm/mm_alloc.c 1.20 -> 1.21
--- mm_alloc.c 2004/11/15 16:48:06 1.20
+++ mm_alloc.c 2005/09/02 19:50:34 1.21
@@ -188,13 +188,17 @@
{
mem_chunk *mc;
mem_chunk *mcPrev;
+ mem_chunk *mcPrevPrev;
mem_chunk *mcNext;
if (!mm_core_lock((void *)mm, MM_LOCK_RW))
return;
mc = &(mm->mp_freechunks);
- while (mc->mc_u.mc_next != NULL && (char *)(mc->mc_u.mc_next) < (char *)mcInsert)
+ mcPrevPrev = mc;
+ while (mc->mc_u.mc_next != NULL && (char *)(mc->mc_u.mc_next) < (char *)mcInsert) {
+ mcPrevPrev = mc;
mc = mc->mc_u.mc_next;
+ }
mcPrev = mc;
mcNext = mc->mc_u.mc_next;
if (mcPrev == mcInsert || mcNext == mcInsert) {
@@ -209,6 +213,13 @@
mcPrev->mc_u.mc_next = mcNext->mc_u.mc_next;
mm->mp_freechunks.mc_usize -= 1;
}
+ else if ((char *)mcPrev+(mcPrev->mc_size) == (char *)mcInsert &&
+ (char *)mcInsert+(mcInsert->mc_size) == ((char *)mm + mm->mp_offset)) {
+ /* merge with previous and spare block (to increase spare area) */
+ mcPrevPrev->mc_u.mc_next = mcPrev->mc_u.mc_next;
+ mm->mp_offset -= (mcInsert->mc_size + mcPrev->mc_size);
+ mm->mp_freechunks.mc_usize -= 1;
+ }
else if ((char *)mcPrev+(mcPrev->mc_size) == (char *)mcInsert) {
/* merge with previous chunk */
mcPrev->mc_size += mcInsert->mc_size;
@@ -219,6 +230,10 @@
mcInsert->mc_u.mc_next = mcNext->mc_u.mc_next;
mcPrev->mc_u.mc_next = mcInsert;
}
+ else if ((char *)mcInsert+(mcInsert->mc_size) == ((char *)mm + mm->mp_offset)) {
+ /* merge with spare block (to increase spare area) */
+ mm->mp_offset -= mcInsert->mc_size;
+ }
else {
/* no merging possible, so insert as new chunk */
mcInsert->mc_u.mc_next = mcNext;
|
|