Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt threadcached and ycsb to work with multi-instanced Montage and … #10

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ LDIRS+=$(NVM_MALLOC_DIR)
# libraries to link against (are expected to be in the above directories,
# or they are system default)
# LIBS :=-l:libjemalloc.so.2 -lstm -lparharness -lpthread -lhwloc -lm -lrt
LIBS :=-l:libjemalloc.so.2 -lpthread -lhwloc -lralloc -lgomp -latomic
LIBS :=-ljemalloc -lpthread -lhwloc -lralloc -lgomp -latomic
LIBS+=-lnvmmalloc
# directories that should be built first using recursive make.
# You should avoid this in general, but it's useful for building
Expand Down
17 changes: 6 additions & 11 deletions ext/ralloc/src/ralloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,13 @@ void* Ralloc::reallocate(void* ptr, size_t new_size){
return new_ptr;
}

struct RallocHolder{
Ralloc* ralloc_instance;
inline int init(int thd_num, const char* _id, uint64_t size) {
ralloc_instance = new Ralloc(thd_num, _id,size);
return (int)ralloc_instance->is_restart();
}
~RallocHolder(){
delete ralloc_instance;
}
};
int RallocHolder::init(int thd_num, const char* _id, uint64_t size){
ralloc_instance = new Ralloc(thd_num, _id,size);
RP_set_tid(0);// set tid for main thread
return (int)ralloc_instance->is_restart();
}

static RallocHolder _holder;
RallocHolder _holder;
/*
* mmap the existing heap file corresponding to id. aka restart,
* and if multiple heaps exist, print out and let user select;
Expand Down
21 changes: 16 additions & 5 deletions ext/ralloc/src/ralloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class Ralloc{
return 0;
}

inline bool is_initialized(){
return initialized;
}

static void set_tid(int tid_){
// Wentao: we deliberately allow tid to be set more than once
// assert((tid==-1 || tid==0) && "tid set more than once!");
Expand All @@ -119,18 +123,25 @@ class Ralloc{
}
};

// RAII ralloc global instance holder for global API
struct RallocHolder{
Ralloc* ralloc_instance;
int init(int thd_num, const char* _id, uint64_t size);
~RallocHolder(){
delete ralloc_instance;
}
};

extern RallocHolder _holder;

/* return 1 if it's a restart, otherwise 0. */
extern "C" int RP_init(const char* _id, uint64_t size = 5*1024*1024*1024ULL, int thd_num = 100);

template<class T>
T* RP_get_root(uint64_t i){
#if 0
assert(ralloc::initialized);
return ralloc::base_md->get_root<T>(i);
#endif
return _holder.ralloc_instance->get_root<T>(i);
}


std::vector<InuseRecovery::iterator> RP_recover(int n = 1);
extern "C"{
#else /* __cplusplus ends */
Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ obj/libthreadcached.a: $(PROT_OBJ)
obj/libthreadcached_nvm.a: $(PROT_OBJ_NVM) $(MONTAGE_PATH)/ext/ralloc/libralloc.a
ar -rcs $@ $^

obj/libthreadcached_montage.a: $(PROT_OBJ_MONTAGE) $(MONTAGE_PATH)/ext/ralloc/libralloc.a $(MONTAGE_PATH)/lib/libPDSHarness.a
obj/libthreadcached_montage.a: $(PROT_OBJ_MONTAGE) $(MONTAGE_PATH)/ext/ralloc/libralloc.a $(MONTAGE_PATH)/lib/libMontage.a
ar -rcs $@ $^

obj/%.o: src/%.cc
Expand Down
4 changes: 3 additions & 1 deletion ext/threadcached/include/memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ extern unsigned stats_id;

using namespace pds;
struct item : public PBlk{
item(){};
item(const item& oth): PBlk(oth){};
#else
struct item{
#endif
Expand All @@ -415,7 +417,7 @@ struct item{
int nbytes; /* size of data */
unsigned short refcount;
uint8_t nsuffix; /* length of flags-and-length string */
uint8_t it_flags; /* ITEM_* above */
uint8_t it_flags=0; /* ITEM_* above */
uint8_t slabs_clsid;/* which slab class we're in */
uint8_t nkey; /* key length, w/terminating null and padding */
/* this odd type prevents type-punning issues when we do
Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/include/pku_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void memcached_start_server();
memcached_return_t
memcached_end ();

void memcached_init();
void memcached_init(int thd_num);

void memcached_close();

Expand Down
7 changes: 5 additions & 2 deletions ext/threadcached/src/items.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ item *do_item_alloc_pull(const size_t ntotal, const unsigned int id) {
uint64_t total_bytes = 0;
/* Try to reclaim memory first */
lru_pull_tail(id, COLD_LRU, 0, 0, 0, NULL);
#ifdef MONTAGE
it = (item*)PMALLOC(ntotal);
#else
it = (item*)pm_malloc(ntotal);

#endif
if (it == NULL) {
// We send '0' in for "total_bytes" as this routine is always
// pulling to evict, or forcing HOT -> COLD migration.
Expand Down Expand Up @@ -666,7 +669,7 @@ int lru_pull_tail(const int orig_id, const int cur_lru,
*/
switch (cur_lru) {
case HOT_LRU:
limit = total_bytes * 20 / 100;
limit = total_bytes * 20 / 100; __attribute__ ((fallthrough));
case WARM_LRU:
if (limit == 0)
limit = total_bytes * 40 / 100;
Expand Down
18 changes: 9 additions & 9 deletions ext/threadcached/src/itoa_ljust.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ static inline int digits( uint32_t u, unsigned k, int* d, char** p, int n ) {

static inline char* itoa(uint32_t u, char* p, int d, int n) {
switch(n) {
case 10: d = u / 100000000; p = out2( d, p );
case 9: u -= d * 100000000;
case 8: d = u / 1000000; p = out2( d, p );
case 7: u -= d * 1000000;
case 6: d = u / 10000; p = out2( d, p );
case 5: u -= d * 10000;
case 4: d = u / 100; p = out2( d, p );
case 3: u -= d * 100;
case 2: d = u / 1; p = out2( d, p );
case 10: d = u / 100000000; p = out2( d, p ); __attribute__ ((fallthrough));
case 9: u -= d * 100000000; __attribute__ ((fallthrough));
case 8: d = u / 1000000; p = out2( d, p ); __attribute__ ((fallthrough));
case 7: u -= d * 1000000; __attribute__ ((fallthrough));
case 6: d = u / 10000; p = out2( d, p ); __attribute__ ((fallthrough));
case 5: u -= d * 10000; __attribute__ ((fallthrough));
case 4: d = u / 100; p = out2( d, p ); __attribute__ ((fallthrough));
case 3: u -= d * 100; __attribute__ ((fallthrough));
case 2: d = u / 1; p = out2( d, p ); __attribute__ ((fallthrough));
case 1: ;
}
*p = '\0';
Expand Down
4 changes: 2 additions & 2 deletions ext/threadcached/src/murmur3_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ uint32_t MurmurHash3_x86_32 ( const void * key, size_t length)

switch(length & 3)
{
case 3: k1 ^= tail[2] << 16;
case 2: k1 ^= tail[1] << 8;
case 3: k1 ^= tail[2] << 16; __attribute__ ((fallthrough));
case 2: k1 ^= tail[1] << 8; __attribute__ ((fallthrough));
case 1: k1 ^= tail[0];
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
Expand Down
7 changes: 5 additions & 2 deletions ext/threadcached/src/pku_memcached.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,18 @@ HODOR_FUNC_EXPORT(memcached_start_server, 0);
#include <errno.h>
#include <unistd.h>
bool server_flag = false;
void memcached_init(){
void memcached_init(int thd_num){
if (!run_once){
run_once = true;
} else return;
// Wt: montage init is done before memcached_init
// TODO: move montage inti into memcached_init
// this part is initializing the global Ralloc heap for transient allocation
#ifdef RALLOC
char* heap_prefix = (char*) malloc(L_cuserid+6);
cuserid(heap_prefix);
strcat(heap_prefix, "_memcached");
is_restart = RP_init(heap_prefix, MEMORY_MAX);
is_restart = RP_init(heap_prefix, MEMORY_MAX, thd_num);
free(heap_prefix);
#else
is_restart = pm_init();
Expand Down
6 changes: 2 additions & 4 deletions ext/threadcached/src/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ enum store_item_type store_item(item *item, int comm) {
#endif
ret = do_store_item(item, comm, hv).first;
#ifdef MONTAGE
if(ret == STORED){
// Wentao: it is safe to persist item after do_store_item because of the lock
esys->register_alloc_pblk(item, epochs[_tid].ui);
}
// Wentao: PMALLOC is used to allocate new items, so we don't
// explicitly register allocated blocks anymore
END_OP;
#endif
item_unlock(hv);
Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/test/end.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string.h>

int main(){
memcached_init();
memcached_init(1);
memcached_end();
memcached_close();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/test/get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define BUFF_LEN 32
int main(){
memcached_init();
memcached_init(1);
std::string name = "chris";

char nbuff[BUFF_LEN];
Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/test/insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ char *keys[N_INSERT];
char *dats[N_INSERT];

int main(){
memcached_init();
memcached_init(1);
std::string name = "chris";
std::string quality = " tests memcached";

Expand Down
2 changes: 1 addition & 1 deletion ext/threadcached/test/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
extern bool server_flag;
int main(){
server_flag = true;
memcached_init();
memcached_init(1);
memcached_start_server();
}
2 changes: 1 addition & 1 deletion ext/threadcached/threadcached.diff
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ diff -r ../MemcachedProtectedLibrary/Makefile ./ext/threadcached/Makefile
> obj/libthreadcached_nvm.a: $(PROT_OBJ_NVM) $(MONTAGE_PATH)/ext/ralloc/test/libralloc.a
> ar -rcs $@ $^
>
> obj/libthreadcached_montage.a: $(PROT_OBJ_MONTAGE) $(MONTAGE_PATH)/ext/ralloc/test/libralloc.a $(MONTAGE_PATH)/lib/libPDSHarness.a
> obj/libthreadcached_montage.a: $(PROT_OBJ_MONTAGE) $(MONTAGE_PATH)/ext/ralloc/test/libralloc.a $(MONTAGE_PATH)/lib/libMontage.a
> ar -rcs $@ $^
61c80,86
< $(CXX) -c $^ $(OPTS) -o $@
Expand Down
7 changes: 4 additions & 3 deletions ext/ycsb-tcd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CFLAGS += -I$(MONTAGE_PATH)/ext/tbb/include
#CFLAGS=-std=c++11 -O0 -g -Wall -pthread -I./ -DTCD -g -m64
LDFLAGS= -lpthread -levent \
-L../threadcached/obj \
-ldl -ljemalloc -lhwloc
-ldl -ljemalloc -lhwloc -lgomp
SUBDIRS=core db cache_test
SUBSRCS=$(wildcard core/*.cc) $(wildcard db/*.cc) $(wildcard cache_test/*.cc)
OBJECTS=$(SUBSRCS:.cc=.o)
Expand All @@ -16,8 +16,9 @@ EXEC=ycsbc
ifeq ($(OPT),montage)
CFLAGS += -DMONTAGE
CFLAGS += -DRALLOC
LDFLAGS += -latomic
LDFLAGS += -lthreadcached_montage
LDFLAGS += -L$(MONTAGE_PATH)/lib -lPDSHarness
LDFLAGS += -L$(MONTAGE_PATH)/lib -lMontage
LDFLAGS += -L$(MONTAGE_PATH)/ext/ralloc -lralloc
endif

Expand All @@ -34,7 +35,7 @@ ifeq ($(OPT),dram)
LDFLAGS += -lthreadcached
endif

# PDSHarness
# Montage

# Ralloc

Expand Down
9 changes: 5 additions & 4 deletions ext/ycsb-tcd/ycsbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ exit(1);

#ifdef MONTAGE
pds::init_thread(tid);
#elif defined(RALLOC)
RP_set_tid(tid);
#endif

db->Init(tid);
Expand All @@ -90,9 +92,9 @@ unsigned cache_test_item_size = 0;
int main(const int argc, char *argv[]) {
// TODO: include GlobalTestConfig, construct command line args, and initialize EpochSys

memcached_init();
utils::Properties props;
string file_name = ParseCommandLine(argc, argv, props);
const int num_threads = stoi(props.GetProperty("threadcount", "1"));
#ifdef MONTAGE
// Ralloc init and close are already handled by memcached_init()
// init epoch system with artificial gtc, only for passing t and d
Expand Down Expand Up @@ -131,8 +133,9 @@ int main(const int argc, char *argv[]) {
hwloc_get_type_depth(gtc.topology, HWLOC_OBJ_PU));
std::cout<<"initial affinity built"<<std::endl;
gtc.buildAffinity(gtc.affinities);
// pds::init(&gtc);
pds::init(&gtc);
#endif
memcached_init(num_threads);
if (do_cache_test_flag){
do_cache_test();
memcached_close();
Expand All @@ -146,8 +149,6 @@ int main(const int argc, char *argv[]) {
ycsbc::CoreWorkload wl;
wl.Init(props);

const int num_threads = stoi(props.GetProperty("threadcount", "1"));

// Loads data
vector<future<int>> actual_ops;
int total_ops = stoi(props[ycsbc::CoreWorkload::RECORD_COUNT_PROPERTY]);
Expand Down
6 changes: 5 additions & 1 deletion src/utils/Persistent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class Persistent {
}

static void init_thread(GlobalTestConfig* gtc, LocalTestConfig* ltc){
Ralloc::set_tid(ltc->tid);
init_thread(ltc->tid);
}

static void init_thread(int tid_){
Ralloc::set_tid(tid_);
}
};

Expand Down