-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgc.h
64 lines (48 loc) · 1.33 KB
/
gc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef GC_H
#define GC_H
#include "util/objects.h"
#include "mem.h"
#include "node_config.h"
namespace felis {
class VHandle;
struct GarbageBlockSlab;
struct GarbageBlock;
class GC {
friend class GarbageBlockSlab;
static std::array<GarbageBlockSlab *, NodeConfiguration::kMaxNrThreads> g_slabs;
std::atomic<GarbageBlock *> collect_head = nullptr;
struct {
int nr_rows, nr_blocks;
size_t nr_bytes;
bool straggler;
uint32_t padding[11];
} stats[NodeConfiguration::kMaxNrThreads];
public:
uint64_t AddRow(VHandle *row, uint64_t epoch_nr);
void RemoveRow(VHandle *row, uint64_t gc_handle);
void PrepareGCForAllCores();
void RunGC();
void PrintStats();
void ClearStats() {
for (int i = 0; i < NodeConfiguration::g_nr_threads; i++) {
memset(&stats[i], 0, 64);
}
}
static void InitPool();
static bool IsDataGarbage(VHandle *row, VarStr *data);
bool FreeIfGarbage(VHandle *row, VarStr *data, VarStr *next);
size_t Collect(VHandle *handle, uint64_t cur_epoch_nr, size_t limit);
static unsigned int g_gc_every_epoch;
static bool g_lazy;
private:
size_t Process(VHandle *handle, uint64_t cur_epoch_nr, size_t limit);
};
}
namespace util {
using namespace felis;
template <> struct InstanceInit<GC> {
static constexpr bool kHasInstance = true;
static GC *instance;
};
}
#endif /* GC_H */