Skip to content

Commit 286b82b

Browse files
committed
fix readme
1 parent 995ff49 commit 286b82b

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Google-tcmalloc-simulation-implementation
1+
# Google-tcmalloc-simulation-implementation(未完成)
22
谷歌开源项目tcmalloc高并发内存池学习和模拟实现
33

44
开题日期:20240504
55

6-
- [Google-tcmalloc-simulation-implementation](#google-tcmalloc-simulation-implementation)
6+
- [Google-tcmalloc-simulation-implementation(未完成)](#google-tcmalloc-simulation-implementation未完成)
7+
- [==bugs to fix (项目目前待解决的问题)==](#bugs-to-fix-项目目前待解决的问题)
78
- [前言](#前言)
89
- [threadCache整体框架](#threadcache整体框架)
910
- [开始写threadCache代码](#开始写threadcache代码)
@@ -29,6 +30,16 @@
2930

3031
***
3132

33+
## ==bugs to fix (项目目前待解决的问题)==
34+
35+
1. 在ubuntu_arm64环境下,如果调用多线程,出现段错误(原因未知,待解决)
36+
2. 在ubuntu_arm64环境下,radix tree需要用第三棵,前两棵用不了,需要解决。
37+
3. 在window32位环境下,可以偶尔成功运行,出现偶发段错误,原因未知,待解决。
38+
39+
经过radixtree优化后,模拟实现的tcmalloc效率高于malloc。(win32下测试,会出现偶发段错误)
40+
41+
![](./assets/5.png)
42+
3243
## 前言
3344

3445
当前项目是实现一个高并发的内存池,他的原型是google的一个开源项目tcmalloc,tcmalloc全称 Thread-Caching Malloc,即线程缓存的malloc,实现了高效的多线程内存管理,用于替代系统的内存分配相关的函数(malloc、free)。

assets/5.png

75.5 KB
Loading

bench_mark.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ void BenchmarkMalloc(size_t ntimes, size_t nworks, size_t rounds) {
3535
for (auto& t : vthread) {
3636
t.join();
3737
}
38-
std::cout << nworks << "个线程并发执行" << rounds << "次,每轮次malloc " << ntimes << "次: 花费:" << malloc_costtime.load() << "ms\n";
39-
std::cout << nworks << "个线程并发执行" << rounds << "轮次,每轮次free " << ntimes << "次: 花费:" << free_costtime.load() << " ms\n";
40-
std::cout << nworks << "个线程并发malloc&free " << nworks * rounds * ntimes << "次,总计花费:" << malloc_costtime.load() + free_costtime.load() << " ms\n";
38+
std::cout << nworks << "threads run" << rounds << " times, each round malloc " << ntimes << " times, cost: " << malloc_costtime.load() << "ms\n";
39+
std::cout << nworks << "threads run" << rounds << " times, each round free " << ntimes << " times, cost: " << free_costtime.load() << " ms\n";
40+
std::cout << nworks << "threads run malloc and free " << nworks * rounds * ntimes << " time, total cost: " << malloc_costtime.load() + free_costtime.load() << " ms\n";
4141
}
4242

4343
// 单轮次申请释放次数 线程数 轮次
@@ -70,18 +70,16 @@ void BenchmarkConcurrentMalloc(size_t ntimes, size_t nworks, size_t rounds) {
7070
for (auto& t : vthread) {
7171
t.join();
7272
}
73-
std::cout << nworks << "个线程并发执行" << rounds << "轮次,每轮次concurrent alloc " << ntimes << "次: 花费:" << malloc_costtime.load() << " ms\n";
74-
std::cout << nworks << "个线程并发执行" << rounds << "轮次,每轮次concurrent dealloc " << ntimes << "次: 花费:" << free_costtime.load() << " ms\n";
75-
std::cout << nworks << "个线程并发concurrent alloc&dealloc " << nworks * rounds * ntimes << "次,总计花费:" << malloc_costtime.load() + free_costtime.load() << " ms\n";
73+
std::cout << nworks << "threads run" << rounds << " times, each round malloc " << ntimes << " times, cost: " << malloc_costtime.load() << "ms\n";
74+
std::cout << nworks << "threads run" << rounds << " times, each round free " << ntimes << " times, cost: " << free_costtime.load() << " ms\n";
75+
std::cout << nworks << "threads run tcmalloc and tcfree " << nworks * rounds * ntimes << " time, total cost: " << malloc_costtime.load() + free_costtime.load() << " ms\n";
7676
}
7777

7878
int main() {
7979
size_t n = 1000;
80-
std::cout << "==========================================================" << std::endl;
8180
BenchmarkConcurrentMalloc(n, 4, 10);
82-
// std::cout << std::endl
83-
// << std::endl;
84-
// BenchmarkMalloc(n, 4, 10);
85-
std::cout << "==========================================================" << std::endl;
81+
std::cout << std::endl
82+
<< std::endl;
83+
BenchmarkMalloc(n, 4, 10);
8684
return 0;
8785
}

makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# out: bench_mark.cc ./src/*.cc
2-
# g++ -o $@ $^ -std=c++11 -lpthread -m32
3-
# debug: bench_mark.cc ./src/*.cc
4-
# g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g -m32
5-
# unit: unit_test.cc ./src/*.cc
6-
# g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g -m32
7-
# .PHONY:clean
8-
# clean:
9-
# rm -f out debug
10-
111
out: bench_mark.cc ./src/*.cc
12-
arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread
2+
g++ -o $@ $^ -std=c++11 -lpthread -m32
133
debug: bench_mark.cc ./src/*.cc
14-
arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g
4+
g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g -m32
155
unit: unit_test.cc ./src/*.cc
16-
arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g
6+
g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g -m32
177
.PHONY:clean
188
clean:
19-
rm -f out debug unit
9+
rm -f out debug
10+
11+
# out: bench_mark.cc ./src/*.cc
12+
# arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread
13+
# debug: bench_mark.cc ./src/*.cc
14+
# arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g
15+
# unit: unit_test.cc ./src/*.cc
16+
# arm-linux-gnueabihf-g++ -o $@ $^ -std=c++11 -lpthread -DPROJECT_DEBUG -g
17+
# .PHONY:clean
18+
# clean:
19+
# rm -f out debug unit

0 commit comments

Comments
 (0)