当前位置:网站首页>Bus error problem of MMAP and its solution
Bus error problem of MMAP and its solution
2022-07-27 11:22:00 【lqw198421】
Preface
In the new trading system , adopt mmap To achieve local persistence of positions and orders , Not used before mmap, There are some problems in this implementation , Record only Bus error problem ;
Realization
Basic logic
OM perhaps PM When it starts , First recover the order or position through the local persistent file :
- If it is the first normal start of the day , There is no persistent file , This is the time ,PM You need to get the initialized position from other places ( Trading hasn't started that day , No orders ,OM No need to deal with );
- If it is not the first normal start of the day , There are persistent files ,OM perhaps PM You need to obtain orders and positions from local persistent files , Initialization complete ;
problem
Persistence is through mmap Mapping local files , Yes Bus error The problem of , What's the reason ?
Because at the first normal start of the day , There is no persistent file ( For each strategy , Persistent files are created and recorded in days ), At this time, you need to create a persistent file first , And then through mmap Write the record information after mapping ; The problem is After creating a new file mmap Mapping modification , For specific reasons, please refer to :
Use mmap Bus error encountered bus error
The reason for the error is mmap Cannot extend a new file with empty content , Because the size is 0, There is no corresponding legal physical page , Can't expand .
solve
The solution is 2 individual :
One is the scheme in the link above : Just write some data in the newly created empty file
The other is adopt ftruncate Map and modify the newly created file after expansion
int fd = open("/workspace/delete/data.txt", O_RDWR | O_CREAT, 777);
if(!fd) {
printf("!fd\n");
return -1;
}
// programme 1: write(fd,"1",1);
ftruncate(fd, 4096*10); // programme 2
void* m_mmap =
mmap(NULL, 4096*10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if(!m_mmap){
printf("!m_mmap\n");
return -1;
}
printf("come here\n");
Position cur_pos;
char buf[1024];
for (int i = 1; i < 10; i++) {
cur_pos.symbol = i*2 + 15;
cur_pos.pos_long = i*3 + 15;
cur_pos.pos_short = i*4 + 15;
cur_pos.long_pending = i*5 + 15;
cur_pos.short_pending = i*6 + 15;
printf("%d: %lld,%d,%d,%d,%d\n", i-1, cur_pos.symbol, cur_pos.pos_long, cur_pos.pos_short, cur_pos.long_pending, cur_pos.short_pending);
memcpy( (void*)((char*)m_mmap + sizeof(Position)*(i-1)), &cur_pos, sizeof(cur_pos));
//memcpy( (buf + sizeof(Position)*(i-1)), &cur_pos, sizeof(cur_pos));
}
边栏推荐
- 49 letter ectopic grouping and 242 effective letter ectopic words
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- Maximized array sum after 13 K negations
- 10 complete half of the questions
- What is the mystery of the gate of the meta universe?
- An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
- FAQs of "relay chain" and "dot" in Poka ecosystem
- Solutions to errors in tensorflow operation
- Internal and external troubles of digital collection NFT "boring ape" bayc
- What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
猜你喜欢

求组合数 AcWing 885. 求组合数 I

2022 Niuke multi school (3) j.journey

How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review

Instructions for mock platform

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
![[shader realizes shake random shaking effect _shader effect Chapter 10]](/img/49/99669ebc3ba59a0277bb8bc928f576.png)
[shader realizes shake random shaking effect _shader effect Chapter 10]

背包模型 AcWing 423. 采药

中国剩余定理 AcWing 204. 表达整数的奇怪方式

Knapsack problem acwing 9. grouping knapsack problem

Gaussian elimination acwing 884. Gaussian elimination for solving XOR linear equations
随机推荐
MySQL installation (RPM package)
Influence of black and white pixel distribution on iteration times
IO stream_ Character stream, IO stream summary, IO stream case summary
【着色器实现Shake随机摇动效果_Shader效果第十篇】
状态压缩DP AcWing 91. 最短Hamilton路径
背包模型 AcWing 1024. 装箱问题
树形DP AcWing 285. 没有上司的舞会
14 check whether integers and their multiples exist
Backpack model acwing 1022. Collection of pet elves
JVM judges that the object is dead, and practices verify GC recycling
Longest ascending subsequence model acwing 1012. Sister Cities
Longest ascending subsequence model acwing 272. longest common ascending subsequence
Today's code farmer girl summarized her notes about NPM package management and URL module
Kangaroo cloud stack based on CBO in spark SQL optimization
Game theory acwing 894. Split Nim game
Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
Solutions to errors in tensorflow operation
6 find the smallest letter larger than the target letter
TensorFlow张量运算函数集
Digital triangle model acwing 1015. Picking flowers