forked from deepseek-ai/3FS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMimallocLib.cc
More file actions
53 lines (42 loc) · 1.56 KB
/
Copy pathMimallocLib.cc
File metadata and controls
53 lines (42 loc) · 1.56 KB
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
#include <cstdio>
#include <cstdlib>
#include "memory/common/MemoryAllocatorInterface.h"
#include "mimalloc.h"
namespace hf3fs::memory {
class MimallocMemoryAllocator : public MemoryAllocatorInterface {
public:
void logstatus(char *buf, size_t size) override {
size_t elapsed_msecs, user_msecs, system_msecs, current_rss, peak_rss, current_commit, peak_commit, page_faults;
mi_process_info(&elapsed_msecs,
&user_msecs,
&system_msecs,
¤t_rss,
&peak_rss,
¤t_commit,
&peak_commit,
&page_faults);
std::snprintf(buf,
size,
"mimalloc enabled, "
"current_rss=%zu, peak_rss=%zu, current_commit=%zu, peak_commit=%zu, page_faults=%zu",
current_rss,
peak_rss,
current_commit,
peak_commit,
page_faults);
}
void *allocate(size_t size) override { return mi_malloc(size); }
void deallocate(void *mem) override { return mi_free(mem); }
void *memalign(size_t alignment, size_t size) override { return mi_memalign(alignment, size); }
bool profiling(bool /*active*/, const char * /*prefix*/) override {
fprintf(stderr, "Memory profile not supported by mimalloc\n");
return true;
}
};
} // namespace hf3fs::memory
extern "C" {
hf3fs::memory::MemoryAllocatorInterface *getMemoryAllocator() {
static hf3fs::memory::MimallocMemoryAllocator mimalloc;
return &mimalloc;
}
}