Color Scheme
Refer to the link.
Add these three lines to ~/.bashrc
1 | $ vi ~/.bashrc |
Refer to the link.
Add these three lines to ~/.bashrc
1 | $ vi ~/.bashrc |
resident set size (RSS)
/proc/self/statm
TIME+1 | TIME |
---|---|
5432:01 means “5432 minutes and 1 second” |
90,32 means “90 hours and 32 minutes” |
25:15.20 means “25 minutes, 15 seconds and 20% of 1 second” |
25:15 means “25 minutes and 15 seconds” |
TIME
: the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME)
Field | value & means |
---|---|
TIME |
1-18:09:38 means “1 day, 18 hours, 9 minutes and 38 seconds” |
子进程是父进程的副本,获取了父进程的数据空间、堆和栈的副本,但是他们共享正文段。
写时复制(Copy-On-Write,COW):不复制父进程的完全副本,只有在父或子进程尝试修改这些区域时,则为修改区域的那块内存制作一个副本,通常是虚拟内存的一页。
博主注: 如果父进程尝试修改共享的内存页,内核会为父进程同样制作副本,而把原本的内存页留给子进程使用,这会导致即使在父进程中,原本的内存页的物理地址也会发生改变,从而使得 RDMA 等机制发生错误(要求物理地址保持不变),所以此时需要使用 madise
设置 MADV_DONTFORK
标志。
在 Linux 中,写时复制(Copy-On-Write, COW)机制主要通过页表和内存管理单元(MMU)来实现。以下是 COW 在 Linux 中的具体实现步骤:
页表标记:当进程调用 fork() 创建子进程时,父进程和子进程的页表会标记共享的内存页为只读。这意味着这些页在初始状态下是共享的,且无法被写入。
页错误处理:如果父进程或子进程尝试写入这些只读页,会触发页错误(page fault)。操作系统内核会捕获这个页错误,并执行 COW 机制。
内存页复制:在页错误发生时,操作系统会分配一个新的物理内存页,并将原始页的内容复制到这个新页中。然后,页表会更新,以指向新的可写内存页。
页表更新:操作系统更新进程的页表,使得写入操作可以在新的内存页上进行,而不会影响其他进程共享的原始页。
引用计数:操作系统维护每个内存页的引用计数,以跟踪有多少进程共享该页。当引用计数减少到零时,内存页可以被释放。
TODO
madvise
是一个系统调用,用于向内核提供关于内存使用的建议。
1 | #include <sys/mman.h> |
MADV_DONTFORK
MADV_DONTFORK
阻止 fork()
后的子进程看见这些范围的内存页。
这意味该内存不会被复制,即在 fork()
调用时,指定的内存区域不会被子进程继承,避免写时复制导致的页物理地址发生变化。在 fork() 之后,如果父进程对共享内存页进行写操作,写时复制(COW)机制会将这些页复制到新的物理位置。这会导致 RDMA 操作使用的内存地址不一致,从而引发数据错误。
拓展: RDMA 中,ibv_fork_init
和 RDMAV_HUGEPAGES_SAFE
会调用 madvise()
来为 IB 卡的 DMA 内存页设置 MADV_DONTFORK
,以避免数据损坏。
what-does-virtual-memory-size-in-top-mean
[2]: https://blog.csdn.net/weixin_42319496/article/details/125940896
[3]: https://docs.nvidia.com/networking/display/rdmaawareprogrammingv17/ibv_fork_init
See the article: Prefixes for binary multiples
Table:
Prefixes for binary multiples |
|||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||
|
See more: Variadic functions in C
vprintf
1 | #include <stdarg.h> |
Output:
1 | $ ./a.out |
ap_list
+ vsnprintf
1 | #include <stdarg.h> |
va_list
+ va_arg
1 | #include <stdarg.h> |
Output:
1 | $ ./a.out |
You can define and specialize members of an inline namespace
as if they were also members of the enclosing namespace.inline namespace
表示该命名空间也是上级命名空间的成员。
参考: Inline namespace definitions (C++11)
例如:
1 | namespace A { |
Refer to: Unnamed / anonymous namespaces vs static in namespace
Sheldon: Woman, you’re playing with forces beyond your ken.
Penny: Yeah, your ken can kiss my Barbie.
Penny想要气气Sheldon,她故意把ken曲解成玩偶,说:你的ken可以和我芭比娃娃谈恋爱。
出处: word reference。
Daisy Armstrong
Miss Mary Debenham
Colonel Arbuthnott
Hercule Poirot
Lieutenant Dubosc
1930
The Armstrong Home, Long Island, N.Y.
Armstrong Baby Kidnapped.
Crushed toys, crushed hopes.
Baby taken in dead of night.
Armstrong Household Turmoil.
Baby Daisy Taken from Armstrong Home.
Staff Wakened But Hopeless.
DAISY ARMSTRONG - Child of Colonel and Mrs. Hamish Armstrong was dramatically kidnapped last night while her parents were being driven to the airport by their chauffeur.
The discover of the missing child was made by the chauffeur on returning from the airport where he found the family nurse bound and gagged in the room next to Baby Daisy’s bedroom.
The police were informed immediately and investigations began at once. They described kidnapping as one of the most vicious crimous that can be commited.
Daisy found slain.
5 years later
The Asian side of Istanbul.
Miss Mary Debenham
Salacak
Welcome aboard.
Bosporus Ferry will shortly depart from Istanbul Sirkeci Station, connecting with the Orient Express.
Here’s your ticket, Monsieur Poirot. I’m afraid you’ve still got another hour.
Well, then, please do not wait.
Not wait? After all you’ve done for us, Monsieur Poriot? My general’s orders were to ensure your safe departure. He also wished me to thank you again for saving the honor of the British garrison in Jordan. The brigadier’s confession was opportune. I say, how did you do it? Was it the old thumbscrew, you know, the rack?
Chop-chop
I hope we did the right thing booking you into a hotel on the European side rather than the Asia side.
我希望我们给你预订的是欧洲酒店而不是亚洲酒店是正确的。
I have no prejudice with either continent.
The crossing should be pleasant. The Borporus is always calm.
穿行应该会很愉快。博斯普鲁斯海峡总是很平静。
You have crossed by the ferry?
你乘渡船穿渡过?
Daisy: 雏菊;人名(黛西)。
kidnapped: 绑架
crushed: 破灭的,压碎的
dead of night: 深夜时分,the quietest, darkest part of the night.
household: 家庭;户;家;家族;家人
turmoil: n. 动荡;动乱
staff: 工作人员。
wakened: waken v. 醒来。wakened 是waken的过去式和过去分词。
chauffeur: 美/ʃoʊˈfɝː/ 英/ˈʃəʊ.fər/ 司机。
bound: 这里是bind的过去式和过去分词,绑定、捆绑。
gag: n./v. 堵嘴;插科打诨。
vicious: 恶毒的。
slay: To kill in a violent way. 残忍杀害。
Istanbul: 伊斯坦布尔,为土耳其首都直至1923年。
Salacak: garrison: A group of soliders living in or defending a town or building, or the building that the soliders live in. 守军;守备营地。
Jordan: 约旦(西亚国家)。
brigadier: 英/ˌbrɪɡəˈdɪə(r)/ 美/ˌbrɪɡəˈdɪr/ 准将。
confession: n. 坦白;忏悔;认罪。
opportune: 英/ˈɒpətjuːn/ 美/ˌɑːpərˈtuːn/ 适当的;及时的。
thumbscrew: 螺丝;拧紧 。
rack: chop-chop: chop v./n. 砍;向下猛击。chop-chop 赶快,快点。
Bosporus Strait: 博斯普鲁斯海峡,又称伊斯坦布尔海峡,介于欧洲与亚洲之间的海峡。它长约30公里,最宽处宽约3,700米,最窄处宽约700米。北连黑海,南通马尔马拉海(土耳其内海),土耳其第一大城伊斯坦堡即隔着博斯普鲁斯海峡与小亚细亚半岛相望,是黑海沿岸国家出海第一关口,也是连接黑海以及地中海的唯一航道。因此,俄罗斯的黑海舰队必须通过博斯普鲁斯海峡才能前往地中海。
ferry: n./v. 渡船;摆渡