Skip to content

Commit d97a4cb

Browse files
Merge pull request #36 from utsaslab/lock-free-queue
Added new lock free queue implementation for staging file mappings
2 parents 343d1e7 + a309c33 commit d97a4cb

File tree

13 files changed

+1144
-860
lines changed

13 files changed

+1144
-860
lines changed

splitfs/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ NVP_NON_TEMPORAL=non_temporal.o
1313
NVP_DELAY=perf_delay/add_delay.o
1414
NVP_TIMER=timers.o
1515
NVP_TBL_MMAP=tbl_mmaps.o
16+
NVP_UTILS=utils.o
17+
NVP_LFQUEUE=lfq.c
1618

1719
all: sofiles $(COMMON_OBJ)
1820
#$(NVP_STACK) $(NVP_LOG) $(NVP_LRU_CACHE)
@@ -28,7 +30,7 @@ sofiles: $(COMMON_OBJ) $(NVP_SOFILES)
2830

2931
# The only .so which doesn't follow the naming convention for its underlying file.
3032
libnvp.so: fileops_hub.o $(COMMON_OBJ)
31-
$(CC) $(CLFAGS) -shared -Wl,-soname,$@ -o $@ $^ -ldl -funroll-loops -L. -llfds711 -lrt
33+
$(CC) $(CLFAGS) -shared -Wl,-soname,$@ -o $@ $^ -ldl -funroll-loops -L. -lrt
3234

3335
# Lives in a different directory.
3436
#libmoneta.so:
@@ -41,8 +43,8 @@ libnvp.so: fileops_hub.o $(COMMON_OBJ)
4143
#libfileops_nvp.so: fileops_nvp.o $(COMMON_OBJ) copy_user_nocache.o
4244
# $(CC) $(CFLAGS) -shared -Wl,-soname,$@ -o $@ $< $(COMMON_OBJ) copy_user_nocache.o -ldl
4345

44-
libfileops_nvp.so: fileops_nvp.o $(COMMON_OBJ) $(NVP_NON_TEMPORAL) $(NVP_DELAY) $(NVP_STACK) $(NVP_TBL_MMAP) $(NVP_LOG) $(NVP_LRU_CACHE) $(NVP_TIMER)
45-
$(CC) $(CFLAGS) -shared -Wl,-soname,$@ -o $@ $< $(COMMON_OBJ) $(NVP_NON_TEMPORAL) $(NVP_DELAY) $(NVP_STACK) $(NVP_TBL_MMAP) $(NVP_LOG) $(NVP_LRU_CACHE) $(NVP_TIMER) -ldl -funroll-loops -L. -llfds711 -lrt
46+
libfileops_nvp.so: fileops_nvp.o $(COMMON_OBJ) $(NVP_LFQUEUE) $(NVP_UTILS) $(NVP_NON_TEMPORAL) $(NVP_DELAY) $(NVP_STACK) $(NVP_TBL_MMAP) $(NVP_LOG) $(NVP_LRU_CACHE) $(NVP_TIMER)
47+
$(CC) $(CFLAGS) -shared -Wl,-soname,$@ -o $@ $< $(COMMON_OBJ) $(NVP_LFQUEUE) $(NVP_UTILS) $(NVP_NON_TEMPORAL) $(NVP_DELAY) $(NVP_STACK) $(NVP_TBL_MMAP) $(NVP_LOG) $(NVP_LRU_CACHE) $(NVP_TIMER) -ldl -funroll-loops -L. -lrt
4648

4749
BANKSHOT2_OBJ=nvp_printf.o fileops_bankshot2_extent.o rbtree.o
4850
libfileops_bankshot2.so: fileops_bankshot2.o $(BANKSHOT2_OBJ)

splitfs/bg_clear_mmap.h

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,45 @@ static void clean_dr_mmap() {
2323
struct free_dr_pool *temp_dr_good_info = NULL;
2424
int dr_fd = 0, ret = 0, i = 0, j = 0;
2525
int num_blocks = clean_overwrite == 1 ? (DR_OVER_SIZE / MMAP_PAGE_SIZE) : (DR_SIZE / MMAP_PAGE_SIZE);
26+
size_t mmap_size = clean_overwrite == 1 ? DR_OVER_SIZE : DR_SIZE;
2627
char prefault_buf[MMAP_PAGE_SIZE];
2728
struct stat stat_buf;
2829
char dr_fname[256];
29-
30+
3031
DEBUG_FILE("%s: Enterred BG thread successfully. Will mmap\n", __func__);
3132

3233
for (i = 0; i < MMAP_PAGE_SIZE; i++)
3334
prefault_buf[i] = '0';
3435
for (i = 0; i < BG_NUM_DR; i++) {
3536
temp_dr_good_info = (struct free_dr_pool *) malloc(sizeof(struct free_dr_pool));
3637
if (clean_overwrite)
37-
sprintf(dr_fname, "%s%s", NVMM_PATH, "DR-OVER-XXXXXX");
38+
sprintf(dr_fname, "%s%s", NVMM_PATH, "DR-OVER-XXXXXX");
3839
else
39-
sprintf(dr_fname, "%s%s", NVMM_PATH, "DR-XXXXXX");
40+
sprintf(dr_fname, "%s%s", NVMM_PATH, "DR-XXXXXX");
4041
dr_fd = _hub_find_fileop("posix")->OPEN(mktemp(dr_fname), O_RDWR | O_CREAT, 0666);
4142
if (dr_fd < 0) {
4243
MSG("%s: mkstemp of DR file failed. Err = %s\n",
4344
__func__, strerror(errno));
4445
assert(0);
4546
}
46-
if (clean_overwrite)
47-
ret = posix_fallocate(dr_fd, 0, DR_OVER_SIZE);
48-
else
49-
ret = posix_fallocate(dr_fd, 0, DR_SIZE);
50-
47+
48+
ret = posix_fallocate(dr_fd, 0, mmap_size);
49+
5150
if (ret < 0) {
5251
MSG("%s: posix_fallocate failed. Err = %s\n",
5352
__func__, strerror(errno));
5453
assert(0);
5554
}
5655

57-
if (clean_overwrite) {
58-
temp_dr_good_info->start_addr = (unsigned long) FSYNC_MMAP
59-
(
60-
NULL,
61-
DR_OVER_SIZE,
62-
PROT_READ | PROT_WRITE, //max_perms,
63-
MAP_SHARED | MAP_POPULATE,
64-
dr_fd, //fd_with_max_perms,
65-
0
66-
);
67-
} else {
68-
temp_dr_good_info->start_addr = (unsigned long) FSYNC_MMAP
69-
(
70-
NULL,
71-
DR_SIZE,
72-
PROT_READ | PROT_WRITE, //max_perms,
73-
MAP_SHARED | MAP_POPULATE,
74-
dr_fd, //fd_with_max_perms,
75-
0
76-
);
77-
}
56+
temp_dr_good_info->start_addr = (unsigned long) FSYNC_MMAP
57+
(
58+
NULL,
59+
mmap_size,
60+
PROT_READ | PROT_WRITE, //max_perms,
61+
MAP_SHARED | MAP_POPULATE,
62+
dr_fd, //fd_with_max_perms,
63+
0
64+
);
7865
if (temp_dr_good_info->start_addr == 0) {
7966
MSG("%s: mmap failed. Err = %s\n", __func__, strerror(errno));
8067
assert(0);
@@ -96,7 +83,7 @@ static void clean_dr_mmap() {
9683
perfmodel_add_delay(0, MMAP_PAGE_SIZE);
9784
#endif //NVM_DELAY
9885
}
99-
86+
10087
num_mmap++;
10188
num_drs++;
10289
fstat(dr_fd, &stat_buf);
@@ -115,15 +102,20 @@ static void clean_dr_mmap() {
115102
__func__, temp_dr_good_info->dr_fd, temp_dr_good_info->start_addr, temp_dr_good_info->valid_offset,
116103
temp_dr_good_info->dr_offset_start, temp_dr_good_info->dr_offset_end);
117104

118-
LFDS711_QUEUE_UMM_SET_VALUE_IN_ELEMENT(temp_dr_good_info->qe, temp_dr_good_info);
119-
if (clean_overwrite)
120-
lfds711_queue_umm_enqueue( &qs_over, &(temp_dr_good_info->qe) );
121-
else
122-
lfds711_queue_umm_enqueue( &qs, &(temp_dr_good_info->qe) );
105+
//LFDS711_QUEUE_UMM_SET_VALUE_IN_ELEMENT(temp_dr_good_info->qe, temp_dr_good_info);
106+
if (clean_overwrite) {
107+
if (lfq_enqueue(&staging_over_mmap_queue_ctx, temp_dr_good_info) != 0)
108+
assert(0);
109+
//lfds711_queue_umm_enqueue( &qs_over, &(temp_dr_good_info->qe) );
110+
} else {
111+
if (lfq_enqueue(&staging_mmap_queue_ctx, temp_dr_good_info) != 0)
112+
assert(0);
113+
//lfds711_queue_umm_enqueue( &qs, &(temp_dr_good_info->qe) );
114+
}
123115
dr_fname[0] = '\0';
124116
__atomic_fetch_add(&num_drs_left, 1, __ATOMIC_SEQ_CST);
125117
}
126-
118+
127119
DEBUG_FILE("%s: Returning successfully\n", __func__);
128120
DEBUG_FILE("%s: ------------- \n", __func__);
129121

splitfs/common.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ LEDGER_DEBUG=0
2929
MOVNTI=1
3030
SYS_APPENDS=0
3131
SYS_PASS_THROUGH=0
32-
DELAYS=1
32+
DELAYS=0
3333
LEDGER_DR_BG_CLEAN=1
3434
LEDGER_INSTRU=0
3535

3636
# WORKLOADS
37-
LEDGER_YCSB=0
38-
LEDGER_TPCC=1
37+
LEDGER_YCSB=1
38+
LEDGER_TPCC=0
3939
LEDGER_REDIS=0
4040
LEDGER_TAR=0
4141
LEDGER_GIT=0

splitfs/cross-platform.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#ifndef __CROSS_PLATFORM_H__
2+
#define __CROSS_PLATFORM_H__
3+
// bool define
4+
#ifdef __KERNEL__
5+
#include <sys/stdbool.h>
6+
#else
7+
#include <stdbool.h>
8+
#endif
9+
10+
// malloc free
11+
#ifdef __KERNEL__
12+
#define malloc(x) kmalloc(x, GFP_KERNEL )
13+
#define free kfree
14+
#define calloc(x,y) kmalloc(x*y, GFP_KERNEL | __GFP_ZERO )
15+
#include<linux/string.h>
16+
#else
17+
#include <stdlib.h>
18+
#include <string.h>
19+
#endif
20+
21+
22+
#ifndef asm
23+
#define asm __asm
24+
#endif
25+
26+
#define cmpxchg( ptr, _old, _new ) { \
27+
volatile uint32_t *__ptr = (volatile uint32_t *)(ptr); \
28+
uint32_t __ret; \
29+
asm volatile( "lock; cmpxchgl %2,%1" \
30+
: "=a" (__ret), "+m" (*__ptr) \
31+
: "r" (_new), "0" (_old) \
32+
: "memory"); \
33+
); \
34+
__ret; \
35+
}
36+
37+
//#define CAS cmpxchg
38+
#define ATOMIC_SET __sync_lock_test_and_set
39+
#define ATOMIC_RELEASE __sync_lock_release
40+
41+
#if defined __GNUC__
42+
#define ATOMIC_SUB __sync_sub_and_fetch
43+
#define ATOMIC_SUB64 ATOMIC_SUB
44+
#define CAS __sync_bool_compare_and_swap
45+
#define XCHG __sync_lock_test_and_set // yes really. The 2nd arg is limited to 1 on machines with TAS but not XCHG. On x86 it's an arbitrary value
46+
#define ATOMIC_ADD __sync_add_and_fetch
47+
#define ATOMIC_ADD64 ATOMIC_ADD
48+
#define mb __sync_synchronize
49+
#if defined(__x86_64__) || defined(__i386)
50+
// #define lmb() asm volatile( "lfence" )
51+
// #define smb() asm volatile( "sfence" )
52+
#define lmb() asm volatile("":::"memory") // compiler barrier only. runtime reordering already impossible on x86
53+
#define smb() asm volatile("":::"memory")
54+
// "mfence" for lmb and smb makes assertion failures rarer, but doesn't eliminate, so it's just papering over the symptoms
55+
#endif // else no definition
56+
57+
// thread
58+
#include <pthread.h>
59+
#include <sched.h>
60+
#define THREAD_WAIT(x) pthread_join(x, NULL);
61+
#define THREAD_ID pthread_self
62+
#define THREAD_FN void *
63+
#define THREAD_YIELD sched_yield
64+
#define THREAD_TOKEN pthread_t
65+
66+
#else
67+
#include <Windows.h>
68+
#define ATOMIC_SUB(x,y) InterlockedExchangeAddNoFence(x, -y)
69+
#define ATOMIC_SUB64(x,y) InterlockedExchangeAddNoFence64(x, -y)
70+
#define ATOMIC_ADD InterlockedExchangeAddNoFence
71+
#define ATOMIC_ADD64 InterlockedExchangeAddNoFence64
72+
#ifdef _WIN64
73+
#define mb() MemoryBarrier()
74+
#define lmb() LoadFence()
75+
#define smb() StoreFence()
76+
inline bool __CAS(LONG64 volatile *x, LONG64 y, LONG64 z) {
77+
return InterlockedCompareExchangeNoFence64(x, z, y) == y;
78+
}
79+
#define CAS(x,y,z) __CAS((LONG64 volatile *)x, (LONG64)y, (LONG64)z)
80+
#else
81+
#define mb() asm mfence
82+
#define lmb() asm lfence
83+
#define smb() asm sfence
84+
inline bool __CAS(LONG volatile *x, LONG y, LONG z) {
85+
return InterlockedCompareExchangeNoFence(x, z, y) == y;
86+
}
87+
#define CAS(x,y,z) __CAS((LONG volatile *)x, (LONG)y, (LONG)z)
88+
#endif
89+
90+
// thread
91+
#include <windows.h>
92+
#define THREAD_WAIT(x) WaitForSingleObject(x, INFINITE);
93+
#define THREAD_ID GetCurrentThreadId
94+
#define THREAD_FN WORD WINAPI
95+
#define THREAD_YIELD SwitchToThread
96+
#define THREAD_TOKEN HANDLE
97+
#endif
98+
#endif
99+

0 commit comments

Comments
 (0)