From 8678395750ebc68aece2cd91bd5cf1afc2923a63 Mon Sep 17 00:00:00 2001 From: Alexandru Ciprian Farcasanu Date: Sun, 13 Dec 2015 16:54:54 +0100 Subject: [PATCH 1/5] Merge gcmalloc into ASCYLIB --- Makefile | 2 +- common/Makefile.common | 7 +++- external/include/gcmalloc.h | 41 +++++++++++++++++++ external/lib/libgcmalloc_x86_64.a | Bin 0 -> 7270 bytes include/memalloc.h | 14 +++++++ src/linkedlist-lazy/Makefile | 7 +++- src/linkedlist-lazy/lazy.c | 4 +- src/linkedlist-lazy/linkedlist-lock.c | 15 +------ src/linkedlist-lazy/linkedlist-lock.h | 1 + src/linkedlist-lazy/test_simple.c | 12 ++---- src/memalloc.c | 55 ++++++++++++++++++++++++++ 11 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 external/include/gcmalloc.h create mode 100644 external/lib/libgcmalloc_x86_64.a create mode 100644 include/memalloc.h create mode 100644 src/memalloc.c diff --git a/Makefile b/Makefile index d95e0bbd..926d161a 100755 --- a/Makefile +++ b/Makefile @@ -269,7 +269,7 @@ lbll_pugh_no_ro: $(MAKE) "RO_FAIL=0" src/linkedlist-pugh lbll_lazy: - $(MAKE) src/linkedlist-lazy + $(MAKE) "GC=1" src/linkedlist-lazy lbll_lazy_no_ro: $(MAKE) "RO_FAIL=0" src/linkedlist-lazy diff --git a/common/Makefile.common b/common/Makefile.common index 341f34e7..f9bf221d 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -219,6 +219,7 @@ ifeq ($(ARCH_NAME), x86_64) LDFLAGS += -m64 SSPFD = -lsspfd_x86_64 LDFLAGS += -L$(LIBSSMEM)/lib -lssmem_x86_64 + LDFLAGS += -L$(LIBGCMALLOC)/lib -lgcmalloc_x86_64 endif ifeq ($(ARCH_NAME), sun4v) @@ -272,7 +273,11 @@ else ifeq ($(GC),0) CFLAGS += -DGC=0 else - CFLAGS += -DGC=1 + ifeq ($(GC),1) + CFLAGS += -DGC=1 + else + CFLAGS += -DGC=2 + endif endif endif diff --git a/external/include/gcmalloc.h b/external/include/gcmalloc.h new file mode 100644 index 00000000..33f50191 --- /dev/null +++ b/external/include/gcmalloc.h @@ -0,0 +1,41 @@ +#ifndef _GCMALLOC_H_ +#define _GCMALLOC_H_ +#include + +/* Allocate an object of specified size. */ +void* gcmem_malloc(size_t size); + +/* + * Free an object. It is guaranteed that the object is buffered until + * it is safe to actually reclaim memory. + */ +void gcmem_free(void* ptr); + +/* + * Informs gcmalloc that the thread enters a critical section and no + * reclamation can be performed, starting from now, on new freed objects. + */ +void gcmem_unsafe_to_reclaim(); + +/* + * Informs gcmalloc that the thread leaves a critical section and + * will not access a shared object. Should not be called without a previous, + * corresponding gcmem_unsafe_to_reclaim(). + */ +void gcmem_safe_to_reclaim(); + +/* Usage example: + +thread_function() { + ... + gmcmem_unsafe_to_reclaim(); + ... + void *object = extract_object_from_shared_data_strucutre(); + gcmem_free(object); + ... + gmcmem_safe_to_reclaim(); + ... +} +*/ + +#endif diff --git a/external/lib/libgcmalloc_x86_64.a b/external/lib/libgcmalloc_x86_64.a new file mode 100644 index 0000000000000000000000000000000000000000..4f206b8e5b47ece693e27dfa4165b496755bf5ae GIT binary patch literal 7270 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 +#define MEM_MAX_ALLOCATORS 4 + +void memalloc_init(unsigned int index, int id); +void memalloc_term(unsigned int index); +void* memalloc_alloc(unsigned int index, size_t size); +void memalloc_free(int index, void *ptr); + +void memalloc_unsafe_to_reclaim(); +void memalloc_safe_to_reclaim(); +#endif diff --git a/src/linkedlist-lazy/Makefile b/src/linkedlist-lazy/Makefile index 7ffe2b10..283342f1 100644 --- a/src/linkedlist-lazy/Makefile +++ b/src/linkedlist-lazy/Makefile @@ -22,6 +22,9 @@ measurements.o: ssalloc.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/ssalloc.o $(PROF)/ssalloc.c +memalloc.o: ssalloc.o + $(CC) $(CFLAGS) -c -o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(PROF)/memalloc.c + htlock.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/htlock.o $(PROF)/htlock.c @@ -40,8 +43,8 @@ intset.o: linkedlist-lock.h lazy.h clh.o test.o: linkedlist-lock.h lazy.h intset.h $(CC) $(CFLAGS) -c -o $(BUILDIR)/test.o $(TEST_FILE) -main: measurements.o ssalloc.o linkedlist-lock.o lazy.o intset.o test.o htlock.o clh.o - $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/linkedlist-lock.o $(BUILDIR)/lazy.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) +main: measurements.o memalloc.o ssalloc.o linkedlist-lock.o lazy.o intset.o test.o htlock.o clh.o + $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/linkedlist-lock.o $(BUILDIR)/lazy.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) clean: rm -f $(BINS) diff --git a/src/linkedlist-lazy/lazy.c b/src/linkedlist-lazy/lazy.c index 42c1296d..d3d92347 100644 --- a/src/linkedlist-lazy/lazy.c +++ b/src/linkedlist-lazy/lazy.c @@ -151,9 +151,7 @@ parse_delete(intset_l_t *set, skey_t key) node_l_t* c_nxt = curr->next; curr->marked = 1; pred->next = c_nxt; -#if GC == 1 - ssmem_free(alloc, (void*) curr); -#endif + memalloc_free(0, (void*) curr); } done = 1; } diff --git a/src/linkedlist-lazy/linkedlist-lock.c b/src/linkedlist-lazy/linkedlist-lock.c index 3255948e..3a4e94f8 100644 --- a/src/linkedlist-lazy/linkedlist-lock.c +++ b/src/linkedlist-lazy/linkedlist-lock.c @@ -24,24 +24,13 @@ #include "intset.h" #include "utils.h" -__thread ssmem_allocator_t* alloc; +__thread ssmem_allocator_t* allocs[MEM_MAX_ALLOCATORS]; node_l_t* new_node_l(skey_t key, sval_t val, node_l_t* next, int initializing) { volatile node_l_t *node; -#if GC == 1 - if (initializing) /* for initialization AND the coupling algorithm */ - { - node = (volatile node_l_t *) ssalloc(sizeof(node_l_t)); - } - else - { - node = (volatile node_l_t *) ssmem_alloc(alloc, sizeof(node_l_t)); - } -#else - node = (volatile node_l_t *) ssalloc(sizeof(node_l_t)); -#endif + node = (volatile node_l_t *) memalloc_alloc(0, sizeof(node_l_t)); if (node == NULL) { diff --git a/src/linkedlist-lazy/linkedlist-lock.h b/src/linkedlist-lazy/linkedlist-lock.h index 19c8ca2a..6935307b 100644 --- a/src/linkedlist-lazy/linkedlist-lock.h +++ b/src/linkedlist-lazy/linkedlist-lock.h @@ -41,6 +41,7 @@ #include "common.h" #include "utils.h" #include "measurements.h" +#include "memalloc.h" #include "ssalloc.h" #include "ssmem.h" diff --git a/src/linkedlist-lazy/test_simple.c b/src/linkedlist-lazy/test_simple.c index 13ff39ae..dc421bb9 100644 --- a/src/linkedlist-lazy/test_simple.c +++ b/src/linkedlist-lazy/test_simple.c @@ -158,11 +158,7 @@ test(void* thread) #endif seeds = seed_rand(); -#if GC == 1 - alloc = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); - assert(alloc != NULL); - ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, ID); -#endif + memalloc_init(0, ID); RR_INIT(phys_id); barrier_cross(&barrier); @@ -248,10 +244,7 @@ test(void* thread) EXEC_IN_DEC_ID_ORDER_END(&barrier); SSPFDTERM(); -#if GC == 1 - ssmem_term(); - free(alloc); -#endif + memalloc_term(0); THREAD_END(); pthread_exit(NULL); } @@ -261,6 +254,7 @@ main(int argc, char **argv) { set_cpu(0); ssalloc_init(); + memalloc_init(0, num_threads); seeds = seed_rand(); struct option long_options[] = { diff --git a/src/memalloc.c b/src/memalloc.c new file mode 100644 index 00000000..1c003a9c --- /dev/null +++ b/src/memalloc.c @@ -0,0 +1,55 @@ +#include "memalloc.h" +#include + +#if GC == 1 + #include "ssmem.h" + extern __thread ssmem_allocator_t* allocs[MEM_MAX_ALLOCATORS]; +#elif GC == 2 + #include "gcmalloc.h" +#else + #include "ssalloc.h" +#endif + +void memalloc_init(unsigned int index, int id) { + #if GC == 1 + allocs[index] = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); + assert(allocs[index] != NULL); + ssmem_alloc_init_fs_size(allocs[index], SSMEM_DEFAULT_MEM_SIZE, + SSMEM_GC_FREE_SET_SIZE, id); + #elif GC == 2 + ; + #else + ssalloc_init(); + #endif +} + +void memalloc_term(unsigned int index) { + #if GC == 1 + ssmem_term(); + free(allocs[index]); + #elif GC == 2 + ; + #else + ; + #endif +} + +void* memalloc_alloc(unsigned int index, size_t size) { + #if GC == 1 + return ssmem_alloc(allocs[index], size); + #elif GC == 2 + return gcmem_malloc(size); + #else + return ssalloc(size); + #endif +} + +void memalloc_free(int index, void *ptr) { + #if GC == 1 + ssmem_free(allocs[index], ptr); + #elif GC == 2 + gcmem_free(ptr); + #else + ssfree(ptr); + #endif +} From 1ad39ab3dfb73f12985964e5fe89dd1aea3e782c Mon Sep 17 00:00:00 2001 From: Alexandru Ciprian Farcasanu Date: Mon, 14 Dec 2015 10:28:28 +0100 Subject: [PATCH 2/5] Critical sections addded --- src/linkedlist-lazy/intset.c | 15 ++++++++++++--- src/linkedlist-lazy/linkedlist-lock.c | 26 +++++++++++++++++--------- src/memalloc.c | 11 +++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/linkedlist-lazy/intset.c b/src/linkedlist-lazy/intset.c index 24329d04..8de9726c 100644 --- a/src/linkedlist-lazy/intset.c +++ b/src/linkedlist-lazy/intset.c @@ -27,17 +27,26 @@ sval_t set_contains_l(intset_l_t* set, skey_t key) { - return parse_find(set, key); + memalloc_unsafe_to_reclaim(); + sval_t r = parse_find(set, key); + memalloc_safe_to_reclaim(); + return r; } int set_add_l(intset_l_t* set, skey_t key, sval_t val) { - return parse_insert(set, key, val); + memalloc_unsafe_to_reclaim(); + int r = parse_insert(set, key, val); + memalloc_safe_to_reclaim(); + return r; } sval_t set_remove_l(intset_l_t* set, skey_t key) { - return parse_delete(set, key); + memalloc_unsafe_to_reclaim(); + sval_t r = parse_delete(set, key); + memalloc_safe_to_reclaim(); + return r; } diff --git a/src/linkedlist-lazy/linkedlist-lock.c b/src/linkedlist-lazy/linkedlist-lock.c index 3a4e94f8..3bfa7fc4 100644 --- a/src/linkedlist-lazy/linkedlist-lock.c +++ b/src/linkedlist-lazy/linkedlist-lock.c @@ -88,12 +88,10 @@ void node_delete_l(node_l_t *node) { DESTROY_LOCK(&node->lock); -#if GC == 1 - ssfree((void*) node); -#endif + memalloc_free(0, (void*)node); } -void set_delete_l(intset_l_t *set) +static void set_delete_l_impl(intset_l_t *set) { node_l_t *node, *next; @@ -102,14 +100,19 @@ void set_delete_l(intset_l_t *set) { next = node->next; DESTROY_LOCK(&node->lock); - /* free(node); */ - ssfree((void*) node); /* TODO : fix with ssmem */ + memalloc_free(0, (void*)node); node = next; } - ssfree(set); + memalloc_free(0, (void*)set); +} + +void set_delete_l(intset_l_t *set) { + memalloc_unsafe_to_reclaim(); + set_delete_l_impl(set); + memalloc_safe_to_reclaim(); } -int set_size_l(intset_l_t *set) +static int set_size_l_impl(intset_l_t *set) { int size = 0; node_l_t *node; @@ -125,6 +128,11 @@ int set_size_l(intset_l_t *set) return size; } - +int set_size_l(intset_l_t *set) { + memalloc_unsafe_to_reclaim(); + int r = set_size_l_impl(set); + memalloc_unsafe_to_reclaim(); + return r; +} diff --git a/src/memalloc.c b/src/memalloc.c index 1c003a9c..5826d85e 100644 --- a/src/memalloc.c +++ b/src/memalloc.c @@ -53,3 +53,14 @@ void memalloc_free(int index, void *ptr) { ssfree(ptr); #endif } + +void memalloc_unsafe_to_reclaim() { + #if GC == 2 + gcmem_unsafe_to_reclaim(); + #endif +} +void memalloc_safe_to_reclaim() { + #if GC == 2 + gcmem_safe_to_reclaim(); + #endif +} From 9d3ede4e195e3991f928918b1c95deb11b490dd3 Mon Sep 17 00:00:00 2001 From: Alexandru Ciprian Farcasanu Date: Thu, 24 Dec 2015 13:55:45 +0200 Subject: [PATCH 3/5] LL optik and harris --- include/memalloc.h | 18 +++++++++++--- src/linkedlist-harris/Makefile | 7 ++++-- src/linkedlist-harris/harris.c | 11 ++++----- src/linkedlist-harris/intset.c | 13 +++++++--- src/linkedlist-harris/linkedlist.c | 23 +++++------------ src/linkedlist-harris/linkedlist.h | 4 +-- src/linkedlist-harris/test_simple.c | 12 +++------ src/linkedlist-lazy/lazy.c | 2 +- src/linkedlist-lazy/linkedlist-lock.c | 8 +++--- src/linkedlist-lazy/test_simple.c | 6 ++--- src/linkedlist-optik/Makefile | 7 ++++-- src/linkedlist-optik/intset.c | 18 +++++++++++--- src/linkedlist-optik/linkedlist-lock.c | 34 ++++++-------------------- src/linkedlist-optik/linkedlist-lock.h | 4 +-- src/linkedlist-optik/test_simple.c | 12 +++------ src/memalloc.c | 25 ++++++++++++++++--- 16 files changed, 104 insertions(+), 100 deletions(-) diff --git a/include/memalloc.h b/include/memalloc.h index 6caec8b1..b9c74a8e 100644 --- a/include/memalloc.h +++ b/include/memalloc.h @@ -2,12 +2,22 @@ #define _MEM_ALLOC_H #include +#include "ssmem.h" +#include "ssalloc.h" #define MEM_MAX_ALLOCATORS 4 -void memalloc_init(unsigned int index, int id); -void memalloc_term(unsigned int index); -void* memalloc_alloc(unsigned int index, size_t size); -void memalloc_free(int index, void *ptr); +void memalloc_init(int id); +void memalloc_term(); +void* memalloc_alloc(size_t size); +void memalloc_free(void *ptr); + +/* + * Functions to be used when several allocation sizes are required. +*/ +void memalloc_init_idx(unsigned int index, int id); +void memalloc_term_idx(unsigned int index); +void* memalloc_alloc_idx(unsigned int index, size_t size); +void memalloc_free_idx(int index, void *ptr); void memalloc_unsafe_to_reclaim(); void memalloc_safe_to_reclaim(); diff --git a/src/linkedlist-harris/Makefile b/src/linkedlist-harris/Makefile index 73a52ff6..5131522c 100644 --- a/src/linkedlist-harris/Makefile +++ b/src/linkedlist-harris/Makefile @@ -17,6 +17,9 @@ measurements.o: ssalloc.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/ssalloc.o $(PROF)/ssalloc.c +memalloc.o: ssalloc.o + $(CC) $(CFLAGS) -c -o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(PROF)/memalloc.c + linkedlist.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/linkedlist.o linkedlist.c @@ -29,8 +32,8 @@ intset.o: linkedlist.h harris.h test.o: linkedlist.h harris.h intset.h $(CC) $(CFLAGS) -c -o $(BUILDIR)/test.o $(TEST_FILE) -main: measurements.o ssalloc.o linkedlist.o harris.o harris.o intset.o test.o $(TMILB) - $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/ssalloc.o $(BUILDIR)/linkedlist.o $(BUILDIR)/harris.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) +main: measurements.o memalloc.o ssalloc.o linkedlist.o harris.o harris.o intset.o test.o $(TMILB) + $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(BUILDIR)/linkedlist.o $(BUILDIR)/harris.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) clean: -rm -f $(BINS) diff --git a/src/linkedlist-harris/harris.c b/src/linkedlist-harris/harris.c index fc7b4602..95d28268 100644 --- a/src/linkedlist-harris/harris.c +++ b/src/linkedlist-harris/harris.c @@ -132,7 +132,7 @@ harris_search(intset_t *set, skey_t key, node_t **left_node) { node_t* free = cur; cur = (node_t*) get_unmarked_ref((long) cur->next); - ssmem_free(alloc, (void*) free); + memalloc_free((void*) free); } while (cur != right_node); #endif @@ -185,7 +185,7 @@ harris_insert(intset_t *set, skey_t key, sval_t val) #if GC == 1 if (unlikely(newnode != NULL)) { - ssmem_free(alloc, (void*) newnode); + memalloc_free((void*) newnode); } #endif return 0; @@ -242,10 +242,7 @@ harris_delete(intset_t *set, skey_t key) if (likely(ATOMIC_CAS_MB(&left_node->next, right_node, right_node_next))) { -#if GC == 1 - ssmem_free(alloc, (void*) get_unmarked_ref((long) right_node)); -#endif - ; + memalloc_free((void*) get_unmarked_ref((long) right_node)); } else { @@ -261,6 +258,7 @@ set_size(intset_t *set) int size = 0; node_t* node; + memalloc_unsafe_to_reclaim(); /* We have at least 2 elements */ node = (node_t*) get_unmarked_ref((long) set->head->next); while ((node_t*) get_unmarked_ref((long) node->next) != NULL) @@ -268,5 +266,6 @@ set_size(intset_t *set) if (!is_marked_ref((long) node->next)) size++; node = (node_t*) get_unmarked_ref((long) node->next); } + memalloc_safe_to_reclaim(); return size; } diff --git a/src/linkedlist-harris/intset.c b/src/linkedlist-harris/intset.c index 622ca876..07369267 100644 --- a/src/linkedlist-harris/intset.c +++ b/src/linkedlist-harris/intset.c @@ -33,6 +33,7 @@ set_contains(intset_t *set, skey_t key) IO_FLUSH; #endif + memalloc_unsafe_to_reclaim(); #ifdef SEQUENTIAL node_t *prev, *next; @@ -47,7 +48,7 @@ set_contains(intset_t *set, skey_t key) #elif defined LOCKFREE result = harris_find(set, key); #endif - + memalloc_safe_to_reclaim(); return result; } @@ -57,6 +58,7 @@ set_seq_add(intset_t* set, skey_t key, sval_t val) int result; node_t *prev, *next; + memalloc_unsafe_to_reclaim(); prev = set->head; next = prev->next; while (next->key < key) @@ -69,6 +71,7 @@ set_seq_add(intset_t* set, skey_t key, sval_t val) { prev->next = new_node(key, val, next, 0); } + memalloc_safe_to_reclaim(); return result; } @@ -81,11 +84,13 @@ set_add(intset_t *set, skey_t key, skey_t val) printf("++> set_add(%d)\n", (int)val); IO_FLUSH; #endif + memalloc_unsafe_to_reclaim(); #ifdef SEQUENTIAL /* Unprotected */ result = set_seq_add(set, key, val); #elif defined LOCKFREE result = harris_insert(set, key, val); #endif + memalloc_safe_to_reclaim(); return result; } @@ -98,7 +103,7 @@ set_remove(intset_t *set, skey_t key) printf("++> set_remove(%d)\n", (int)val); IO_FLUSH; #endif - + memalloc_unsafe_to_reclaim(); #ifdef SEQUENTIAL /* Unprotected */ node_t *prev, *next; prev = set->head; @@ -112,12 +117,12 @@ set_remove(intset_t *set, skey_t key) if (result) { prev->next = next->next; - free(next); + memalloc_free(next); } #elif defined LOCKFREE result = harris_delete(set, key); #endif - + memalloc_safe_to_reclaim(); return result; } diff --git a/src/linkedlist-harris/linkedlist.c b/src/linkedlist-harris/linkedlist.c index 2d0952bf..127d925c 100644 --- a/src/linkedlist-harris/linkedlist.c +++ b/src/linkedlist-harris/linkedlist.c @@ -23,26 +23,14 @@ #include "linkedlist.h" -__thread ssmem_allocator_t* alloc; +__thread ssmem_allocator_t* allocs[MEM_MAX_ALLOCATORS]; node_t* new_node(skey_t key, sval_t val, node_t* next, int initializing) { volatile node_t* node; -#if GC == 1 - if (unlikely(initializing)) - { - node = (volatile node_t *) ssalloc(sizeof(node_t)); - } - else - { - node = (volatile node_t *) ssmem_alloc(alloc, sizeof(node_t)); - } - -#else - node = (volatile node_t *) ssalloc(sizeof(node_t)); -#endif + node = memalloc_alloc(sizeof(node_t)); if (node == NULL) { @@ -78,14 +66,15 @@ set_new() void set_delete(intset_t *set) { node_t *node, *next; - + memalloc_unsafe_to_reclaim(); node = set->head; while (node != NULL) { next = node->next; - free((void*) node); + memalloc_free((void*) node); node = next; } - free(set); + memalloc_safe_to_reclaim(); + ssfree(set); } diff --git a/src/linkedlist-harris/linkedlist.h b/src/linkedlist-harris/linkedlist.h index c44b28a4..b68be7a2 100644 --- a/src/linkedlist-harris/linkedlist.h +++ b/src/linkedlist-harris/linkedlist.h @@ -38,8 +38,7 @@ #include "common.h" #include "utils.h" #include "measurements.h" -#include "ssalloc.h" -#include "ssmem.h" +#include "memalloc.h" #ifdef DEBUG #define IO_FLUSH fflush(NULL) @@ -50,7 +49,6 @@ #define DEFAULT_EFFECTIVE 1 static volatile int stop; -extern __thread ssmem_allocator_t* alloc; #define TRANSACTIONAL 4 diff --git a/src/linkedlist-harris/test_simple.c b/src/linkedlist-harris/test_simple.c index 1a4325e2..51b4a21d 100644 --- a/src/linkedlist-harris/test_simple.c +++ b/src/linkedlist-harris/test_simple.c @@ -157,11 +157,7 @@ test(void* thread) #endif seeds = seed_rand(); -#if GC == 1 - alloc = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); - assert(alloc != NULL); - ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, ID); -#endif + memalloc_init(ID); RR_INIT(phys_id); @@ -250,10 +246,7 @@ test(void* thread) EXEC_IN_DEC_ID_ORDER_END(&barrier); SSPFDTERM(); -#if GC == 1 - ssmem_term(); - free(alloc); -#endif + memalloc_term(); THREAD_END(); pthread_exit(NULL); } @@ -263,6 +256,7 @@ main(int argc, char **argv) { set_cpu(0); ssalloc_init(); + memalloc_init(num_threads); seeds = seed_rand(); struct option long_options[] = { diff --git a/src/linkedlist-lazy/lazy.c b/src/linkedlist-lazy/lazy.c index d3d92347..3f60a68b 100644 --- a/src/linkedlist-lazy/lazy.c +++ b/src/linkedlist-lazy/lazy.c @@ -151,7 +151,7 @@ parse_delete(intset_l_t *set, skey_t key) node_l_t* c_nxt = curr->next; curr->marked = 1; pred->next = c_nxt; - memalloc_free(0, (void*) curr); + memalloc_free((void*) curr); } done = 1; } diff --git a/src/linkedlist-lazy/linkedlist-lock.c b/src/linkedlist-lazy/linkedlist-lock.c index 3bfa7fc4..610cf6dc 100644 --- a/src/linkedlist-lazy/linkedlist-lock.c +++ b/src/linkedlist-lazy/linkedlist-lock.c @@ -30,7 +30,7 @@ node_l_t* new_node_l(skey_t key, sval_t val, node_l_t* next, int initializing) { volatile node_l_t *node; - node = (volatile node_l_t *) memalloc_alloc(0, sizeof(node_l_t)); + node = (volatile node_l_t *) memalloc_alloc(sizeof(node_l_t)); if (node == NULL) { @@ -88,7 +88,7 @@ void node_delete_l(node_l_t *node) { DESTROY_LOCK(&node->lock); - memalloc_free(0, (void*)node); + memalloc_free((void*)node); } static void set_delete_l_impl(intset_l_t *set) @@ -100,10 +100,10 @@ static void set_delete_l_impl(intset_l_t *set) { next = node->next; DESTROY_LOCK(&node->lock); - memalloc_free(0, (void*)node); + memalloc_free((void*)node); node = next; } - memalloc_free(0, (void*)set); + ssfree((void*)set); } void set_delete_l(intset_l_t *set) { diff --git a/src/linkedlist-lazy/test_simple.c b/src/linkedlist-lazy/test_simple.c index dc421bb9..7c37935c 100644 --- a/src/linkedlist-lazy/test_simple.c +++ b/src/linkedlist-lazy/test_simple.c @@ -158,7 +158,7 @@ test(void* thread) #endif seeds = seed_rand(); - memalloc_init(0, ID); + memalloc_init(ID); RR_INIT(phys_id); barrier_cross(&barrier); @@ -244,7 +244,7 @@ test(void* thread) EXEC_IN_DEC_ID_ORDER_END(&barrier); SSPFDTERM(); - memalloc_term(0); + memalloc_term(); THREAD_END(); pthread_exit(NULL); } @@ -254,7 +254,7 @@ main(int argc, char **argv) { set_cpu(0); ssalloc_init(); - memalloc_init(0, num_threads); + memalloc_init(num_threads); seeds = seed_rand(); struct option long_options[] = { diff --git a/src/linkedlist-optik/Makefile b/src/linkedlist-optik/Makefile index 9d8c2af7..b9769a2e 100644 --- a/src/linkedlist-optik/Makefile +++ b/src/linkedlist-optik/Makefile @@ -22,6 +22,9 @@ measurements.o: ssalloc.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/ssalloc.o $(PROF)/ssalloc.c +memalloc.o: ssalloc.o + $(CC) $(CFLAGS) -c -o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(PROF)/memalloc.c + htlock.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/htlock.o $(PROF)/htlock.c @@ -40,8 +43,8 @@ intset.o: linkedlist-lock.h linkedlist-optik.h clh.o test.o: linkedlist-lock.h linkedlist-optik.h intset.h $(CC) $(CFLAGS) -c -o $(BUILDIR)/test.o $(TEST_FILE) -main: measurements.o ssalloc.o linkedlist-lock.o linkedlist-optik.o intset.o test.o htlock.o clh.o - $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/linkedlist-lock.o $(BUILDIR)/linkedlist-optik.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) +main: measurements.o memalloc.o ssalloc.o linkedlist-lock.o linkedlist-optik.o intset.o test.o htlock.o clh.o + $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/linkedlist-lock.o $(BUILDIR)/linkedlist-optik.o $(BUILDIR)/intset.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) clean: rm -f $(BINS) diff --git a/src/linkedlist-optik/intset.c b/src/linkedlist-optik/intset.c index 5e4908f0..e35cfed1 100644 --- a/src/linkedlist-optik/intset.c +++ b/src/linkedlist-optik/intset.c @@ -27,17 +27,29 @@ inline sval_t set_contains_l(intset_l_t* set, skey_t key) { - return optik_find(set, key); + sval_t r; + memalloc_unsafe_to_reclaim(); + r = optik_find(set, key); + memalloc_safe_to_reclaim(); + return r; } inline int set_add_l(intset_l_t* set, skey_t key, sval_t val) { - return optik_insert(set, key, val); + int r; + memalloc_unsafe_to_reclaim(); + r = optik_insert(set, key, val); + memalloc_safe_to_reclaim(); + return r; } inline sval_t set_remove_l(intset_l_t* set, skey_t key) { - return optik_delete(set, key); + sval_t r; + memalloc_unsafe_to_reclaim(); + r = optik_delete(set, key); + memalloc_safe_to_reclaim(); + return r; } diff --git a/src/linkedlist-optik/linkedlist-lock.c b/src/linkedlist-optik/linkedlist-lock.c index 15fcbd8d..b42b0b26 100644 --- a/src/linkedlist-optik/linkedlist-lock.c +++ b/src/linkedlist-optik/linkedlist-lock.c @@ -24,24 +24,13 @@ #include "intset.h" #include "utils.h" -__thread ssmem_allocator_t* alloc; +__thread ssmem_allocator_t* allocs[MEM_MAX_ALLOCATORS]; node_l_t* new_node_l(skey_t key, sval_t val, node_l_t* next, int initializing) { volatile node_l_t *node; -#if GC == 1 - if (initializing) /* for initialization AND the coupling algorithm */ - { - node = (volatile node_l_t *) ssalloc(sizeof(node_l_t)); - } - else - { - node = (volatile node_l_t *) ssmem_alloc(alloc, sizeof(node_l_t)); - } -#else - node = (volatile node_l_t *) ssalloc(sizeof(node_l_t)); -#endif + node = memalloc_alloc(sizeof(node_l_t)); if (node == NULL) { @@ -76,7 +65,6 @@ intset_l_t *set_new_l() } max = new_node_l(KEY_MAX, 0, NULL, 1); - /* ssalloc_align_alloc(0); */ min = new_node_l(KEY_MIN, 0, max, 1); set->head = min; @@ -87,24 +75,22 @@ intset_l_t *set_new_l() inline void node_delete_l(node_l_t *node) { -#if GC == 1 - ssmem_free(alloc, (void*) node); -#endif + memalloc_free((void*)node); } void set_delete_l(intset_l_t *set) { node_l_t *node, *next; - + memalloc_unsafe_to_reclaim(); node = set->head; while (node != NULL) { next = node->next; DESTROY_LOCK(&node->lock); - /* free(node); */ - ssfree((void*) node); /* TODO : fix with ssmem */ + memalloc_free((void*)node); node = next; } + memalloc_safe_to_reclaim(); ssfree(set); } @@ -112,7 +98,7 @@ int set_size_l(intset_l_t *set) { int size = 0; node_l_t *node; - + memalloc_unsafe_to_reclaim(); /* We have at least 2 elements */ node = set->head->next; while (node->next != NULL) @@ -120,10 +106,6 @@ int set_size_l(intset_l_t *set) size++; node = node->next; } - + memalloc_safe_to_reclaim(); return size; } - - - - diff --git a/src/linkedlist-optik/linkedlist-lock.h b/src/linkedlist-optik/linkedlist-lock.h index d13c0c4f..46f32855 100644 --- a/src/linkedlist-optik/linkedlist-lock.h +++ b/src/linkedlist-optik/linkedlist-lock.h @@ -42,15 +42,13 @@ #include "common.h" #include "utils.h" #include "measurements.h" -#include "ssalloc.h" -#include "ssmem.h" +#include "memalloc.h" #define DEFAULT_LOCKTYPE 2 #define DEFAULT_ALTERNATE 0 #define DEFAULT_EFFECTIVE 1 static volatile int stop; -extern __thread ssmem_allocator_t* alloc; typedef volatile struct node_l { diff --git a/src/linkedlist-optik/test_simple.c b/src/linkedlist-optik/test_simple.c index c41b15b8..8310f22d 100644 --- a/src/linkedlist-optik/test_simple.c +++ b/src/linkedlist-optik/test_simple.c @@ -158,11 +158,7 @@ test(void* thread) #endif seeds = seed_rand(); -#if GC == 1 - alloc = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); - assert(alloc != NULL); - ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, ID); -#endif + memalloc_init(ID); RR_INIT(phys_id); barrier_cross(&barrier); @@ -250,10 +246,7 @@ test(void* thread) EXEC_IN_DEC_ID_ORDER_END(&barrier); SSPFDTERM(); -#if GC == 1 - ssmem_term(); - free(alloc); -#endif + memalloc_term(); THREAD_END(); pthread_exit(NULL); } @@ -265,6 +258,7 @@ main(int argc, char **argv) { set_cpu(0); ssalloc_init(); + memalloc_init(num_threads); seeds = seed_rand(); struct option long_options[] = { diff --git a/src/memalloc.c b/src/memalloc.c index 5826d85e..70abdb4c 100644 --- a/src/memalloc.c +++ b/src/memalloc.c @@ -10,7 +10,23 @@ #include "ssalloc.h" #endif -void memalloc_init(unsigned int index, int id) { +void memalloc_init(int id) { + memalloc_init_idx(0, id); +} + +void memalloc_term() { + memalloc_term_idx(0); +} + +void* memalloc_alloc(size_t size) { + return memalloc_alloc_idx(0, size); +} + +void memalloc_free(void *ptr) { + memalloc_free_idx(0, ptr); +} + +void memalloc_init_idx(unsigned int index, int id) { #if GC == 1 allocs[index] = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); assert(allocs[index] != NULL); @@ -23,7 +39,8 @@ void memalloc_init(unsigned int index, int id) { #endif } -void memalloc_term(unsigned int index) { + +void memalloc_term_idx(unsigned int index) { #if GC == 1 ssmem_term(); free(allocs[index]); @@ -34,7 +51,7 @@ void memalloc_term(unsigned int index) { #endif } -void* memalloc_alloc(unsigned int index, size_t size) { +void* memalloc_alloc_idx(unsigned int index, size_t size) { #if GC == 1 return ssmem_alloc(allocs[index], size); #elif GC == 2 @@ -44,7 +61,7 @@ void* memalloc_alloc(unsigned int index, size_t size) { #endif } -void memalloc_free(int index, void *ptr) { +void memalloc_free_idx(int index, void *ptr) { #if GC == 1 ssmem_free(allocs[index], ptr); #elif GC == 2 From 759551fe14f5785fbfa3cae7f56702ea1d32b277 Mon Sep 17 00:00:00 2001 From: Alexandru Ciprian Farcasanu Date: Sat, 26 Dec 2015 11:16:26 +0200 Subject: [PATCH 4/5] Htable copy --- src/hashtable-copy/Makefile | 8 +++-- src/hashtable-copy/copy_on_write.c | 50 +++++++++++++++++++++++------- src/hashtable-copy/copy_on_write.h | 3 +- src/hashtable-copy/test_simple.c | 12 ++----- 4 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/hashtable-copy/Makefile b/src/hashtable-copy/Makefile index af70d030..5b42f76c 100644 --- a/src/hashtable-copy/Makefile +++ b/src/hashtable-copy/Makefile @@ -22,6 +22,10 @@ measurements.o: ssalloc.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/ssalloc.o $(PROF)/ssalloc.c +memalloc.o: ssalloc.o + $(CC) $(CFLAGS) -c -o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(PROF)/memalloc.c + + htlock.o: $(CC) $(CFLAGS) -c -o $(BUILDIR)/htlock.o $(PROF)/htlock.c @@ -34,8 +38,8 @@ copy_on_write.o: htlock.o clh.o test.o: copy_on_write.h $(CC) $(CFLAGS) -c -o $(BUILDIR)/test.o $(TEST_FILE) -main: measurements.o ssalloc.o copy_on_write.o test.o htlock.o clh.o - $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/copy_on_write.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) +main: measurements.o memalloc.o ssalloc.o copy_on_write.o test.o htlock.o clh.o + $(CC) $(CFLAGS) $(BUILDIR)/measurements.o $(BUILDIR)/memalloc.o $(BUILDIR)/ssalloc.o $(BUILDIR)/htlock.o $(BUILDIR)/clh.o $(BUILDIR)/copy_on_write.o $(BUILDIR)/test.o -o $(BINS) $(LDFLAGS) clean: rm -f $(BINS) diff --git a/src/hashtable-copy/copy_on_write.c b/src/hashtable-copy/copy_on_write.c index 638ddb11..9cf24e9b 100644 --- a/src/hashtable-copy/copy_on_write.c +++ b/src/hashtable-copy/copy_on_write.c @@ -23,8 +23,7 @@ #include "copy_on_write.h" -__thread ssmem_allocator_t* alloc; - +__thread ssmem_allocator_t* allocs[MEM_MAX_ALLOCATORS]; size_t array_ll_fixed_size; @@ -32,7 +31,7 @@ static inline volatile array_ll_t* array_ll_new_init(size_t size) { array_ll_t* all; - all = ssalloc_aligned(CACHE_LINE_SIZE, sizeof(array_ll_t) + (array_ll_fixed_size * sizeof(kv_t))); + all = memalloc_alloc(sizeof(array_ll_t) + (array_ll_fixed_size * sizeof(kv_t))); assert(all != NULL); all->size = size; @@ -45,7 +44,7 @@ static inline array_ll_t* array_ll_new(size_t size) { array_ll_t* all; - all = ssmem_alloc(alloc, sizeof(array_ll_t) + (array_ll_fixed_size * sizeof(kv_t))); + all = memalloc_alloc(sizeof(array_ll_t) + (array_ll_fixed_size * sizeof(kv_t))); assert(all != NULL); all->size = size; @@ -95,7 +94,7 @@ copy_on_write_new(size_t num_buckets) sval_t -cpy_search(copy_on_write_t* set, skey_t key) +cpy_search_impl(copy_on_write_t* set, skey_t key) { size_t bucket = key & set->hash; @@ -113,6 +112,14 @@ cpy_search(copy_on_write_t* set, skey_t key) return 0; } +sval_t +cpy_search(copy_on_write_t* set, skey_t key) { + memalloc_unsafe_to_reclaim(); + sval_t r = cpy_search_impl(set, key); + memalloc_safe_to_reclaim(); + return r; +} + sval_t cpy_array_search(array_ll_t* all_cur, skey_t key) { @@ -129,7 +136,7 @@ cpy_array_search(array_ll_t* all_cur, skey_t key) } sval_t -cpy_delete(copy_on_write_t* set, skey_t key) +cpy_delete_impl(copy_on_write_t* set, skey_t key) { size_t bucket = key & set->hash; array_ll_t* all_old; @@ -166,11 +173,11 @@ cpy_delete(copy_on_write_t* set, skey_t key) if (removed) { set->array[bucket] = all_new; - ssmem_free(alloc, (void*) all_old); + memalloc_free((void*) all_old); } else { - ssmem_free(alloc, (void*) all_new); + memalloc_free((void*) all_new); } GL_UNLOCK(set->lock); @@ -178,8 +185,17 @@ cpy_delete(copy_on_write_t* set, skey_t key) return removed; } +sval_t +cpy_delete(copy_on_write_t* set, skey_t key) { + sval_t r; + memalloc_unsafe_to_reclaim(); + r = cpy_delete_impl(set, key); + memalloc_safe_to_reclaim(); + return r; +} + int -cpy_insert(copy_on_write_t* set, skey_t key, sval_t val) +cpy_insert_impl(copy_on_write_t* set, skey_t key, sval_t val) { size_t bucket = key & set->hash; array_ll_t* all_old; @@ -203,7 +219,7 @@ cpy_insert(copy_on_write_t* set, skey_t key, sval_t val) { if (unlikely(all_old->kvs[i].key == key)) { - ssmem_free(alloc, (void*) all_new); + memalloc_free((void*) all_new); GL_UNLOCK(set->lock); UNLOCK(set->lock + bucket); return 0; @@ -216,23 +232,33 @@ cpy_insert(copy_on_write_t* set, skey_t key, sval_t val) all_new->kvs[i].val = val; set->array[bucket] = all_new; - ssmem_free(alloc, (void*) all_old); + memalloc_free((void*) all_old); GL_UNLOCK(set->lock); UNLOCK(set->lock + bucket); return 1; } +int +cpy_insert(copy_on_write_t* set, skey_t key, sval_t val) { + int r; + memalloc_unsafe_to_reclaim(); + r = cpy_insert_impl(set, key, val); + memalloc_safe_to_reclaim(); + return r; +} + size_t copy_on_write_size(copy_on_write_t* set) { size_t s = 0; int i; + memalloc_unsafe_to_reclaim(); for (i = 0; i < set->num_buckets; i++) { s += set->array[i]->size; } - + memalloc_safe_to_reclaim(); return s; }; diff --git a/src/hashtable-copy/copy_on_write.h b/src/hashtable-copy/copy_on_write.h index b91be013..ebabd292 100644 --- a/src/hashtable-copy/copy_on_write.h +++ b/src/hashtable-copy/copy_on_write.h @@ -41,8 +41,7 @@ #include "common.h" #include "utils.h" #include "measurements.h" -#include "ssalloc.h" -#include "ssmem.h" +#include "memalloc.h" #define DEFAULT_ALTERNATE 0 #define DEFAULT_EFFECTIVE 1 diff --git a/src/hashtable-copy/test_simple.c b/src/hashtable-copy/test_simple.c index 11a70fbb..e5f02f29 100644 --- a/src/hashtable-copy/test_simple.c +++ b/src/hashtable-copy/test_simple.c @@ -162,11 +162,7 @@ test(void* thread) init_clh_thread(&clh_local_p); #endif -#if GC == 1 - alloc = (ssmem_allocator_t*) malloc(sizeof(ssmem_allocator_t)); - assert(alloc != NULL); - ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, ID); -#endif + memalloc_init(ID); RR_INIT(phys_id); barrier_cross(&barrier); @@ -250,10 +246,7 @@ test(void* thread) EXEC_IN_DEC_ID_ORDER_END(&barrier); SSPFDTERM(); -#if GC == 1 - ssmem_term(); - free(alloc); -#endif + memalloc_term(); THREAD_END(); pthread_exit(NULL); } @@ -263,6 +256,7 @@ main(int argc, char **argv) { set_cpu(0); ssalloc_init(); + memalloc_init(num_threads); seeds = seed_rand(); struct option long_options[] = { From 481a258518a2df004d7bc9a8ef6ead20beab574c Mon Sep 17 00:00:00 2001 From: Alexandru Ciprian Farcasanu Date: Sat, 26 Dec 2015 12:49:45 +0200 Subject: [PATCH 5/5] Ssfree does no free --- src/memalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memalloc.c b/src/memalloc.c index 70abdb4c..e524139d 100644 --- a/src/memalloc.c +++ b/src/memalloc.c @@ -67,7 +67,7 @@ void memalloc_free_idx(int index, void *ptr) { #elif GC == 2 gcmem_free(ptr); #else - ssfree(ptr); + //ssfree(ptr); #endif }