fixed a bug regarding lazy sweeping in moo_allocbytes

This commit is contained in:
hyunghwan.chung 2020-11-28 15:56:24 +00:00
parent 87afd9354d
commit 7d7bedc2bb
4 changed files with 23 additions and 7 deletions

View File

@ -6355,10 +6355,12 @@ int moo_execute (moo_t* moo)
moo->proc_switched = 0; moo->proc_switched = 0;
moo->abort_req = 0; moo->abort_req = 0;
moo->gci.lazy_sweep = 1; /* TODO: make it configurable?? */
//moo->gci.lazy_sweep = 1;
n = __execute (moo); n = __execute (moo);
moo->gci.lazy_sweep = 0;
vm_cleanup (moo); vm_cleanup (moo);
moo->log.default_type_mask = log_default_type_mask; moo->log.default_type_mask = log_default_type_mask;

View File

@ -1003,7 +1003,6 @@ void moo_gc_ms_sweep_lazy (moo_t* moo, moo_oow_t allocsize)
freed_size = 0; freed_size = 0;
//printf ("starting lazy sweep...gci.ls.curr [%p]\n", moo->gci.ls.curr);
prev = moo->gci.ls.prev; prev = moo->gci.ls.prev;
curr = moo->gci.ls.curr; curr = moo->gci.ls.curr;
@ -1031,10 +1030,8 @@ void moo_gc_ms_sweep_lazy (moo_t* moo, moo_oow_t allocsize)
if (freed_size > allocsize) /* TODO: can it secure large enough space? */ if (freed_size > allocsize) /* TODO: can it secure large enough space? */
{ {
//printf ("stopping lazy sweeping after %lu free, allocsize %lu\n", (unsigned long int)freed_size, (unsigned long int)allocsize);
moo->gci.ls.curr = next; /* let the next lazy sweeping begin at this point */
moo->gci.ls.prev = prev; moo->gci.ls.prev = prev;
//printf ("finished lazy sweep...\n"); moo->gci.ls.curr = next; /* let the next lazy sweeping begin at this point */
return; return;
} }
} }
@ -1043,7 +1040,6 @@ void moo_gc_ms_sweep_lazy (moo_t* moo, moo_oow_t allocsize)
} }
moo->gci.ls.curr = MOO_NULL; moo->gci.ls.curr = MOO_NULL;
//printf ("finished lazy sweep...\n");
} }
static MOO_INLINE void gc_ms_sweep (moo_t* moo) static MOO_INLINE void gc_ms_sweep (moo_t* moo)
@ -1075,7 +1071,6 @@ static MOO_INLINE void gc_ms_sweep (moo_t* moo)
curr = next; curr = next;
} }
printf ("finised full sweep...\n");
moo->gci.ls.curr = MOO_NULL; moo->gci.ls.curr = MOO_NULL;
} }
#endif #endif
@ -1397,6 +1392,8 @@ void moo_gc (moo_t* moo, int full)
#if defined(MOO_ENABLE_GC_MARK_SWEEP) #if defined(MOO_ENABLE_GC_MARK_SWEEP)
if (moo->gc_type == MOO_GC_TYPE_MARK_SWEEP) if (moo->gc_type == MOO_GC_TYPE_MARK_SWEEP)
{ {
if (moo->gci.lazy_sweep) moo_gc_ms_sweep_lazy (moo, MOO_TYPE_MAX(moo_oow_t));
MOO_LOG1 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Starting GC (mark-sweep) - gci.bsz = %zu\n", moo->gci.bsz); MOO_LOG1 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Starting GC (mark-sweep) - gci.bsz = %zu\n", moo->gci.bsz);
moo->gci.stack.len = 0; moo->gci.stack.len = 0;
@ -1405,6 +1402,9 @@ void moo_gc (moo_t* moo, int full)
if (!full && moo->gci.lazy_sweep) if (!full && moo->gci.lazy_sweep)
{ {
/* set the lazy sweeping point to the head of the allocated blocks.
* hawk_allocbytes() updates moo->gci.ls.prev if it is called while
* moo->gci.ls.curr stays at moo->gci.b */
moo->gci.ls.prev = MOO_NULL; moo->gci.ls.prev = MOO_NULL;
moo->gci.ls.curr = moo->gci.b; moo->gci.ls.curr = moo->gci.b;
} }

View File

@ -79,6 +79,14 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
} }
} }
if (moo->gci.lazy_sweep && moo->gci.ls.curr == moo->gci.b)
{
/* if the lazy sweeping point is at the beginning of the allocation block,
* moo->gc.ls.prev must get updated */
MOO_ASSERT (moo, moo->gci.ls.prev == MOO_NULL);
moo->gci.ls.prev = gch;
}
gch->next = moo->gci.b; gch->next = moo->gci.b;
moo->gci.b = gch; moo->gci.b = gch;
moo->gci.bsz += size; moo->gci.bsz += size;

View File

@ -236,6 +236,12 @@ int moo_xma_init (moo_xma_t* xma, moo_mmgr_t* mmgr, void* zoneptr, moo_oow_t zon
internal = 1; /* internally created. must be freed upon moo_xma_fini() */ internal = 1; /* internally created. must be freed upon moo_xma_fini() */
} }
else if (zonesize < FBLKMINSIZE)
{
/* the zone size is too small for an externally allocated zone. */
/* TODO: difference error code from memory allocation failure.. this is not really memory shortage */
return -1;
}
first = (moo_xma_fblk_t*)zoneptr; first = (moo_xma_fblk_t*)zoneptr;