From 494dbc2269c950e8edda4a6a841771a256604d7f Mon Sep 17 00:00:00 2001 From: dryman Date: Sat, 25 Mar 2017 22:06:25 -0700 Subject: [PATCH 1/6] OPIC-34 refactored USpanInit and HPageInit --- src/opic/malloc/allocator.c | 4 +-- src/opic/malloc/allocator_test.c | 22 +++++++------- src/opic/malloc/deallocator_test.c | 49 +++++++++++++++++++++--------- src/opic/malloc/init_helper.c | 10 ++---- src/opic/malloc/init_helper.h | 4 +-- src/opic/malloc/init_helper_test.c | 22 +++++++------- 6 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/opic/malloc/allocator.c b/src/opic/malloc/allocator.c index cf4ec6e..71fe4df 100644 --- a/src/opic/malloc/allocator.c +++ b/src/opic/malloc/allocator.c @@ -208,7 +208,7 @@ DispatchUSpanForAddr(OPHeapCtx* ctx, Magic uspan_magic, void** addr) atomic_exit_check_out(&ctx->uqueue->pcard); return false; } - USpanInit(ctx, uspan_magic, spage_cnt); + USpanInit(ctx->sspan.uspan, uspan_magic, spage_cnt); EnqueueUSpan(ctx->uqueue, ctx->sspan.uspan); atomic_exit_check_out(&ctx->uqueue->pcard); goto retry; @@ -252,7 +252,7 @@ DispatchHPageForSSpan(OPHeapCtx* ctx, Magic magic, unsigned int spage_cnt, atomic_exit_check_out(&ctx->hqueue->pcard); return false; } - HPageInit(ctx, magic); + HPageInit(ctx->hspan.hpage, magic); EnqueueHPage(ctx->hqueue, ctx->hspan.hpage); atomic_exit_check_out(&ctx->hqueue->pcard); goto retry; diff --git a/src/opic/malloc/allocator_test.c b/src/opic/malloc/allocator_test.c index 413e336..86e3b10 100644 --- a/src/opic/malloc/allocator_test.c +++ b/src/opic/malloc/allocator_test.c @@ -328,8 +328,8 @@ test_HPageObtainUSpan(void** context) assert_true(OPHeapObtainHPage(heap, &ctx)); ctx.hqueue = &heap->raw_type.hpage_queue; magic.raw_hpage.pattern = RAW_HPAGE_PATTERN; - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); EnqueueHPage(ctx.hqueue, hpage); assert_ptr_equal(hpage, ctx.hqueue->hpage); assert_int_equal(SPAN_ENQUEUED, hpage->state); @@ -406,8 +406,8 @@ test_HPageObtainUSpan(void** context) // get second hpage to test uspan offset // The offset should be sizeof(HugePage) assert_true(OPHeapObtainHPage(heap, &ctx)); - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); EnqueueHPage(ctx.hqueue, hpage); assert_ptr_equal(hpage, ctx.hqueue->hpage); assert_int_equal(SPAN_ENQUEUED, hpage->state); @@ -424,8 +424,8 @@ test_HPageObtainUSpan(void** context) // get third hpage to test use_full_span logic assert_true(OPHeapObtainHPage(heap, &ctx)); - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); EnqueueHPage(ctx.hqueue, hpage); assert_int_equal(SPAN_ENQUEUED, hpage->state); assert_ptr_equal(hpage, ctx.hqueue->hpage->next); @@ -458,8 +458,8 @@ test_HPageObtainSSpan(void** context) assert_true(OPHeapObtainHPage(heap, &ctx)); ctx.hqueue = &heap->raw_type.hpage_queue; magic.raw_hpage.pattern = RAW_HPAGE_PATTERN; - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); EnqueueHPage(ctx.hqueue, hpage); assert_ptr_equal(hpage, ctx.hqueue->hpage); assert_int_equal(SPAN_ENQUEUED, hpage->state); @@ -502,8 +502,8 @@ test_HPageObtainSSpan(void** context) // Second HPage assert_true(OPHeapObtainHPage(heap, &ctx)); - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); EnqueueHPage(ctx.hqueue, hpage); assert_ptr_equal(hpage, ctx.hqueue->hpage); assert_int_equal(SPAN_ENQUEUED, hpage->state); @@ -566,8 +566,8 @@ test_USpanObtainAddr(void** context) umagic.raw_uspan.thread_id = 0; ctx.uqueue = &heap->raw_type.uspan_queue[0][0]; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + SPAGE_SIZE; - USpanInit(&ctx, umagic, 1); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 1); EnqueueUSpan(ctx.uqueue, uspan); assert_ptr_equal(uspan, ctx.uqueue->uspan); assert_int_equal(SPAN_ENQUEUED, uspan->state); @@ -597,8 +597,8 @@ test_USpanObtainAddr(void** context) * number of objects: 256 - 13 = 243 */ ctx.sspan.uintptr = heap_base + HPAGE_SIZE + sizeof(HugePage); - USpanInit(&ctx, umagic, 1); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 1); EnqueueUSpan(ctx.uqueue, uspan); assert_ptr_equal(uspan, ctx.uqueue->uspan); assert_int_equal(SPAN_ENQUEUED, uspan->state); @@ -627,8 +627,8 @@ test_USpanObtainAddr(void** context) */ umagic.raw_uspan.obj_size = 24; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + 2 * SPAGE_SIZE; - USpanInit(&ctx, umagic, 1); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 1); EnqueueUSpan(ctx.uqueue, uspan); assert_ptr_equal(uspan, ctx.uqueue->uspan); assert_int_equal(SPAN_ENQUEUED, uspan->state); @@ -661,7 +661,7 @@ test_USpanObtainAddr(void** context) umagic.typed_uspan.type_alias = 0; ctx.uqueue = &heap->type_alias[0].uspan_queue[0]; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + 3 * SPAGE_SIZE; - USpanInit(&ctx, umagic, 1); + USpanInit(ctx.sspan.uspan, umagic, 1); uspan = ctx.sspan.uspan; EnqueueUSpan(ctx.uqueue, uspan); @@ -711,8 +711,8 @@ test_USpanObtainAddr_Large(void** context) umagic.large_uspan.obj_size = 1024; ctx.uqueue = &heap->raw_type.large_uspan_queue[0]; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + SPAGE_SIZE; - USpanInit(&ctx, umagic, 16); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 16); EnqueueUSpan(ctx.uqueue, uspan); assert_ptr_equal(uspan, ctx.uqueue->uspan); assert_int_equal(SPAN_ENQUEUED, uspan->state); @@ -742,8 +742,8 @@ test_USpanObtainAddr_Large(void** context) umagic.large_uspan.obj_size = 2048; ctx.uqueue = &heap->raw_type.large_uspan_queue[0]; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + 32 * SPAGE_SIZE; - USpanInit(&ctx, umagic, 32); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 32); EnqueueUSpan(ctx.uqueue, uspan); assert_ptr_equal(uspan, ctx.uqueue->uspan); assert_int_equal(SPAN_ENQUEUED, uspan->state); diff --git a/src/opic/malloc/deallocator_test.c b/src/opic/malloc/deallocator_test.c index c3914d2..4bbc436 100644 --- a/src/opic/malloc/deallocator_test.c +++ b/src/opic/malloc/deallocator_test.c @@ -96,14 +96,10 @@ test_OPHeapReleaseHSpan_1Page(void** context) hspan[5].uintptr = heap_base + 65 * HPAGE_SIZE; hspan[6].uintptr = heap_base + 66 * HPAGE_SIZE; hspan[7].uintptr = heap_base + 67 * HPAGE_SIZE; - ctx.hspan = hspan[0]; - HPageInit(&ctx, raw_hpage_magic); - ctx.hspan = hspan[1]; - HPageInit(&ctx, raw_hpage_magic); - ctx.hspan = hspan[2]; - HPageInit(&ctx, typed_hpage_magic); - ctx.hspan = hspan[3]; - HPageInit(&ctx, typed_hpage_magic); + HPageInit(hspan[0].hpage, raw_hpage_magic); + HPageInit(hspan[1].hpage, raw_hpage_magic); + HPageInit(hspan[2].hpage, typed_hpage_magic); + HPageInit(hspan[3].hpage, typed_hpage_magic); *hspan[4].magic = hblob_magic; *hspan[5].magic = hblob_magic; *hspan[6].magic = hblob_magic; @@ -349,8 +345,8 @@ test_HPageReleaseSSpan(void** context) hmagic.raw_hpage.pattern = RAW_HPAGE_PATTERN; ctx.hqueue = &heap->raw_type.hpage_queue; ctx.hspan.uintptr = heap_base + HPAGE_SIZE; - HPageInit(&ctx, hmagic); hpage2 = ctx.hspan.hpage; + HPageInit(hpage2, hmagic); hqueue = ctx.hqueue; memset(hpage2->occupy_bmap, 0xFF, 8 * sizeof(uint64_t)); @@ -361,8 +357,8 @@ test_HPageReleaseSSpan(void** context) umagic.raw_uspan.obj_size = 24; umagic.raw_uspan.thread_id = 0; ctx.sspan.uintptr = heap_base + HPAGE_SIZE + sizeof(HugePage); - USpanInit(&ctx, umagic, 1); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 1); // Enqueue hpage if it were dequeued memset(occupy_bmap, 0xFF, sizeof(occupy_bmap)); @@ -380,8 +376,8 @@ test_HPageReleaseSSpan(void** context) // Enqueue another hpage which precedes previous one. ctx.hspan.hpage = &heap->hpage; - HPageInit(&ctx, hmagic); hpage1 = ctx.hspan.hpage; + HPageInit(hpage1, hmagic); hpage1->state = SPAN_DEQUEUED; hpage1->occupy_bmap[2] = 0x01UL; hpage1->header_bmap[2] = 0x01UL; @@ -406,8 +402,8 @@ test_HPageReleaseSSpan(void** context) // Setup third hpage and test releasing it ctx.hspan.uintptr = heap_base + 2 * HPAGE_SIZE; - HPageInit(&ctx, hmagic); hpage3 = ctx.hspan.hpage; + HPageInit(hpage3, hmagic); EnqueueHPage(ctx.hqueue, hpage3); assert_ptr_equal(hpage1, hqueue->hpage); assert_ptr_equal(hpage2, hqueue->hpage->next); @@ -415,8 +411,8 @@ test_HPageReleaseSSpan(void** context) umagic.large_uspan.pattern = LARGE_USPAN_PATTERN; umagic.large_uspan.obj_size = 2048; ctx.sspan.uintptr = heap_base + 2 * HPAGE_SIZE + sizeof(HugePage); - USpanInit(&ctx, umagic, 128); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 128); hpage3->occupy_bmap[0] = ~0UL; hpage3->occupy_bmap[1] = ~0UL; hpage3->header_bmap[0] = 1UL; @@ -436,8 +432,8 @@ test_HPageReleaseSSpan(void** context) umagic.typed_uspan.obj_size = 2; umagic.typed_uspan.thread_id = 0; ctx.sspan.uintptr = heap_base + 128 * SPAGE_SIZE; - USpanInit(&ctx, umagic, 1); uspan = ctx.sspan.uspan; + USpanInit(uspan, umagic, 1); HPageReleaseSSpan(hpage1, uspan); assert_int_equal(0x02UL, heap->occupy_bmap[0]); assert_int_equal(0x02UL, heap->header_bmap[0]); @@ -445,6 +441,31 @@ test_HPageReleaseSSpan(void** context) OPHeapDestroy(heap); } +static void +test_USpanReleaseAddr(void** context) +{ + OPHeap* heap; + SmallSpanPtr sspan1, sspan2, sspan3; + UnarySpanQueue* uqueue; + HugePage *hpage; + uintptr_t heap_base; + OPHeapCtx ctx; + Magic hmagic = {}; + Magic umagic = {}; + uint64_t occupy_bmap[8] = {0}; + uint64_t header_bmap[8] = {0}; + + assert_ture(OPHeapNew(&heap)); + heap_base = (uintptr_t)heap; + + ctx.hspan.uintptr = heap_base + HPAGE_SIZE; + hmagic.raw_hpage.pattern = RAW_HPAGE_PATTERN; + hpage = ctx.hspan.hpage; + HPageInit(hpage, hmagic); + hpage->occupy_bmap[0] = 0x0F; + hpage->header_bmap[0] = 0x0F; +} + int main (void) { diff --git a/src/opic/malloc/init_helper.c b/src/opic/malloc/init_helper.c index 2a9057f..278f485 100644 --- a/src/opic/malloc/init_helper.c +++ b/src/opic/malloc/init_helper.c @@ -101,10 +101,8 @@ OPHeapDestroy(OPHeap* heap) } void -HPageInit(OPHeapCtx* ctx, Magic magic) +HPageInit(HugePage* hpage, Magic magic) { - HugePage* hpage; - hpage = ctx->hspan.hpage; hpage->magic = magic; hpage->pcard = 0; HPageEmptiedBMaps(hpage, @@ -123,15 +121,13 @@ HPageInit(OPHeapCtx* ctx, Magic magic) * = 144 + 24 + 256 = 424 bytes */ void -USpanInit(OPHeapCtx* ctx, Magic magic, unsigned int spage_cnt) +USpanInit(UnarySpan* uspan, Magic magic, unsigned int spage_cnt) { - UnarySpan* uspan; uintptr_t uspan_base; unsigned int obj_size, obj_cnt, bitmap_cnt, padding, headroom; size_t container_size, bmap_projection; uint64_t* bmap; - uspan = ctx->sspan.uspan; container_size = (size_t)spage_cnt * SPAGE_SIZE; uspan_base = ObtainSSpanBase(uspan); obj_size = magic.uspan_generic.obj_size < 16 ? @@ -154,7 +150,7 @@ USpanInit(OPHeapCtx* ctx, Magic magic, unsigned int spage_cnt) uspan->obj_cnt = 0; uspan->next = NULL; - bmap = (uint64_t*)(ctx->sspan.uintptr + sizeof(UnarySpan)); + bmap = (uint64_t*)((uintptr_t)uspan + sizeof(UnarySpan)); USpanEmptiedBMap(uspan, bmap); } diff --git a/src/opic/malloc/init_helper.h b/src/opic/malloc/init_helper.h index 33f9879..8e97f10 100644 --- a/src/opic/malloc/init_helper.h +++ b/src/opic/malloc/init_helper.h @@ -65,10 +65,10 @@ bool OPHeapNew(OPHeap** heap_ref); void OPHeapDestroy(OPHeap* heap); -void HPageInit(OPHeapCtx* ctx, Magic magic) +void HPageInit(HugePage* hpage, Magic magic) __attribute__ ((visibility ("internal"))); -void USpanInit(OPHeapCtx* ctx, Magic magic, unsigned int spage_cnt) +void USpanInit(UnarySpan* uspan, Magic magic, unsigned int spage_cnt) __attribute__ ((visibility ("internal"))); void OPHeapEmptiedBMaps(OPHeap* heap, BmapPtr occupy_bmap, BmapPtr header_bmap) diff --git a/src/opic/malloc/init_helper_test.c b/src/opic/malloc/init_helper_test.c index 86fd3a1..24e1eef 100644 --- a/src/opic/malloc/init_helper_test.c +++ b/src/opic/malloc/init_helper_test.c @@ -74,8 +74,8 @@ test_HPageInit(void** context) magic.raw_hpage.pattern = RAW_HPAGE_PATTERN; ctx.hspan.hpage = &heap->hpage; - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); assert_int_equal(magic.int_value, hpage->magic.int_value); assert_int_equal(0, hpage->pcard); @@ -94,8 +94,8 @@ test_HPageInit(void** context) assert_memory_equal(header_bmap, hpage->header_bmap, 8 * sizeof(uint64_t)); ctx.hspan.uintptr = heap_base + HPAGE_SIZE; - HPageInit(&ctx, magic); hpage = ctx.hspan.hpage; + HPageInit(hpage, magic); assert_int_equal(magic.int_value, hpage->magic.int_value); assert_int_equal(0, hpage->pcard); @@ -134,7 +134,7 @@ test_USpanInit_RawTypeSmall(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 16; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(4, uspan->bitmap_cnt); assert_int_equal(4, uspan->bitmap_headroom); @@ -159,7 +159,7 @@ test_USpanInit_RawTypeSmall(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 24; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(3, uspan->bitmap_cnt); assert_int_equal(2, uspan->bitmap_headroom); @@ -205,7 +205,7 @@ test_USpanInit_RawTypeSmall_FstPage(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 16; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(4, uspan->bitmap_cnt); assert_int_equal(13, uspan->bitmap_headroom); @@ -231,7 +231,7 @@ test_USpanInit_RawTypeSmall_FstPage(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 24; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(3, uspan->bitmap_cnt); assert_int_equal(8, uspan->bitmap_headroom); @@ -276,7 +276,7 @@ test_USpanInit_RawTypeLarge(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 1024; - USpanInit(&ctx, magic, 16); + USpanInit(uspan, magic, 16); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(1, uspan->bitmap_cnt); assert_int_equal(1, uspan->bitmap_headroom); @@ -303,7 +303,7 @@ test_USpanInit_RawTypeLarge(void** context) */ magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = 2048; - USpanInit(&ctx, magic, 16); + USpanInit(uspan, magic, 16); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(1, uspan->bitmap_cnt); assert_int_equal(1, uspan->bitmap_headroom); @@ -351,7 +351,7 @@ test_USpanInit_OtherSizes(void** context) magic.typed_uspan.pattern = TYPED_USPAN_PATTERN; magic.typed_uspan.obj_size = 2; magic.typed_uspan.type_alias = 3; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(4, uspan->bitmap_cnt); assert_int_equal(4, uspan->bitmap_headroom); @@ -379,7 +379,7 @@ test_USpanInit_OtherSizes(void** context) magic.typed_uspan.pattern = TYPED_USPAN_PATTERN; magic.typed_uspan.obj_size = 2; magic.typed_uspan.type_alias = 3; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(4, uspan->bitmap_cnt); assert_int_equal(13, uspan->bitmap_headroom); @@ -404,7 +404,7 @@ test_USpanInit_OtherSizes(void** context) */ magic.typed_uspan.pattern = TYPED_USPAN_PATTERN; magic.typed_uspan.obj_size = 100; - USpanInit(&ctx, magic, 1); + USpanInit(uspan, magic, 1); assert_int_equal(magic.int_value, uspan->magic.int_value); assert_int_equal(1, uspan->bitmap_cnt); assert_int_equal(2, uspan->bitmap_headroom); From c7ce640be7657090d268d1e6d81cbd47a4f3234b Mon Sep 17 00:00:00 2001 From: dryman Date: Sat, 25 Mar 2017 23:16:21 -0700 Subject: [PATCH 2/6] OPIC-34 USpanReleaseAddr test --- src/opic/malloc/deallocator.c | 8 +-- src/opic/malloc/deallocator_test.c | 91 ++++++++++++++++++++++++++---- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/src/opic/malloc/deallocator.c b/src/opic/malloc/deallocator.c index 0fd476f..8be0299 100644 --- a/src/opic/malloc/deallocator.c +++ b/src/opic/malloc/deallocator.c @@ -101,10 +101,10 @@ USpanReleaseAddr(UnarySpan* uspan, void* addr) if (obj_size < 16) obj_size = 16; _addr_obj_size = _addr / obj_size; - op_assert(_addr_obj_size > uspan->bitmap_headroom, - "Address %p mapped to bitmap_headroom", addr); - op_assert(_addr_obj_size < uspan->bitmap_cnt * 64UL + uspan->bitmap_headroom, - "Address %p mapped to bitmap_padding", addr); + op_assert(_addr_obj_size >= uspan->bitmap_headroom, + "Address %p mapped to bitmap_headroom\n", addr); + op_assert(_addr_obj_size < uspan->bitmap_cnt * 64UL - uspan->bitmap_padding, + "Address %p mapped to bitmap_padding\n", addr); _addr_bmidx = _addr_obj_size / 64; _addr_bmbit = _addr_obj_size % 64; diff --git a/src/opic/malloc/deallocator_test.c b/src/opic/malloc/deallocator_test.c index 4bbc436..fd50d3b 100644 --- a/src/opic/malloc/deallocator_test.c +++ b/src/opic/malloc/deallocator_test.c @@ -68,7 +68,6 @@ test_OPHeapReleaseHSpan_1Page(void** context) uint64_t occupy_bmap[HPAGE_BMAP_NUM] = {}; uint64_t header_bmap[HPAGE_BMAP_NUM] = {}; HugeSpanPtr hspan[8]; - OPHeapCtx ctx; Magic raw_hpage_magic = {}, typed_hpage_magic = {}, hblob_magic = {}; assert_true(OPHeapNew(&heap)); @@ -446,24 +445,93 @@ test_USpanReleaseAddr(void** context) { OPHeap* heap; SmallSpanPtr sspan1, sspan2, sspan3; - UnarySpanQueue* uqueue; + UnarySpanQueue* uqueue1; + UnarySpanQueue* uqueue2; + UnarySpanQueue* uqueue3; HugePage *hpage; uintptr_t heap_base; - OPHeapCtx ctx; Magic hmagic = {}; - Magic umagic = {}; - uint64_t occupy_bmap[8] = {0}; - uint64_t header_bmap[8] = {0}; + Magic umagic1 = {}; + Magic umagic2 = {}; + Magic umagic3 = {}; + void* addr1; + void* addr2; + OPHeapCtx ctx; - assert_ture(OPHeapNew(&heap)); + assert_true(OPHeapNew(&heap)); heap_base = (uintptr_t)heap; + heap->occupy_bmap[0] = 0x02UL; + heap->header_bmap[0] = 0x02UL; - ctx.hspan.uintptr = heap_base + HPAGE_SIZE; hmagic.raw_hpage.pattern = RAW_HPAGE_PATTERN; - hpage = ctx.hspan.hpage; + hpage = (HugePage*)(heap_base + HPAGE_SIZE); HPageInit(hpage, hmagic); - hpage->occupy_bmap[0] = 0x0F; - hpage->header_bmap[0] = 0x0F; + hpage->occupy_bmap[0] = ~0UL; + hpage->header_bmap[0] = 0x07; + hpage->occupy_bmap[1] = 0x07; + hpage->header_bmap[1] = 0x04; + + sspan1.uintptr = heap_base + HPAGE_SIZE + sizeof(HugePage); + sspan2.uintptr = heap_base + HPAGE_SIZE + SPAGE_SIZE; + sspan3.uintptr = heap_base + HPAGE_SIZE + 2 * SPAGE_SIZE; + umagic1.raw_uspan.pattern = RAW_USPAN_PATTERN; + umagic2.typed_uspan.pattern = TYPED_USPAN_PATTERN; + umagic3.large_uspan.pattern = LARGE_USPAN_PATTERN; + umagic1.raw_uspan.obj_size = 48; + umagic2.typed_uspan.obj_size = 2; + umagic3.large_uspan.obj_size = 2048; + USpanInit(sspan1.uspan, umagic1, 1); + USpanInit(sspan2.uspan, umagic2, 1); + USpanInit(sspan3.uspan, umagic3, 64); + + uqueue1 = &heap->raw_type.uspan_queue[2][0]; + uqueue2 = &heap->type_alias[0].uspan_queue[0]; + uqueue3 = &heap->raw_type.large_uspan_queue[2]; + + ctx.uqueue = uqueue1; + ctx.sspan = sspan1; + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr1)); + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr2)); + sspan1.uspan->state = SPAN_DEQUEUED; + USpanReleaseAddr(sspan1.uspan, addr1); + assert_ptr_equal(sspan1.uspan, uqueue1->uspan); + assert_int_equal(SPAN_ENQUEUED, sspan1.uspan->state); + USpanReleaseAddr(sspan1.uspan, addr2); + assert_ptr_equal(NULL, uqueue1->uspan); + // 7654321076543210 + assert_int_equal(0xFFFFFFFFFFFFFFFEUL, hpage->occupy_bmap[0]); + assert_int_equal(0x06UL, hpage->header_bmap[0]); + + ctx.uqueue = uqueue2; + ctx.sspan = sspan2; + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr1)); + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr2)); + sspan2.uspan->state = SPAN_DEQUEUED; + USpanReleaseAddr(sspan2.uspan, addr1); + assert_ptr_equal(sspan2.uspan, uqueue2->uspan); + assert_int_equal(SPAN_ENQUEUED, sspan2.uspan->state); + USpanReleaseAddr(sspan2.uspan, addr2); + assert_ptr_equal(NULL, uqueue2->uspan); + // 7654321076543210 + assert_int_equal(0xFFFFFFFFFFFFFFFCUL, hpage->occupy_bmap[0]); + assert_int_equal(0x04UL, hpage->header_bmap[0]); + + ctx.uqueue = uqueue3; + ctx.sspan = sspan3; + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr1)); + assert_int_equal(QOP_SUCCESS, USpanObtainAddr(&ctx, &addr2)); + sspan3.uspan->state = SPAN_DEQUEUED; + USpanReleaseAddr(sspan3.uspan, addr1); + assert_ptr_equal(sspan3.uspan, uqueue3->uspan); + assert_int_equal(SPAN_ENQUEUED, sspan3.uspan->state); + USpanReleaseAddr(sspan3.uspan, addr2); + assert_ptr_equal(NULL, uqueue3->uspan); + assert_int_equal(0UL, hpage->occupy_bmap[0]); + assert_int_equal(0UL, hpage->header_bmap[0]); + assert_int_equal(0x04UL, hpage->occupy_bmap[1]); + assert_int_equal(0x04UL, hpage->header_bmap[1]); + + OPHeapDestroy(heap); } int @@ -475,6 +543,7 @@ main (void) cmocka_unit_test(test_OPHeapReleaseHSpan_smallHBlob), cmocka_unit_test(test_OPHeapReleaseHSpan_lageHBlob), cmocka_unit_test(test_HPageReleaseSSpan), + cmocka_unit_test(test_USpanReleaseAddr), }; return cmocka_run_group_tests(deallocator_tests, NULL, NULL); From 17c2038da783d609e7fb7eab422adf2b636e8313 Mon Sep 17 00:00:00 2001 From: dryman Date: Sat, 25 Mar 2017 23:21:20 -0700 Subject: [PATCH 3/6] OPIC-34 remove log4c from OPHeap because log4c uses malloc --- src/opic/malloc/allocator.c | 19 +++---------------- src/opic/malloc/deallocator.c | 9 +++------ src/opic/malloc/init_helper.c | 10 ---------- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/opic/malloc/allocator.c b/src/opic/malloc/allocator.c index 71fe4df..c9163c8 100644 --- a/src/opic/malloc/allocator.c +++ b/src/opic/malloc/allocator.c @@ -56,7 +56,6 @@ #define DISPATCH_ATTEMPT 1024 -OP_LOGGER_FACTORY(logger, "opic.malloc.allocator"); static __thread int thread_id = -1; static a_uint32_t round_robin = 0; @@ -585,9 +584,6 @@ OPHeapObtainHPage(OPHeap* heap, OPHeapCtx* ctx) } } - OP_LOG_WARN(logger, - "Running out of available hpages. Lock to check remaining"); - if (!atomic_book_critical(&heap->pcard)) { atomic_check_out(&heap->pcard); @@ -603,7 +599,6 @@ OPHeapObtainHPage(OPHeap* heap, OPHeapCtx* ctx) if (cmp_result) goto retry; - OP_LOG_ERROR(logger, "No available hpage."); return false; } @@ -664,9 +659,6 @@ OPHeapObtainSmallHBlob(OPHeap* heap, OPHeapCtx* ctx, unsigned int hpage_cnt) } } - OP_LOG_WARN(logger, - "Running out of available hpages. Lock to check remaining"); - if (!atomic_book_critical(&heap->pcard)) { atomic_check_out(&heap->pcard); @@ -692,7 +684,8 @@ OPHeapObtainLargeHBlob(OPHeap* heap, OPHeapCtx* ctx, unsigned int hpage_cnt) while (1) { - if (bmidx_head > HPAGE_BMAP_NUM) goto fail; + if (bmidx_head > HPAGE_BMAP_NUM) + return false; if (occupy_bmap[bmidx_head] & (1UL << 63)) { bmidx_head++; @@ -713,7 +706,7 @@ OPHeapObtainLargeHBlob(OPHeap* heap, OPHeapCtx* ctx, unsigned int hpage_cnt) while (1) { if (bmidx_iter > HPAGE_BMAP_NUM) - goto fail; + return false; if (_hpage_cnt > 64) { if (occupy_bmap[bmidx_iter] != 0UL) @@ -758,12 +751,6 @@ OPHeapObtainLargeHBlob(OPHeap* heap, OPHeapCtx* ctx, unsigned int hpage_cnt) occupy_bmap[bmidx] = ~0UL; } return true; - - fail: - OP_LOG_ERROR(logger, - "No available contiguous hpages for huge page count %d", - hpage_cnt); - return false; } /* op_pspan.c ends here */ diff --git a/src/opic/malloc/deallocator.c b/src/opic/malloc/deallocator.c index 8be0299..232af93 100644 --- a/src/opic/malloc/deallocator.c +++ b/src/opic/malloc/deallocator.c @@ -54,7 +54,6 @@ #include "init_helper.h" #include "lookup_helper.h" -OP_LOGGER_FACTORY(logger, "opic.malloc.deallocator"); void OPDealloc(void* addr) @@ -111,11 +110,9 @@ USpanReleaseAddr(UnarySpan* uspan, void* addr) mask = ~(1UL << _addr_bmbit); old_bmap = atomic_fetch_and_explicit(&bmap[_addr_bmidx], mask, memory_order_release); - if (op_unlikely((old_bmap & (1UL << _addr_bmbit)) == 0)) - { - OP_LOG_ERROR(logger, "Double free address %p", addr); - } - else if (atomic_fetch_sub_explicit(&uspan->obj_cnt, 1, + op_assert(old_bmap & (1UL << _addr_bmbit), + "Double free address %p\n", addr); + if (atomic_fetch_sub_explicit(&uspan->obj_cnt, 1, memory_order_acq_rel) == 1) { if (!atomic_book_critical(&uspan->pcard)) diff --git a/src/opic/malloc/init_helper.c b/src/opic/malloc/init_helper.c index 278f485..2b1765b 100644 --- a/src/opic/malloc/init_helper.c +++ b/src/opic/malloc/init_helper.c @@ -51,7 +51,6 @@ #include "init_helper.h" #include "opic/common/op_log.h" -OP_LOGGER_FACTORY(logger, "opic.malloc.init_helper"); bool OPHeapNew(OPHeap** heap_ref) @@ -61,18 +60,12 @@ OPHeapNew(OPHeap** heap_ref) map_addr = MAP_FAILED; for (int i = 0; i < (1<<15); i++) { - OP_LOG_INFO(logger, - "Attempt to create OPHeap on %p", - addr); map_addr = mmap(addr, OPHEAP_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); if (map_addr != MAP_FAILED) { - OP_LOG_INFO(logger, - "Successfully created OPHeap on %p", - map_addr); *heap_ref = map_addr; memset(*heap_ref, 0, sizeof(OPHeap)); (*heap_ref)->version = OPHEAP_VERSION; @@ -82,14 +75,12 @@ OPHeapNew(OPHeap** heap_ref) else addr += OPHEAP_SIZE; } - OP_LOG_ERROR(logger, "Cannot allocate OPHeap, reached address limit"); return false; } bool OPHeapNewFromFile(OPHeap** heap_ref, FILE fd) { - OP_LOG_ERROR(logger, "Not implemented yet"); return false; } @@ -97,7 +88,6 @@ void OPHeapDestroy(OPHeap* heap) { munmap(heap, OPHEAP_SIZE); - OP_LOG_INFO(logger, "Successfully destroyed OPHeap on %p", heap); } void From b30352e47b8fa9d05ac3ce5b20a80e49bb24db2f Mon Sep 17 00:00:00 2001 From: dryman Date: Sun, 26 Mar 2017 11:43:31 -0700 Subject: [PATCH 4/6] OPIC-34 remove legacy code --- src/opic/malloc/allocator.c | 30 ++- src/opic/malloc/huge_page.c | 281 --------------------- src/opic/malloc/huge_page.h | 79 ------ src/opic/malloc/op_heap.c | 340 -------------------------- src/opic/malloc/op_heap.h | 56 ----- src/opic/malloc/op_heap_internal.h | 376 ----------------------------- src/opic/malloc/op_malloc.c | 38 +-- src/opic/malloc/op_malloc.h | 8 + 8 files changed, 53 insertions(+), 1155 deletions(-) delete mode 100644 src/opic/malloc/huge_page.c delete mode 100644 src/opic/malloc/huge_page.h delete mode 100644 src/opic/malloc/op_heap.c delete mode 100644 src/opic/malloc/op_heap.h delete mode 100644 src/opic/malloc/op_heap_internal.h diff --git a/src/opic/malloc/allocator.c b/src/opic/malloc/allocator.c index c9163c8..61c928e 100644 --- a/src/opic/malloc/allocator.c +++ b/src/opic/malloc/allocator.c @@ -71,7 +71,17 @@ OPMallocRaw(OPHeap* heap, size_t size) } void* -OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) +OPCallocRaw(OPHeap* heap, size_t size) +{ + if (thread_id == -1) + thread_id = atomic_fetch_add_explicit + (&round_robin, 1, memory_order_acquire) % 16; + + return OPCallocRawAdviced(heap, size, thread_id); +} + +void* +OPMallocRawAdviced(OPHeap* heap, size_t size, int advice) { OPHeapCtx ctx; void* addr; @@ -80,7 +90,7 @@ OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) op_assert(size > 0, "malloc size must greater than 0"); - hint %= 16; + advice %= 16; ctx.hqueue = &heap->raw_type.hpage_queue; if (size <= 256) @@ -88,8 +98,8 @@ OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) size_class = round_up_div(size, 16); magic.raw_uspan.pattern = RAW_USPAN_PATTERN; magic.raw_uspan.obj_size = size_class * 16; - magic.raw_uspan.thread_id = hint; - ctx.uqueue = &heap->raw_type.uspan_queue[size_class][hint]; + magic.raw_uspan.thread_id = advice; + ctx.uqueue = &heap->raw_type.uspan_queue[size_class][advice]; if (DispatchUSpanForAddr(&ctx, magic, &addr)) return addr; else @@ -143,6 +153,18 @@ OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) } } +void* +OPCallocRawAdviced(OPHeap* heap, size_t size, int advice) +{ + void* addr; + + addr = OPMallocRawAdviced(heap, size, thread_id); + if (addr) + memset(addr, 0x00, size); + + return addr; +} + bool DispatchUSpanForAddr(OPHeapCtx* ctx, Magic uspan_magic, void** addr) { diff --git a/src/opic/malloc/huge_page.c b/src/opic/malloc/huge_page.c deleted file mode 100644 index 4618454..0000000 --- a/src/opic/malloc/huge_page.c +++ /dev/null @@ -1,281 +0,0 @@ -/* op_vpage.c --- - * - * Filename: op_vpage.c - * Description: - * Author: Felix Chern - * Maintainer: - * Copyright: (c) 2016 Felix Chern - * Created: Tue Oct 11 2016 - * Version: - * Package-Requires: () - * Last-Updated: - * By: - * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * - */ - -/* Commentary: - * - * - * - */ - -/* Change Log: - * - * - */ - -/* This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* Code: */ - - -#include -#include -#include -#include "span.h" -#include "huge_page.h" -#include "opic/common/op_utils.h" - -OP_LOGGER_FACTORY(logger, "opic.malloc.huge_page"); - -void HugePageInit(HugePage* self, Magic magic) -{ - /* - op_assert(((size_t)addr & ((1UL<<21)-1)) == 0, - "HugePage address should align 2MB, but were %p\n", addr); - */ - OPHeap* heap = get_opheap(self); - - memset(&self->occupy_bmap, 0, sizeof(self->occupy_bmap)); - memset(&self->header_bmap, 0, sizeof(self->header_bmap)); - self->magic = magic; - self->next = NULL; - - if (self == heap->first_hpage) - { - int occupied = round_up_div(sizeof(OPHeap), (1UL << 12)); - int i; - for (i = 0; i < occupied/64; i++) - self->occupy_bmap[i] = ~0UL; - self->occupy_bmap[i] |= (1UL << (occupied % 64)) - 1; - } -} - - -bool ObtainUSpan(HugePage* self, - UnarySpan** uspan, - Magic magic, - unsigned int span_cnt) -{ - // In current logic, we can get at most 64 spans.. - op_assert(span_cnt <= 64, - "span_cnt is limited to 64 pages, aka 512KB\n"); - - uint64_t old_bmap, new_bmap; - uintptr_t base; - Magic magic = self->magic; - OPHeap* heap = get_opheap(self); - a_int16_t* hpage_queue_pcard; - HugePage** hpage_queue; - - while (1) - { - base = self == heap->first_hpage ? (uintptr_t)heap : (uintptr_t)self; - if (!atomic_check_in(&self->pcard)) - return false; - for (int i = 0; i < 8; i++) - { - old_bmap = atomic_load_explicit(&self->occupy_bmap[i], - memory_order_relaxed); - /* Unlike uspan, we don't capture the item count in - * huge span. In uspan we can use the count to show - * if the span is available for allocation, because - * the empty spot is guaranteed to present. In huge page, - * however, even if the required space is less than the - * count, we may not have enough contiguous space to allocate. - */ - while(1) - { - if (old_bmap == ~0UL) break; - int pos = fftstr0l(old_bmap, span_cnt); - if (pos == -1) break; - new_bmap = old_bmap | ((1UL << span_cnt)-1) << pos; - - if (atomic_compare_exchange_weak_explicit - (&self->occupy_bmap[i], &old_bmap, new_bmap, - memory_order_acquire, - memory_order_relaxed)) - { - *uspan = (UnarySpan*)(base + ((i*64 + pos) << 12)); - if (i == 0 && pos == 0) - USpanInit(*uspan, magic, - (span_cnt << 12) - sizeof(HugePage)); - else - USpanInit(*uspan, magic, span_cnt << 12); - atomic_fetch_or_explicit(&self->header_bmap[i], 1UL << pos, - memory_order_release); - atomic_check_out(&self->pcard); - return true; - } - } - } - atomic_check_out(&self->pcard); - - if (magic.generic.pattern == RAW_HPAGE_PATTERN) - { - hpage_queue_pcard = &heap->raw_type.hpage_pcard; - hpage_queue = &heap->raw_type.hpage; - } - else - { - TypeAlias* ta = &heap->type_alias[magic.typed_hpage.type_alias]; - hpage_queue_pcard = &ta->hpage_pcard; - hpage_queue = &ta->hpage; - } - if (!atomic_book_critical(hpage_queue_pcard)) - return false; - atomic_enter_critical(hpage_queue_pcard); - dequeue_hpage(hpage_queue, self); - - // If the next page is available, use it - if (*hpage_queue) - { - self = *hpage_queue; - atomic_exit_critical(hpage_queue_pcard); - continue; - } - // else insert a new hpage - for (int i = 0; i < 10; i++) - { - if (ObtainHPage(heap, &self, magic)) - goto obtain_hpage_success; - } - return false; - - obtain_hpage_success: - enqueue_hpage(hpage_queue, self); - atomic_exit_critical(hpage_queue_pcard); - // continue with new self - } -} - -BitMapState HPageFree(HugePage* self, void* addr) -{ - OPHeap* heap = get_opheap(self); - bool is_first_hpage = self == heap->first_hpage; - uintptr_t base = is_first_hpage ? (uintptr_t)heap : (uintptr_t)self; - ptrdiff_t diff = (uintptr_t)addr - base; - UnarySpan* span; - int page_idx = diff >> 12; - int span_header_idx; - uint64_t header_mask, occupy_mask; - size_t span_size; - - // TODO: this implementation is assuming pspan can only be - // UnaryPSpan, but we might have Varying PSpan (alloc multiple - // element at same time), and Array PSpan (array of objects cross - // multiple pages) in near future. - - // Do we really need to check in? - while (!atomic_check_in(&self->punch_card)) - ; - - - if (page_idx == 0) - { - span = base + sizeof(HugePage); - header_mask = ~1UL; - span_header_idx = 0; - } - else - { - uint64_t bitmap = atomic_load_explicit(&self->header_bmap[page_idx >> 6], - memory_order_relaxed); - uint64_t clear_low = bitmap & ~((1UL << page_idx % 64)-1); - span_header_idx = ((page_idx >> 6) << 6) + __builtin_ctzl(clear_low); - span = base + (span_header_idx << 12); - header_mask = ~(clear_low & (~(clear_low) + 1)); - } - - if (USpanFree(span, addr) == BM_NORMAL) - return BM_NORMAL; - - - /*** PSpan is freed. Start critical section ***/ - - // First exclude access - /* int8_t expected_refcnt = 0; */ - /* while (!atomic_compare_exchange_weak_explicit */ - /* (&self->refcnt[span_header_idx], */ - /* &expected_refcnt, CHAR_MIN, */ - /* memory_order_acquire, */ - /* memory_order_relaxed)) */ - /* expected_refcnt = 0; */ - - atomic_fetch_and_explicit(&self->header_bmap[page_idx >> 6], header_mask, - memory_order_relaxed); - - // need to determine span type.. - span_size = span->magic.typed_uspan.obj_size* - (64*span->bitmap_cnt - span->bitmap_padding); - // first occupy bitmap is different - if (page_idx == 0) span_size += sizeof(HugePage); - op_assert((span_size & ((1UL<<12)-1))==0, - "span size should align page, but were %zu", span_size); - occupy_mask = ~(((1UL << (span_size >> 12))-1) << span_header_idx); - - // Release semantic to ensure header unmark happens before occupy unmark - atomic_fetch_and_explicit(&self->occupy_bmap[page_idx >> 6], occupy_mask, - memory_order_release); - - if (atomic_load_explicit(&self->occupy_bmap[page_idx >> 6], - memory_order_relaxed)) - return false; - - - uint64_t expected_empty = 0UL; - int iter = 0; - - for (iter = 0; iter < 8; iter++) - { - expected_empty = 0UL; - if (!atomic_compare_exchange_strong_explicit - (&self->occupy_bmap[iter], &expected_empty, ~0UL, - memory_order_acquire, - memory_order_relaxed)) - goto catch_nonempty_exception; - } - - return true; - - catch_nonempty_exception: - - for (int i = 0; i < iter; i++) - atomic_store_explicit(&self->occupy_bmap[i], 0UL, - memory_order_release); - - return false; -} - -void HPageFreeUSpan(HugePage* self, void* addr) -{ -} - -/* op_vpage.c ends here */ diff --git a/src/opic/malloc/huge_page.h b/src/opic/malloc/huge_page.h deleted file mode 100644 index 0d5e83a..0000000 --- a/src/opic/malloc/huge_page.h +++ /dev/null @@ -1,79 +0,0 @@ -/* huge_page.h --- - * - * Filename: huge_page.h - * Description: - * Author: Felix Chern - * Maintainer: - * Copyright: (c) 2016 Felix Chern - * Created: Sat Oct 22, 2016 - * Version: - * Package-Requires: () - * Last-Updated: - * By: - * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * - */ - -/* Commentary: - * - * - * - */ - -/* Change Log: - * - * - */ - -/* This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* Code: */ - -#ifndef HUGE_PAGE_H -#define HUGE_PAGE_H 1 - -#include -#include -#include -#include "opic/common/op_macros.h" -#include "opic/common/op_assert.h" -#include "opic/common/op_log.h" -#include "malloc_internal.h" -#include - -OP_BEGIN_DECLS - - -HugePage* HugePageInit(void* addr, Magic magic) - __attribute__((nonnull)); - -UnarySpan* ObtainUSpan(HugePage* self, - Magic magic, - unsigned int span_cnt) - __attribute__((nonnull)); - -FreeStatus HugePageFree(HugePage* self, void* addr) - __attribute__((nonnull)); - - -OP_END_DECLS - -#endif - -/* huge_page.h ends here */ diff --git a/src/opic/malloc/op_heap.c b/src/opic/malloc/op_heap.c deleted file mode 100644 index 999f2aa..0000000 --- a/src/opic/malloc/op_heap.c +++ /dev/null @@ -1,340 +0,0 @@ -/* op_heap.c --- - * - * Filename: op_heap.c - * Description: - * Author: Felix Chern - * Maintainer: - * Copyright: (c) 2016 Felix Chern - * Created: Sat Oct 22, 2016 - * Version: - * Package-Requires: () - * Last-Updated: - * By: - * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * - */ - -/* Commentary: - * - * - * - */ - -/* Change Log: - * - * - */ - -/* This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* Code: */ - -#include "op_heap.h" -#include "op_heap_internal.h" -#include "span.h" -#include "huge_page.h" -#include -#include -#include - - -typedef struct RawType RawType; -typedef struct TypeAlias TypeAlias; - -static __thread int thread_id = -1; -static atomic_uint round_robin = 0; - -OP_LOGGER_FACTORY(logger, "opic.malloc.op_heap"); - - - -int OPHeapCreate(OPHeap** heap_ref) -{ - ptrdiff_t offset = OPHEAP_SIZE; - void* addr = NULL + offset; - void* map_addr = MAP_FAILED; - OPHeap* self; - for (int i = 0; i < (1<<15); i++) - { - OP_LOG_INFO(logger, - "Attempt to create OPHeap on %p", - addr); - map_addr = mmap(addr, OPHEAP_SIZE, - PROT_READ | PROT_WRITE, - MAP_ANON | MAP_PRIVATE | MAP_FIXED, - -1, 0); - if (map_addr != MAP_FAILED) - { - OP_LOG_INFO(logger, - "Successfully created OPHeap on %p", - map_addr); - *heap_ref = map_addr; - self = *heap_ref; - goto init_opheap; - } - else - addr += OPHEAP_SIZE; - } - OP_LOG_ERROR(logger, - "Cannot allocate OPHeap, reached address limit"); - return -1; - - init_opheap: - memset(self, 0, sizeof(OPHeap)); - // TODO assign first hugepage to raw - atomic_store_explicit(&self->occupy_bmap[0], 1, memory_order_relaxed); - atomic_store_explicit(&self->header_bmap[0], 1, memory_order_relaxed); - return 0; -} - -void* OPAllocRaw(OPHeap* self, size_t size) -{ - if (thread_id == -1) - thread_id = atomic_fetch_add_explicit - (&round_robin, 1, memory_order_acquire) % 16; - - int tid = thread_id; - void* addr = NULL; - - if (size <= 256) - { - int size_class = (int)(size >> 4); - size_class += (int)size - (size_class << 4) == 0 ? 0 : 1; - - UnarySpan* uspan = NULL; - - a_int16_t* pcard = self->raw_type.uspan_card[size_class][tid]; - while (1) - { - if (!atomic_check_in(pcard)) - continue; - uspan = self->raw_type.uspan[size_class][tid]; - if (uspan == NULL) - { - if (!atomic_book_critical(pcard)) - { - atomic_check_out(pcard); - continue; - } - atomic_enter_critical(pcard); - Magic magic = - { - .raw_uspan = - { - .pattern = RAW_USPAN_PATTERN, - .obj_size = size_class, - .thread_id = tid - } - }; - while (1) - { - // TODO: would this be a dead lock? - a_int16_t* hpage_pcard = self->raw_type.hpage_pcard; - if (!atomic_check_in(hpage_pcard)) - continue; - HugePage* hpage = self->raw_type.hpage; - if (hpage == NULL) - { - if(!atomic_book_critical(hpage_pcard)) - { - atomic_check_out(hpage_pcard); - continue; - } - atomic_enter_critical(hpage_pcard); - Magic magic = - {.raw_hpage = {.pattern = RAW_HPAGE_PATTERN}}; - hpage = ObtainHPage(self, magic); - enqueue_hpage(&self->raw_type.hpage, hpage); - atomic_exit_critical(hpage_pcard); - } - // TODO: We can optimize for different object sizes. - // Larger object can use larger span. - // Or the size that get allocated frequently can use - // larger span. - uspan = ObtainUSpan(hpage, magic, 1); - atomic_check_out(hpage_pcard); - if (uspan) - break; - } - enqueue_uspan(&self->raw_type.uspan[size_class][tid], - uspan); - atomic_exit_critical(pcard); - break; - } - if (!USpanMalloc(uspan, &addr)) - { - atomic_check_out(pcard); - continue; - } - atomic_check_out(pcard); - return addr; - } - } - else if (size <= 2048) - { - int size_class; - int favor; - int large_uspan_id; - if (size <= 512) - { - large_uspan_id = 0; - size_class = 512; - favor = FAVOR_512; - } - else if (size <= 1024) - { - large_uspan_id = 1; - size_class = 1024; - favor = FAVOR_1024; - } - else - { - large_uspan_id = 2; - size_class = 2048; - favor = FAVOR_2048; - } - - UnarySpan* uspan = NULL; - - while (1) - { - acq_rlock(&self->raw_type.large_uspan_rwlock[large_uspan_id], - &self->raw_type.remain_favor, - favor); - uspan = self->raw_type.large_uspan[large_uspan_id]; - if (uspan == NULL) - { - favor_write(&self->raw_type.remain_favor, - favor); - rel_rlock(&self->raw_type.large_uspan_rwlock[large_uspan_id]); - insert_new_large_uspan(&self->raw_type, - large_uspan_id, - size_class, - favor, - self); - continue; - } - addr = USpanMalloc(uspan); - if (addr == NULL) - { - favor_write(&self->raw_type.remain_favor, - favor); - rel_rlock(&self->raw_type.large_uspan_rwlock[large_uspan_id]); - remove_large_uspan - (&self->raw_type.large_uspan[large_uspan_id], - &self->raw_type.large_uspan_rwlock[large_uspan_id], - &self->raw_type.remain_favor, - favor, - uspan); - continue; - } - break; - } - rel_rlock(&self->raw_type.large_uspan_rwlock[large_uspan_id]); - return addr; - } - else - { - op_assert(0, "not implemented yet\n"); - } - - return NULL; -} - -void OPFree2(void* addr) -{ - OPHeap* self = (OPHeap*)(((uintptr_t)addr) & OPHEAP_SIZE); - ptrdiff_t diff = (uintptr_t)addr - (uintptr_t)self; - - int hpage_idx = diff >> 21; - - if (hpage_idx == 0) - { - // TODO: special logic to handle first hpage - return; - } - - // TODO the logic here is terrible, need to rewrite. - /* uint64_t bmap = atomic_load_explicit(&self->header_bmap[hpage_idx >> 6], */ - /* memory_order_relaxed); */ - /* uint64_t clear_low = bitmap & ~((1UL << hpage_idx % 64)-1); */ - /* int hpage_header_idx = ((hpage_idx >> 6) << 6) + __builtin_ctzl(clear_low); */ - /* span = base + (span_header_idx << 12); */ - /* header_mask = ~(clear_low & (~(clear_low) + 1)); */ -} - -bool ObtainHPage(OPHeap* self, - HugePage** hpage, - Magic magic) -{ - if (ObtainHBlob(self, hpage, 1)) - { - HugePageInit(hpage, magic); - return true; - } - return false; -} - -bool ObtainHBlob(OPHeap* self, - void** blob, - unsigned int span_cnt) -{ - op_assert(span_cnt <= 64, - "span_cnt is limitted to 64 huge pages, aka 256MB\n"); - - uint64_t old_bmap, new_bmap; - uintptr_t base = (uintptr_t)self; - ptrdiff_t item_offset; - int pos; - - if (span_cnt == 1 && - (atomic_fetch_or_explicit(&self->occupy_bmap[0], - 1, memory_order_relaxed) - & 1) == 0) - { - atomic_fetch_or_explicit(&self->header_bmap[0], 1, - memory_order_release); - *blob = &self->first_page; - return true; - } - for (int i = 0; i < VSPAN_BMAP_NUM; i++) - { - old_bmap = atomic_load_explicit(&self->occupy_bmap[i], - memory_order_relaxed); - do - { - if (old_bmap == ~0UL) break; - pos = fftstr0l(old_bmap, span_cnt); - if (pos == -1) break; - item_offset = __builtin_ctzl(new_bmap); - new_bmap = old_bmap | ((1UL << span_cnt)-1) << pos; - } - while (!atomic_compare_exchange_weak_explicit - (&self->occupy_bmap[i], &old_bmap, new_bmap, - memory_order_acquire, - memory_order_relaxed)); - *blob = base + ((i << 6) + item_offset); - atomic_fetch_or_explicit(&self->header_bmap[i], 1UL << item_offset, - memory_order_release); - return true; - } - return false; -} - -/* op_heap.c ends here */ diff --git a/src/opic/malloc/op_heap.h b/src/opic/malloc/op_heap.h deleted file mode 100644 index 93a74a8..0000000 --- a/src/opic/malloc/op_heap.h +++ /dev/null @@ -1,56 +0,0 @@ -/* op_heap.h --- - * - * Filename: op_heap.h - * Description: - * Author: Felix Chern - * Maintainer: - * Copyright: (c) 2016 Felix Chern - * Created: Thu Oct 20, 2016 - * Version: - * Package-Requires: () - * Last-Updated: - * By: - * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * - */ - -/* Commentary: - * - * - * - */ - -/* Change Log: - * - * - */ - -/* This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* Code: */ - - -#ifndef OP_HEAP_H -#define OP_HEAP_H - -typedef struct OPHeap OPHeap; - -#endif /* OP_HEAP_H */ - -/* op_heap.h ends here */ diff --git a/src/opic/malloc/op_heap_internal.h b/src/opic/malloc/op_heap_internal.h deleted file mode 100644 index bda07e8..0000000 --- a/src/opic/malloc/op_heap_internal.h +++ /dev/null @@ -1,376 +0,0 @@ -/* op_lock_utils.h --- - * - * Filename: op_lock_utils.h - * Description: - * Author: Felix Chern - * Maintainer: - * Copyright: (c) 2016 Felix Chern - * Created: Thu Nov 3 2016 - * Version: - * Package-Requires: () - * Last-Updated: - * By: - * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * - */ - -/* Commentary: - * - * - * - */ - -/* Change Log: - * - * - */ - -/* This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* Code: */ - -#ifndef OP_HEAP_INTERNAL_H -#define OP_HEAP_INTERNAL_H 1 - -#include -#include -#include -#include "opic/common/op_macros.h" -#include "opic/common/op_atomic.h" -#include "opic/malloc/huge_page.h" -#include "opic/malloc/op_heap.h" - -OP_BEGIN_DECLS - - - - -static inline void -insert_hpage_internal(HugePage** hpage_ref, HugePage* hpage) -{ - HugePage** it = hpage_ref; - while (*it && (*it) < hpage) - it = &(*it)->next; - - if (*it == NULL) - { - *it = hpage; - return; - } - // TODO maybe we should assert *it > hpage - // because equal case should not happen because we always - // use try wlock. - else if (*it > hpage) - { - hpage->next = (*it); - *it = hpage; - return; - } -} - -static inline bool -enqueue_new_raw_hpage(HugePage** hpage_ref, - a_int16_t* h_pcard, - OPHeap* heap) -{ - if (!atomic_enter_critical(h_pcard)) - return false; - Magic magic = {.raw_hpage = {.pattern = RAW_HPAGE_PATTERN}}; - HugePage* hpage = ObtainHPage(heap, magic); - insert_hpage_internal(hpage_ref, hpage); - atomic_exit_critical(h_pcard); - return true; -} - -static inline bool -enqueue_new_typed_hpage(uint16_t type_alias_id, - HugePage** hpage_ref, - a_int16_t* h_pcard, - OPHeap* heap) -{ - if (!atomic_enter_critical(h_pcard)) - return false; - Magic magic = - { - .typed_hpage = - { - .pattern = TYPED_HPAGE_PATTERN, - .type_alias = type_alias_id - } - }; - HugePage* hpage = ObtainHPage(heap, magic); - insert_hpage_internal(hpage_ref, hpage); - atomic_exit_critical(h_pcard); - return true; -} - -static inline bool -enqueue_hpage(HugePage** hpage_ref, - a_int16_t* h_pcard, - HugePage* hpage) -{ - if (!atomic_enter_critical(h_pcard)) - return false; - insert_hpage_internal(hpage_ref, hpage); - atomic_exit_critical(h_pcard); - return true; -} - -static inline bool -dequeue_hpage(HugePage** hpage_ref, - a_int16_t* h_pcard, - HugePage* hpage) -{ - if (!atomic_enter_critical(h_pcard)) - return false; - - HugePage** it = hpage_ref; - while (*it != hpage) - it = &(*it)->next; - - *it = (*it)->next; - atomic_exit_critical(h_pcard); - return true; -} - - -static inline void -insert_uspan_internal(UnarySpan** uspan_ref, UnarySpan* uspan) -{ - UnarySpan** it = uspan_ref; - while (*it && (*it) < uspan) - it = &(*it)->next; - - if (*it == NULL) - { - *it = uspan; - return; - } - else if (*it > uspan) - { - uspan->next = (*it); - *it = uspan; - return; - } -} - -static inline bool -enqueue_new_raw_uspan(RawType* raw_type, - uint16_t size_class, - uint8_t tid, - OPHeap* heap) -{ - if (!atomic_enter_critical(&raw_type->uspan_pcard[size_class][tid])) - return false; - - HugePage* hpage = NULL; - UnarySpan* uspan = NULL; - Magic magic = - { - .raw_uspan = - { - .pattern = RAW_USPAN_PATTERN, - .obj_size = size_class, - .thread_id = tid - } - }; - - // TODO: we copied this part for three times - // Shouldn't we create a new inline function for this? - while (1) - { - if(!atomic_check_in(&raw_type->hpage_pcard)) - continue; - hpage = raw_type->hpage; - if (hpage == NULL) - { - if (!atomic_book_critical(&raw_type->hpage_pcard)) - { - atomic_check_out(&raw_type->hpage_pcard); - continue; - } - while (!enqueue_new_raw_hpage(&raw_type->hpage, - &raw_type->hpage_pcard, - heap)) - ; - } - - // TODO: should optimize for different size classes - // TODO: should pass-in uspan ref - // TODO: use do {} while (obtained_state != BM_NORMAL) - uspan = ObtainUSpan(hpage, magic, 1); - atomic_check_out(&raw_type->hpage_pcard); - if (uspan) - break; - } - insert_uspan_internal(&raw_type->uspan[size_class][tid], uspan); - atomic_exit_critical(&raw_type->uspan_pcard[size_class][tid]); - return true; -} - - -static inline bool -enqueue_new_typed_uspan(TypeAlias* type_alias, - uint16_t obj_size, - uint8_t tid, - uint16_t type_alias_id, - OPHeap* heap) -{ - if (!atomic_enter_critical(&type_alias->uspan_pcard[tid])) - return false; - - HugePage* hpage = NULL; - UnarySpan* uspan = NULL; - Magic magic = - { - .typed_uspan = - { - .pattern = TYPED_USPAN_PATTERN, - .obj_size = obj_size, - .thread_id = tid, - .type_alias = type_alias_id - } - }; - - while (1) - { - if(!atomic_check_in(&type_alias->hpage_pcard)) - continue; - hpage = type_alias->hpage; - if (hpage == NULL) - { - if (!atomic_book_critical(&type_alias->hpage_pcard)) - { - atomic_check_out(&type_alias->hpage_pcard); - continue; - } - while (!enqueue_new_typed_hpage(type_alias_id, - &type_alias->hpage, - &type_alias->hpage_pcard, - heap)) - ; - } - - // TODO: should optimize for different object size - // TODO: should pass-in uspan ref - // TODO: use do {} while (obtained_state != BM_NORMAL) - uspan = ObtainUSpan(hpage, magic, 1); - atomic_check_out(&type_alias->hpage_pcard); - if (uspan) - break; - } - - insert_uspan_internal(&type_alias->uspan[tid], uspan); - atomic_exit_critical(&type_alias->uspan_pcard[tid]); - return true; -} - -static inline bool -enqueue_new_large_uspan(RawType* raw_type, - int large_uspan_id, - int size_class, - int favor, - OPHeap* heap) -{ - if (!atomic_enter_critical(&raw_type->large_uspan_pcard[large_uspan_id])) - return false; - HugePage* hpage = NULL; - UnarySpan* uspan = NULL; - Magic magic = - { - .large_uspan = - { - .pattern = LARGE_USPAN_PATTERN, - .obj_size = size_class, - } - }; - - while (1) - { - if(!atomic_check_in(&raw_type->hpage_pcard)) - continue; - hpage = raw_type->hpage; - if (hpage == NULL) - { - if (!atomic_book_critical(&raw_type->hpage_pcard)) - { - atomic_check_out(&raw_type->hpage_pcard); - continue; - } - while (!enqueue_new_raw_hpage(&raw_type->hpage, - &raw_type->hpage_pcard, - heap)) - ; - } - - // TODO: should optimize for different object size - // TODO: should pass-in uspan ref - // TODO: use do {} while (obtained_state != BM_NORMAL) - uspan = ObtainUSpan(hpage, magic, 1); - atomic_check_out(&raw_type->hpage_pcard); - if (uspan) - break; - } - - insert_uspan_internal(&raw_type->large_uspan[large_uspan_id], uspan); - atomic_exit_critical(&raw_type->large_uspan_pcard[large_uspan_id]); - return true; -} - -static inline bool -dequeue_hpage(HugePage** hpage_ref, - a_int16_t pcard, - HugePage* hpage) -{ - if (!atomic_enter_critical(pcard)) - return false; - - HugePage** it = hpage_ref; - while (*it != hpage) - it = &(*it)->next; - - *it = (*it)->next; - atomic_exit_critical(pcard); - return true; -} - - - - -static inline bool -dequeue_large_uspan(UnarySpan** uspan_ref, - a_int16_t* pcard, - UnarySpan* uspan) -{ - if (!atomic_enter_critical(pcard)) - return false; - - UnarySpan** it = uspan_ref; - while (*it != uspan) - it = &(*it)->next; - - *it = (*it)->next; - atomic_exit_critical(pcard); - return true; -} - -OP_END_DECLS - -#endif /* OP_HEAP_INTERNAL_H */ -/* op_lock_utils.h ends here */ diff --git a/src/opic/malloc/op_malloc.c b/src/opic/malloc/op_malloc.c index 7ae2b30..0eb3fff 100644 --- a/src/opic/malloc/op_malloc.c +++ b/src/opic/malloc/op_malloc.c @@ -1,43 +1,43 @@ -/* op_malloc.c --- - * +/* op_malloc.c --- + * * Filename: op_malloc.c - * Description: + * Description: * Author: Felix Chern * Maintainer: Felix Chern * Created: Sat Oct 1 16:25:47 2016 - * Version: + * Version: * Package-Requires: () - * Last-Updated: - * By: + * Last-Updated: + * By: * Update #: 0 - * URL: - * Doc URL: - * Keywords: - * Compatibility: - * + * URL: + * Doc URL: + * Keywords: + * Compatibility: + * */ -/* Commentary: - * - * - * +/* Commentary: + * + * + * */ /* Change Log: - * - * + * + * */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ diff --git a/src/opic/malloc/op_malloc.h b/src/opic/malloc/op_malloc.h index 8e457dd..ad94f54 100644 --- a/src/opic/malloc/op_malloc.h +++ b/src/opic/malloc/op_malloc.h @@ -55,10 +55,18 @@ void* OPMallocRaw(OPHeap* heap, size_t size) __attribute__ ((malloc)); +void* +OPCallocRaw(OPHeap* heap, size_t size) + __attribute__ ((malloc)); + void* OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) __attribute__ ((malloc)); +void* +OPCallocRawAdviced(OPHeap* heap, size_t size, int advice) + __attribute__ ((malloc)); + void OPDealloc(void* addr); From a4354311571bd874544206aae60f9ffbbc9076a0 Mon Sep 17 00:00:00 2001 From: dryman Date: Sun, 26 Mar 2017 15:41:37 -0700 Subject: [PATCH 5/6] OPIC-34 demomalloc --- configure.ac | 1 + src/Makefile.am | 2 +- src/opic/Makefile.am | 17 +++++ src/opic/demomalloc.c | 110 ++++++++++++++++++++++++++++++ src/opic/demomalloc.h | 84 +++++++++++++++++++++++ src/opic/malloc/Makefile.am | 15 ++-- src/opic/malloc/allocator.c | 14 ++-- src/opic/malloc/allocator_test.c | 2 - src/opic/malloc/deallocator.c | 1 - src/opic/malloc/init_helper.c | 3 +- src/opic/malloc/init_helper.h | 4 -- src/opic/malloc/lookup_helper.h | 6 -- src/opic/malloc/magic.h | 2 - src/opic/malloc/objdef.h | 2 +- src/opic/{malloc => }/op_malloc.h | 28 ++++++-- 15 files changed, 252 insertions(+), 39 deletions(-) create mode 100644 src/opic/Makefile.am create mode 100644 src/opic/demomalloc.c create mode 100644 src/opic/demomalloc.h rename src/opic/{malloc => }/op_malloc.h (72%) diff --git a/configure.ac b/configure.ac index 4869ce7..7a0db54 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,7 @@ PKG_CHECK_MODULES([cmocka], [cmocka >= 1.0.1]) AC_CONFIG_FILES([ Makefile src/Makefile + src/opic/Makefile src/opic/malloc/Makefile ]) diff --git a/src/Makefile.am b/src/Makefile.am index fdb71da..017b7f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # TODO: Can we put Makefile.am in subdir? # https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html -SUBDIRS = opic/malloc +SUBDIRS = opic # AUTOMAKE_OPTIONS = subdir-objects # diff --git a/src/opic/Makefile.am b/src/opic/Makefile.am new file mode 100644 index 0000000..2106725 --- /dev/null +++ b/src/opic/Makefile.am @@ -0,0 +1,17 @@ +SUBDIRS = malloc + +AUTOMAKE_OPTIONS = subdir-objects +AM_CPPFLAGS = -I$(top_srcdir)/src + +lib_LTLIBRARIES = libdemomalloc.la + +libdemomalloc_la_SOURCES = \ + demomalloc.c \ + malloc/allocator.c \ + malloc/deallocator.c \ + malloc/init_helper.c \ + malloc/lookup_helper.c + +libdemomalloc_la_LIBADD = @atomic_LIBS@ + +include_HEADERS = demomalloc.h op_malloc.h diff --git a/src/opic/demomalloc.c b/src/opic/demomalloc.c new file mode 100644 index 0000000..59ad608 --- /dev/null +++ b/src/opic/demomalloc.c @@ -0,0 +1,110 @@ +/* demomalloc.c --- + * + * Filename: demomalloc.c + * Description: + * Author: Felix Chern + * Maintainer: + * Copyright: (c) 2017 Felix Chern + * Created: Sun Mar 26 11:43:56 2017 (-0700) + * Version: + * Package-Requires: () + * Last-Updated: + * By: + * Update #: 0 + * URL: + * Doc URL: + * Keywords: + * Compatibility: + * + */ + +/* Commentary: + * + * + * + */ + +/* Change Log: + * + * + */ + +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +/* Code: */ + +#include +#include +#include +#include +#include +#include "opic/op_malloc.h" +#include "opic/demomalloc.h" + +static atomic_flag lock = ATOMIC_FLAG_INIT; +static OPHeap* heap; + +static +OPHeap* GetOPHeap() +{ + while (true) + { + if (heap) + return heap; + if (atomic_flag_test_and_set_explicit(&lock, memory_order_acquire)) + continue; + OPHeapNew(&heap); + atomic_flag_clear_explicit(&lock, memory_order_release); + } +} + +void* +OPDemoMalloc(size_t size) +{ + OPHeap* heap = GetOPHeap(); + return OPMallocRaw(heap, size); +} + +void* +OPDemoCalloc(size_t num, size_t size) +{ + OPHeap* heap = GetOPHeap(); + return OPCallocRaw(heap, num, size); +} + +void* +OPDemoRealloc(void* addr, size_t size) +{ + OPHeap* heap; + void* new_addr; + heap = ObtainOPHeap(addr); + // NOTE: for sblob/hblob we might find the new size still fits in the blob. + // We can do this optimization later. + new_addr = OPMallocRaw(heap, size); + if (new_addr) + { + memcpy(new_addr, addr, size); + OPDealloc(addr); + } + return new_addr; +} + +void +OPDemoFree(void* addr) +{ + OPDealloc(addr); +} + +/* demomalloc.c ends here */ diff --git a/src/opic/demomalloc.h b/src/opic/demomalloc.h new file mode 100644 index 0000000..c7e308c --- /dev/null +++ b/src/opic/demomalloc.h @@ -0,0 +1,84 @@ +/* demomalloc.h --- + * + * Filename: demomalloc.h + * Description: + * Author: Felix Chern + * Maintainer: + * Copyright: (c) 2017 Felix Chern + * Created: Sun Mar 26 12:07:34 2017 (-0700) + * Version: + * Package-Requires: () + * Last-Updated: + * By: + * Update #: 0 + * URL: + * Doc URL: + * Keywords: + * Compatibility: + * + */ + +/* Commentary: + * + * + * + */ + +/* Change Log: + * + * + */ + +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +/* Code: */ + +#ifndef OPIC_DEMOMALLOC_H +#define OPIC_DEMOMALLOC_H 1 + +#include "opic/common/op_macros.h" +#include "opic/op_malloc.h" + +OP_BEGIN_DECLS + +void* OPDemoMalloc(size_t size) + __attribute__((malloc)); + +void* OPDemoCalloc(size_t num, size_t size) + __attribute__((malloc)); + +void* OPDemoRealloc(void* addr, size_t size) + __attribute__((malloc)); + +void OPDemoFree(void* addr); + + +void* malloc(size_t size) + __attribute__((weak, alias("OPDemoMalloc"))) __attribute__((malloc)); + +void* calloc(size_t num, size_t size) + __attribute__((weak, alias("OPDemoCalloc"))) __attribute__((malloc)); + +void* realloc(void* addr, size_t size) + __attribute__((weak, alias("OPDemoRealloc"))) __attribute__((malloc)); + +void free(void* addr) + __attribute__((weak, alias("OPDemoFree"))); + +OP_END_DECLS + +#endif + +/* demomalloc.h ends here */ diff --git a/src/opic/malloc/Makefile.am b/src/opic/malloc/Makefile.am index c5d4d4b..3a4da94 100644 --- a/src/opic/malloc/Makefile.am +++ b/src/opic/malloc/Makefile.am @@ -1,6 +1,5 @@ -AUTOMAKE_OPTIONS = subdir-objects AM_CPPFLAGS = -I$(top_srcdir)/src -AM_CFLAGS = @log4c_CFLAGS@ @cmocka_CFLAGS@ +AM_CFLAGS = @cmocka_CFLAGS@ TESTS = lookup_helper_test init_helper_test allocator_test \ deallocator_test @@ -10,8 +9,7 @@ check_PROGRAMS = lookup_helper_test init_helper_test allocator_test \ lookup_helper_test_SOURCES = \ lookup_helper_test.c \ lookup_helper.c \ - init_helper.c \ - ../common/op_log.c + init_helper.c lookup_helper_test_LDADD = @log4c_LIBS@ @PTHREAD_LIBS@ \ @cmocka_LIBS@ @atomic_LIBS@ @@ -20,8 +18,7 @@ lookup_helper_test_LDFLAGS = -static init_helper_test_SOURCES = \ init_helper.c \ init_helper_test.c \ - lookup_helper.c \ - ../common/op_log.c + lookup_helper.c init_helper_test_LDADD = @log4c_LIBS@ @PTHREAD_LIBS@ \ @cmocka_LIBS@ @atomic_LIBS@ @@ -32,8 +29,7 @@ allocator_test_SOURCES = \ allocator_test.c \ deallocator.c \ init_helper.c \ - lookup_helper.c \ - ../common/op_log.c + lookup_helper.c allocator_test_LDADD = @log4c_LIBS@ @PTHREAD_LIBS@ \ @cmocka_LIBS@ @atomic_LIBS@ @@ -44,8 +40,7 @@ deallocator_test_SOURCES = \ deallocator.c \ deallocator_test.c \ init_helper.c \ - lookup_helper.c \ - ../common/op_log.c + lookup_helper.c deallocator_test_LDADD = @log4c_LIBS@ @PTHREAD_LIBS@ \ @cmocka_LIBS@ @atomic_LIBS@ diff --git a/src/opic/malloc/allocator.c b/src/opic/malloc/allocator.c index 61c928e..06c6838 100644 --- a/src/opic/malloc/allocator.c +++ b/src/opic/malloc/allocator.c @@ -48,7 +48,6 @@ #include #include "opic/common/op_assert.h" #include "opic/common/op_atomic.h" -#include "opic/common/op_log.h" #include "opic/common/op_utils.h" #include "allocator.h" #include "init_helper.h" @@ -71,13 +70,13 @@ OPMallocRaw(OPHeap* heap, size_t size) } void* -OPCallocRaw(OPHeap* heap, size_t size) +OPCallocRaw(OPHeap* heap, size_t num, size_t size) { if (thread_id == -1) thread_id = atomic_fetch_add_explicit (&round_robin, 1, memory_order_acquire) % 16; - return OPCallocRawAdviced(heap, size, thread_id); + return OPCallocRawAdviced(heap, num, size, thread_id); } void* @@ -154,13 +153,16 @@ OPMallocRawAdviced(OPHeap* heap, size_t size, int advice) } void* -OPCallocRawAdviced(OPHeap* heap, size_t size, int advice) +OPCallocRawAdviced(OPHeap* heap, size_t num, size_t size, int advice) { void* addr; + size_t _size; + + _size = num * size; + addr = OPMallocRawAdviced(heap, _size, thread_id); - addr = OPMallocRawAdviced(heap, size, thread_id); if (addr) - memset(addr, 0x00, size); + memset(addr, 0x00, _size); return addr; } diff --git a/src/opic/malloc/allocator_test.c b/src/opic/malloc/allocator_test.c index 86e3b10..a2ecea6 100644 --- a/src/opic/malloc/allocator_test.c +++ b/src/opic/malloc/allocator_test.c @@ -767,10 +767,8 @@ static void test_DispatchHPageForSSpan(void** context) { OPHeap* heap; - uintptr_t heap_base; assert_true(OPHeapNew(&heap)); - heap_base = (uintptr_t)heap; // TODO: configure different kind of init state // run dispatch and see if the end state is expected diff --git a/src/opic/malloc/deallocator.c b/src/opic/malloc/deallocator.c index 232af93..abe44e7 100644 --- a/src/opic/malloc/deallocator.c +++ b/src/opic/malloc/deallocator.c @@ -48,7 +48,6 @@ #include #include "opic/common/op_assert.h" #include "opic/common/op_atomic.h" -#include "opic/common/op_log.h" #include "deallocator.h" #include "inline_aux.h" #include "init_helper.h" diff --git a/src/opic/malloc/init_helper.c b/src/opic/malloc/init_helper.c index 2b1765b..9bf31a5 100644 --- a/src/opic/malloc/init_helper.c +++ b/src/opic/malloc/init_helper.c @@ -46,11 +46,10 @@ /* Code: */ #include +#include #include #include "lookup_helper.h" #include "init_helper.h" -#include "opic/common/op_log.h" - bool OPHeapNew(OPHeap** heap_ref) diff --git a/src/opic/malloc/init_helper.h b/src/opic/malloc/init_helper.h index 8e97f10..598fc1d 100644 --- a/src/opic/malloc/init_helper.h +++ b/src/opic/malloc/init_helper.h @@ -61,10 +61,6 @@ union BmapPtr a_uint64_t* a_uint64; } __attribute__ ((__transparent_union__)); -bool OPHeapNew(OPHeap** heap_ref); - -void OPHeapDestroy(OPHeap* heap); - void HPageInit(HugePage* hpage, Magic magic) __attribute__ ((visibility ("internal"))); diff --git a/src/opic/malloc/lookup_helper.h b/src/opic/malloc/lookup_helper.h index 66eb332..00e3c48 100644 --- a/src/opic/malloc/lookup_helper.h +++ b/src/opic/malloc/lookup_helper.h @@ -52,12 +52,6 @@ OP_BEGIN_DECLS -static inline OPHeap* -ObtainOPHeap(void* addr) -{ - return (OPHeap*)((uintptr_t)addr & ~(OPHEAP_SIZE - 1)); -} - static inline HugePage* ObtainHPage(void* addr) { diff --git a/src/opic/malloc/magic.h b/src/opic/malloc/magic.h index 1f01950..8726ee4 100644 --- a/src/opic/malloc/magic.h +++ b/src/opic/malloc/magic.h @@ -53,10 +53,8 @@ #define OPHEAP_VERSION 3 -#define OPHEAP_BITS 36 #define HPAGE_BITS 21 #define SPAGE_BITS 12 -#define OPHEAP_SIZE (1UL << OPHEAP_BITS) #define HPAGE_SIZE (1UL << HPAGE_BITS) #define SPAGE_SIZE (1UL << SPAGE_BITS) #define HPAGE_BMAP_NUM 512 diff --git a/src/opic/malloc/objdef.h b/src/opic/malloc/objdef.h index 1cba6c5..1b0a73b 100644 --- a/src/opic/malloc/objdef.h +++ b/src/opic/malloc/objdef.h @@ -54,7 +54,7 @@ #include "opic/common/op_atomic.h" #include "opic/common/op_macros.h" #include "magic.h" -#include "op_malloc.h" +#include "opic/op_malloc.h" OP_BEGIN_DECLS diff --git a/src/opic/malloc/op_malloc.h b/src/opic/op_malloc.h similarity index 72% rename from src/opic/malloc/op_malloc.h rename to src/opic/op_malloc.h index ad94f54..54c2004 100644 --- a/src/opic/malloc/op_malloc.h +++ b/src/opic/op_malloc.h @@ -49,27 +49,47 @@ #ifndef OP_MALLOC_H #define OP_MALLOC_H 1 +#include +#include "opic/common/op_macros.h" + +OP_BEGIN_DECLS + +#define OPHEAP_BITS 36 +#define OPHEAP_SIZE (1UL << OPHEAP_BITS) + typedef struct OPHeap OPHeap; +bool OPHeapNew(OPHeap** heap_ref); + +void OPHeapDestroy(OPHeap* heap); + +static inline OPHeap* +ObtainOPHeap(void* addr) +{ + return (OPHeap*)((uintptr_t)addr & ~(OPHEAP_SIZE - 1)); +} + void* OPMallocRaw(OPHeap* heap, size_t size) __attribute__ ((malloc)); void* -OPCallocRaw(OPHeap* heap, size_t size) +OPCallocRaw(OPHeap* heap, size_t num, size_t size) __attribute__ ((malloc)); void* -OPMallocRawAdviced(OPHeap* heap, size_t size, int hint) +OPMallocRawAdviced(OPHeap* heap, size_t size, int advice) __attribute__ ((malloc)); void* -OPCallocRawAdviced(OPHeap* heap, size_t size, int advice) +OPCallocRawAdviced(OPHeap* heap, size_t num, size_t size, int advice) __attribute__ ((malloc)); void OPDealloc(void* addr); -#endif /* OP_MALLOC_H */ +OP_END_DECLS + +#endif /* op_malloc.h ends here */ From 73059dfa704ef8ba99e84b19450b04a71d3f49ec Mon Sep 17 00:00:00 2001 From: dryman Date: Sun, 26 Mar 2017 16:23:45 -0700 Subject: [PATCH 6/6] OPIC-34 restructured directory --- Makefile.am | 6 ++- configure.ac | 7 ++- {src/opic => opic}/Makefile.am | 4 +- {src/opic => opic}/common/op_assert.h | 0 {src/opic => opic}/common/op_atomic.h | 0 {src/opic => opic}/common/op_log.c | 0 {src/opic => opic}/common/op_log.h | 0 {src/opic => opic}/common/op_macros.h | 0 {src/opic => opic}/common/op_utils.h | 0 {src/opic => opic}/demomalloc.c | 0 {src/opic => opic}/demomalloc.h | 6 +++ {src/opic => opic}/malloc/Makefile.am | 2 +- {src/opic => opic}/malloc/allocator.c | 0 {src/opic => opic}/malloc/allocator.h | 0 {src/opic => opic}/malloc/allocator_test.c | 0 {src/opic => opic}/malloc/deallocator.c | 0 {src/opic => opic}/malloc/deallocator.h | 0 {src/opic => opic}/malloc/deallocator_test.c | 0 {src/opic => opic}/malloc/init_helper.c | 0 {src/opic => opic}/malloc/init_helper.h | 0 {src/opic => opic}/malloc/init_helper_test.c | 0 {src/opic => opic}/malloc/inline_aux.h | 0 {src/opic => opic}/malloc/lookup_helper.c | 0 {src/opic => opic}/malloc/lookup_helper.h | 0 .../opic => opic}/malloc/lookup_helper_test.c | 0 {src/opic => opic}/malloc/magic.h | 0 {src/opic => opic}/malloc/objdef.h | 0 {src/opic => opic}/malloc/op_malloc.c | 0 {src/opic => opic}/object/class_map.c | 0 {src/opic => opic}/object/class_map.h | 0 {src/opic => opic}/object/op_malloc_manager.c | 0 {src/opic => opic}/object/op_object.c | 0 {src/opic => opic}/object/op_object.h | 0 {src/opic => opic}/object/op_object_def.h | 0 {src/opic => opic}/object/op_serializable.c | 0 {src/opic => opic}/object/op_serializable.h | 0 {src/opic => opic}/object/op_trait.c | 0 {src/opic => opic}/object/op_trait.h | 0 {src/opic => opic}/object/ptr_range_map.h | 0 .../object/ptr_range_map_splay.c | 0 {src/opic => opic}/op_malloc.h | 0 src/Makefile.am | 48 ------------------- 42 files changed, 16 insertions(+), 57 deletions(-) rename {src/opic => opic}/Makefile.am (77%) rename {src/opic => opic}/common/op_assert.h (100%) rename {src/opic => opic}/common/op_atomic.h (100%) rename {src/opic => opic}/common/op_log.c (100%) rename {src/opic => opic}/common/op_log.h (100%) rename {src/opic => opic}/common/op_macros.h (100%) rename {src/opic => opic}/common/op_utils.h (100%) rename {src/opic => opic}/demomalloc.c (100%) rename {src/opic => opic}/demomalloc.h (93%) rename {src/opic => opic}/malloc/Makefile.am (97%) rename {src/opic => opic}/malloc/allocator.c (100%) rename {src/opic => opic}/malloc/allocator.h (100%) rename {src/opic => opic}/malloc/allocator_test.c (100%) rename {src/opic => opic}/malloc/deallocator.c (100%) rename {src/opic => opic}/malloc/deallocator.h (100%) rename {src/opic => opic}/malloc/deallocator_test.c (100%) rename {src/opic => opic}/malloc/init_helper.c (100%) rename {src/opic => opic}/malloc/init_helper.h (100%) rename {src/opic => opic}/malloc/init_helper_test.c (100%) rename {src/opic => opic}/malloc/inline_aux.h (100%) rename {src/opic => opic}/malloc/lookup_helper.c (100%) rename {src/opic => opic}/malloc/lookup_helper.h (100%) rename {src/opic => opic}/malloc/lookup_helper_test.c (100%) rename {src/opic => opic}/malloc/magic.h (100%) rename {src/opic => opic}/malloc/objdef.h (100%) rename {src/opic => opic}/malloc/op_malloc.c (100%) rename {src/opic => opic}/object/class_map.c (100%) rename {src/opic => opic}/object/class_map.h (100%) rename {src/opic => opic}/object/op_malloc_manager.c (100%) rename {src/opic => opic}/object/op_object.c (100%) rename {src/opic => opic}/object/op_object.h (100%) rename {src/opic => opic}/object/op_object_def.h (100%) rename {src/opic => opic}/object/op_serializable.c (100%) rename {src/opic => opic}/object/op_serializable.h (100%) rename {src/opic => opic}/object/op_trait.c (100%) rename {src/opic => opic}/object/op_trait.h (100%) rename {src/opic => opic}/object/ptr_range_map.h (100%) rename {src/opic => opic}/object/ptr_range_map_splay.c (100%) rename {src/opic => opic}/op_malloc.h (100%) delete mode 100644 src/Makefile.am diff --git a/Makefile.am b/Makefile.am index af437a6..4c7605a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1,5 @@ -SUBDIRS = src +SUBDIRS = opic + +nobase_include_HEADERS = \ + opic/op_malloc.h \ + opic/demomalloc.h diff --git a/configure.ac b/configure.ac index 7a0db54..5eea126 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_INIT([OPIC],[0.3]) AC_CONFIG_SRCDIR([README.md]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) -AM_CONFIG_HEADER([src/config.h]) +AM_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_PROG_AR @@ -46,9 +46,8 @@ PKG_CHECK_MODULES([cmocka], [cmocka >= 1.0.1]) AC_CONFIG_FILES([ Makefile - src/Makefile - src/opic/Makefile - src/opic/malloc/Makefile + opic/Makefile + opic/malloc/Makefile ]) AC_OUTPUT diff --git a/src/opic/Makefile.am b/opic/Makefile.am similarity index 77% rename from src/opic/Makefile.am rename to opic/Makefile.am index 2106725..31f2997 100644 --- a/src/opic/Makefile.am +++ b/opic/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = malloc AUTOMAKE_OPTIONS = subdir-objects -AM_CPPFLAGS = -I$(top_srcdir)/src +AM_CPPFLAGS = -I$(top_srcdir) lib_LTLIBRARIES = libdemomalloc.la @@ -13,5 +13,3 @@ libdemomalloc_la_SOURCES = \ malloc/lookup_helper.c libdemomalloc_la_LIBADD = @atomic_LIBS@ - -include_HEADERS = demomalloc.h op_malloc.h diff --git a/src/opic/common/op_assert.h b/opic/common/op_assert.h similarity index 100% rename from src/opic/common/op_assert.h rename to opic/common/op_assert.h diff --git a/src/opic/common/op_atomic.h b/opic/common/op_atomic.h similarity index 100% rename from src/opic/common/op_atomic.h rename to opic/common/op_atomic.h diff --git a/src/opic/common/op_log.c b/opic/common/op_log.c similarity index 100% rename from src/opic/common/op_log.c rename to opic/common/op_log.c diff --git a/src/opic/common/op_log.h b/opic/common/op_log.h similarity index 100% rename from src/opic/common/op_log.h rename to opic/common/op_log.h diff --git a/src/opic/common/op_macros.h b/opic/common/op_macros.h similarity index 100% rename from src/opic/common/op_macros.h rename to opic/common/op_macros.h diff --git a/src/opic/common/op_utils.h b/opic/common/op_utils.h similarity index 100% rename from src/opic/common/op_utils.h rename to opic/common/op_utils.h diff --git a/src/opic/demomalloc.c b/opic/demomalloc.c similarity index 100% rename from src/opic/demomalloc.c rename to opic/demomalloc.c diff --git a/src/opic/demomalloc.h b/opic/demomalloc.h similarity index 93% rename from src/opic/demomalloc.h rename to opic/demomalloc.h index c7e308c..14ac805 100644 --- a/src/opic/demomalloc.h +++ b/opic/demomalloc.h @@ -64,7 +64,12 @@ void* OPDemoRealloc(void* addr, size_t size) void OPDemoFree(void* addr); +/* + * Somehow I cannot compile the code below on OSX. + * Since replacing malloc is not the major goal, I'll just leave it here. + */ +/* void* malloc(size_t size) __attribute__((weak, alias("OPDemoMalloc"))) __attribute__((malloc)); @@ -76,6 +81,7 @@ void* realloc(void* addr, size_t size) void free(void* addr) __attribute__((weak, alias("OPDemoFree"))); +*/ OP_END_DECLS diff --git a/src/opic/malloc/Makefile.am b/opic/malloc/Makefile.am similarity index 97% rename from src/opic/malloc/Makefile.am rename to opic/malloc/Makefile.am index 3a4da94..6533423 100644 --- a/src/opic/malloc/Makefile.am +++ b/opic/malloc/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(top_srcdir)/src +AM_CPPFLAGS = -I$(top_srcdir) AM_CFLAGS = @cmocka_CFLAGS@ TESTS = lookup_helper_test init_helper_test allocator_test \ diff --git a/src/opic/malloc/allocator.c b/opic/malloc/allocator.c similarity index 100% rename from src/opic/malloc/allocator.c rename to opic/malloc/allocator.c diff --git a/src/opic/malloc/allocator.h b/opic/malloc/allocator.h similarity index 100% rename from src/opic/malloc/allocator.h rename to opic/malloc/allocator.h diff --git a/src/opic/malloc/allocator_test.c b/opic/malloc/allocator_test.c similarity index 100% rename from src/opic/malloc/allocator_test.c rename to opic/malloc/allocator_test.c diff --git a/src/opic/malloc/deallocator.c b/opic/malloc/deallocator.c similarity index 100% rename from src/opic/malloc/deallocator.c rename to opic/malloc/deallocator.c diff --git a/src/opic/malloc/deallocator.h b/opic/malloc/deallocator.h similarity index 100% rename from src/opic/malloc/deallocator.h rename to opic/malloc/deallocator.h diff --git a/src/opic/malloc/deallocator_test.c b/opic/malloc/deallocator_test.c similarity index 100% rename from src/opic/malloc/deallocator_test.c rename to opic/malloc/deallocator_test.c diff --git a/src/opic/malloc/init_helper.c b/opic/malloc/init_helper.c similarity index 100% rename from src/opic/malloc/init_helper.c rename to opic/malloc/init_helper.c diff --git a/src/opic/malloc/init_helper.h b/opic/malloc/init_helper.h similarity index 100% rename from src/opic/malloc/init_helper.h rename to opic/malloc/init_helper.h diff --git a/src/opic/malloc/init_helper_test.c b/opic/malloc/init_helper_test.c similarity index 100% rename from src/opic/malloc/init_helper_test.c rename to opic/malloc/init_helper_test.c diff --git a/src/opic/malloc/inline_aux.h b/opic/malloc/inline_aux.h similarity index 100% rename from src/opic/malloc/inline_aux.h rename to opic/malloc/inline_aux.h diff --git a/src/opic/malloc/lookup_helper.c b/opic/malloc/lookup_helper.c similarity index 100% rename from src/opic/malloc/lookup_helper.c rename to opic/malloc/lookup_helper.c diff --git a/src/opic/malloc/lookup_helper.h b/opic/malloc/lookup_helper.h similarity index 100% rename from src/opic/malloc/lookup_helper.h rename to opic/malloc/lookup_helper.h diff --git a/src/opic/malloc/lookup_helper_test.c b/opic/malloc/lookup_helper_test.c similarity index 100% rename from src/opic/malloc/lookup_helper_test.c rename to opic/malloc/lookup_helper_test.c diff --git a/src/opic/malloc/magic.h b/opic/malloc/magic.h similarity index 100% rename from src/opic/malloc/magic.h rename to opic/malloc/magic.h diff --git a/src/opic/malloc/objdef.h b/opic/malloc/objdef.h similarity index 100% rename from src/opic/malloc/objdef.h rename to opic/malloc/objdef.h diff --git a/src/opic/malloc/op_malloc.c b/opic/malloc/op_malloc.c similarity index 100% rename from src/opic/malloc/op_malloc.c rename to opic/malloc/op_malloc.c diff --git a/src/opic/object/class_map.c b/opic/object/class_map.c similarity index 100% rename from src/opic/object/class_map.c rename to opic/object/class_map.c diff --git a/src/opic/object/class_map.h b/opic/object/class_map.h similarity index 100% rename from src/opic/object/class_map.h rename to opic/object/class_map.h diff --git a/src/opic/object/op_malloc_manager.c b/opic/object/op_malloc_manager.c similarity index 100% rename from src/opic/object/op_malloc_manager.c rename to opic/object/op_malloc_manager.c diff --git a/src/opic/object/op_object.c b/opic/object/op_object.c similarity index 100% rename from src/opic/object/op_object.c rename to opic/object/op_object.c diff --git a/src/opic/object/op_object.h b/opic/object/op_object.h similarity index 100% rename from src/opic/object/op_object.h rename to opic/object/op_object.h diff --git a/src/opic/object/op_object_def.h b/opic/object/op_object_def.h similarity index 100% rename from src/opic/object/op_object_def.h rename to opic/object/op_object_def.h diff --git a/src/opic/object/op_serializable.c b/opic/object/op_serializable.c similarity index 100% rename from src/opic/object/op_serializable.c rename to opic/object/op_serializable.c diff --git a/src/opic/object/op_serializable.h b/opic/object/op_serializable.h similarity index 100% rename from src/opic/object/op_serializable.h rename to opic/object/op_serializable.h diff --git a/src/opic/object/op_trait.c b/opic/object/op_trait.c similarity index 100% rename from src/opic/object/op_trait.c rename to opic/object/op_trait.c diff --git a/src/opic/object/op_trait.h b/opic/object/op_trait.h similarity index 100% rename from src/opic/object/op_trait.h rename to opic/object/op_trait.h diff --git a/src/opic/object/ptr_range_map.h b/opic/object/ptr_range_map.h similarity index 100% rename from src/opic/object/ptr_range_map.h rename to opic/object/ptr_range_map.h diff --git a/src/opic/object/ptr_range_map_splay.c b/opic/object/ptr_range_map_splay.c similarity index 100% rename from src/opic/object/ptr_range_map_splay.c rename to opic/object/ptr_range_map_splay.c diff --git a/src/opic/op_malloc.h b/opic/op_malloc.h similarity index 100% rename from src/opic/op_malloc.h rename to opic/op_malloc.h diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 017b7f7..0000000 --- a/src/Makefile.am +++ /dev/null @@ -1,48 +0,0 @@ -# TODO: Can we put Makefile.am in subdir? -# https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html - -SUBDIRS = opic - -# AUTOMAKE_OPTIONS = subdir-objects -# -# AM_CPPFLAGS = -I$(top_srcdir)/src -# -# lib_LTLIBRARIES = libopic.la -# libopic_la_SOURCES = \ -# opic/common/op_log.c \ -# opic/malloc/span.c \ -# opic/malloc/huge_page.c \ -# opic/malloc/op_heap.c \ -# opic/object/op_serializable.c \ -# opic/object/op_trait.c \ -# opic/object/op_object.c \ -# opic/object/op_malloc_manager.c \ -# opic/object/class_map.c \ -# opic/object/ptr_range_map_splay.c \ -# op_collection.c \ -# op_iterator.c \ -# op_linked_list.c \ -# op_list.c -# libopic_la_CFLAGS = @log4c_CFLAGS@ @PTHREAD_CFLAGS@ -# -# include_HEADERS = \ -# opic.h \ -# op_collection.h \ -# op_functional.h \ -# op_iterator.h \ -# op_linked_list.h \ -# op_list.h -# -# # TODO some of the internal headers -# # may not be needed -# nobase_include_HEADERS = \ -# opic/common/op_assert.h \ -# opic/common/op_log.h \ -# opic/common/op_macros.h \ -# opic/malloc/op_heap.h \ -# opic/malloc/huge_page.h \ -# opic/malloc/span.h \ -# opic/object/op_serializable.h \ -# opic/object/op_trait.h \ -# opic/object/op_object_def.h \ -# opic/object/op_object.h