Skip to content

Commit 45e9b8f

Browse files
committed
update
1 parent 15db85d commit 45e9b8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+812
-0
lines changed

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ See the [LICENSE][] file for the specific language governing permissions and lim
3030
<summary>目录</summary>
3131

3232
<ul>
33+
<li><a href="#%E7%AE%97%E6%B3%95">算法</a></li>
34+
<li><a href="#%E8%AE%A1%E7%AE%97%E6%9C%BA">计算机</a></li>
3335
<li>
3436
<a href="#%E6%95%B0%E6%8D%AE%E5%BA%93">数据库</a>
3537
<ul>
@@ -52,9 +54,11 @@ See the [LICENSE][] file for the specific language governing permissions and lim
5254
<li><a href="#go">Go</a></li>
5355
<li><a href="#javascript">Javascript</a></li>
5456
<li><a href="#k8s">K8S</a></li>
57+
<li><a href="#%E8%AF%AD%E8%A8%80%E8%AE%BE%E8%AE%A1">语言设计</a></li>
5558
<li><a href="#linux">Linux</a></li>
5659
<li><a href="#language%20server%20protocol%20(lsp)">Language Server Protocol (LSP)</a></li>
5760
<li><a href="#mac">Mac</a></li>
61+
<li><a href="#%E6%95%B0%E5%AD%A6">数学</a></li>
5862
<li><a href="#%E7%BD%91%E7%BB%9C">网络</a></li>
5963
<li><a href="#nodejs">Nodejs</a></li>
6064
<li><a href="#%E8%BF%90%E7%BB%B4">运维</a></li>
@@ -74,6 +78,23 @@ See the [LICENSE][] file for the specific language governing permissions and lim
7478
</details>
7579
<!-- tocstop -->
7680

81+
## 算法
82+
83+
- [Raft 算法](algorithm/raft.md)
84+
85+
## 计算机
86+
87+
记录与计算机硬件相关的知识。
88+
89+
- [RDMA](computer/RDMA.md)
90+
- [单指令流多数据流 (SIMD)](computer/SIMD.md)
91+
- [TLB](computer/TLB.md)
92+
- [CPU 伪共享 (CPU Cache Line False Sharing)](computer/cpu-cache-line-false-sharing.md)
93+
- [CPU 缓存](computer/cpu-cache.md)
94+
- [CPU](computer/cpu.md)
95+
- [内存屏障](computer/memory-barrier.md)
96+
- [随机存取存储器 (RAM)](computer/ram.md)
97+
7798
## 数据库
7899

79100
- [flyway 用法](database/flyway-usage.md)
@@ -97,6 +118,8 @@ See the [LICENSE][] file for the specific language governing permissions and lim
97118

98119
## 设计
99120

121+
记录平面设计的相关知识
122+
100123
- [8 点栅格](design/8-point-grid.md)
101124
- [色彩空间](design/color-space.md)
102125
- [UI 的加载状态](design/loading-status-of-ui.md)
@@ -196,7 +219,9 @@ See the [LICENSE][] file for the specific language governing permissions and lim
196219

197220
## Go
198221

222+
- [Go Module](go/go-module.md)
199223
- [Golang 学习](go/golang-learning.md)
224+
- [Gorutine](go/gorutine.md)
200225

201226
## Javascript
202227

@@ -227,8 +252,18 @@ See the [LICENSE][] file for the specific language governing permissions and lim
227252
- [重启 Pod 中的容器](k8s/restart-container-in-pod.md)
228253
- [configmap 和 secret 的滚动更新](k8s/rolling-update-of-configmap-and-secret.md)
229254

255+
## 语言设计
256+
257+
记录编程语言的内部设计与思想
258+
259+
- [Actor 并发模型](language/actor.md)
260+
- [协程 (Coroutine)](language/coroutine.md)
261+
- [CSP 并发模型](language/csp.md)
262+
230263
## Linux
231264

265+
记录 Linux 系统设计、系统命令,Linux 生态软件等相关知识
266+
232267
- [XDG 基础目录标准](linux/XDG-base-directory-spec.md)
233268
- [ab 与 wrk 比较](linux/ab-vs-wrk.md)
234269
- [用户线程,内核线程,CPU 超线程技术](linux/about-multi-thread.md)
@@ -246,6 +281,7 @@ See the [LICENSE][] file for the specific language governing permissions and lim
246281
- [linux 命令被 hash 缓存](linux/command-be-hashed.md)
247282
- [compgen](linux/compgen.md)
248283
- [连接 tty](linux/connect-tty.md)
284+
- [上下文切换](linux/context-switch.md)
249285
- [CPU](linux/cpu.md)
250286
- [判断文件编码](linux/detect-encoding-of-file.md)
251287
- [diff 与 patch](linux/diff-and-patch.md)
@@ -266,6 +302,7 @@ See the [LICENSE][] file for the specific language governing permissions and lim
266302
- [Here Strings and Here Documents](linux/here-strings-and-here-documents.md)
267303
- [Hostname in Linux](linux/hostname.md)
268304
- [查看进程的环境变量](linux/inspect-process-environment.md)
305+
- [中断](linux/interrupt.md)
269306
- [调用原生 shell 命令](linux/invoke-origin-shell-command-with-backslash.md)
270307
- [IO、select、epoll](linux/io-select-epoll.md)
271308
- [iproute2 与 ifconfig 命令](linux/iproute2-vs-ifconfig.md)
@@ -277,6 +314,7 @@ See the [LICENSE][] file for the specific language governing permissions and lim
277314
- [mount](linux/mount.md)
278315
- [netstat 与 ss](linux/netstat-and-ss.md)
279316
- [NTP 时间同步](linux/ntp.md)
317+
- [perf 命令](linux/perf.md)
280318
- [管道重定向](linux/pipe-redirect.md)
281319
- [进程内存](linux/process-memory.md)
282320
- [慎用双引号与单引号](linux/quotes-in-bash.md)
@@ -293,16 +331,22 @@ See the [LICENSE][] file for the specific language governing permissions and lim
293331
- [systemd](linux/systemd.md)
294332
- [tailf](linux/tailf.md)
295333
- [基于内存的虚拟文件系统](linux/temporary-fs-in-memory.md)
334+
- [线程与进程](linux/thread-and-process.md)
296335
- [UNIX Domain Socket](linux/unix-domain-socket.md)
297336
- [unlink 是删除任何文件](linux/unlink.md)
298337
- [/usr/bin/env](linux/usr-bin-env.md)
338+
- [虚拟内存](linux/virtual-memory.md)
299339
- [奇怪的 ESC](linux/weird-esc-key.md)
300340
- [Welcome Message Banner](linux/welcome-message-banner.md)
301341
- [监听 0.0.0.0 与 127.0.0.1 的区别](linux/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1.md)
342+
- [为什么创建 Daemon 进程要 Fork 两次?](linux/why-fork-twice-when-create-daemon-process.md)
302343
- [Zsh 的坑](linux/zsh-pitfalls.md)
303344

304345
## Language Server Protocol (LSP)
305346

347+
- https://microsoft.github.io/language-server-protocol/
348+
- https://langserver.org/
349+
306350
- [YAML Language Server](lsp/yaml-language-server.md)
307351

308352
## Mac
@@ -318,8 +362,17 @@ See the [LICENSE][] file for the specific language governing permissions and lim
318362
- [Tab 键不能切换弹出框的选中焦点](mac/tab-not-always-work.md)
319363
- [xcode 重新安装](mac/xcode.md)
320364

365+
## 数学
366+
367+
数学,不仅仅是算法
368+
369+
- [豪斯多夫维数](math/hausdorff-besicovitch-dimension.md)
370+
- [空间填充曲线 (Space-Filling Curve)](math/space-filling-curve.md)
371+
321372
## 网络
322373

374+
记录网络相关知识
375+
323376
- [DNS SRV](network/dns_srv.md)
324377
- [HTTP Request/Response 网络包](network/http-request-and-response-package.md)
325378
- [TCP Buffer 大小](network/tcp-buffer-size.md)
@@ -361,6 +414,8 @@ See the [LICENSE][] file for the specific language governing permissions and lim
361414

362415
## 其他
363416

417+
记录各种奇奇怪怪的小知识
418+
364419
- [0.30000000000000004](others/0.30000000000000004.md)
365420
- [Today I learned (TIL) 资源列表](others/TIL.md)
366421
- [Alfred Workflow debug 技巧](others/alfred-workflow-debug.md)
@@ -372,6 +427,7 @@ See the [LICENSE][] file for the specific language governing permissions and lim
372427
- [github 中 markdown 折叠文本](others/fold-text-in-github.md)
373428
- [从微信公众号提取原图](others/get-raw-image-from-weixin.md)
374429
- [Github Template (模板)](others/github-template.md)
430+
- [gRPC](others/grpc.md)
375431
- [通过 Hash 密码到 url 来验证密码](others/hashed-password-to-url.md)
376432
- [如何阅读标准](others/how-to-read-spec.md)
377433
- [如何审核代码](others/how-to-review-code.md)
@@ -381,10 +437,13 @@ See the [LICENSE][] file for the specific language governing permissions and lim
381437
- [Jinja2](others/jinja2.md)
382438
- [Language Server Protocol](others/language-server-protocol.md)
383439
- [箴言](others/maxim.md)
440+
- [元语法 (Metasyntax)](others/metasyntax.md)
384441
- [终端邮件客户端 Mutt](others/mutt.md)
385442
- [NFS](others/nfs.md)
443+
- [堆外内存](others/off-heap-memory.md)
386444
- [原码, 反码, 补码](others/one_complement-and-two_complement.md)
387445
- [Protocol Buffers](others/protocal-buffers.md)
446+
- [正则表达式的小技巧](others/regexp-tricks.md)
388447
- [在 Github Markdown 中如何填写图片的链接](others/relative-link-in-github-markdown.md)
389448
- [Markdown 里写反引号](others/reverse-quote-in-markdown.md)
390449
- [Semver](others/semver.md)
@@ -394,8 +453,10 @@ See the [LICENSE][] file for the specific language governing permissions and lim
394453
- [UTF-8 vs UTF-16](others/utf-8-vs-utf-16.md)
395454
- [Vagrant DNS](others/vagrant-dns.md)
396455
- [vagrant-vbguest](others/vagrant-vbguest.md)
456+
- [查看 Chrome 通知历史列表](others/view-chrome-notification-history.md)
397457
- [Virtualbox VBoxManage](others/virtualbox-VBoxManage.md)
398458
- [水快速加热](others/water-heating-in-seconds.md)
459+
- [为何 Protobuf 3 移除了 required 和 optional](others/why-protobuf-3-remove-required-and-optional.md)
399460
- [zookeeper 健康检查](others/zookeeper-health-check.md)
400461

401462
## 哲学
@@ -428,6 +489,9 @@ See the [LICENSE][] file for the specific language governing permissions and lim
428489

429490
## 思考
430491

492+
记录我的碎片式思考
493+
494+
- [CLD 图](thinking/causal-loop-diagram.md)
431495
- [项目代码如何组织](thinking/how-to-make-code-organization.md)
432496
- [如何编程](thinking/how-to-programming.md)
433497
- [不完整的函数](thinking/non-total-function.md)
@@ -451,6 +515,8 @@ See the [LICENSE][] file for the specific language governing permissions and lim
451515

452516
## Web
453517

518+
记录 Web 服务开发涉及的相关知识。
519+
454520
- [URL QueryString 传数组参数](web/array-params-in-url.md)
455521
- [DNS](web/dns.md)
456522
- [国际化 SEO](web/international-SEO.md)

algorithm/raft.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Raft 算法
2+
3+
非常好的 Raft 算法可视化解释:
4+
5+
- http://thesecretlivesofdata.com/raft/
6+
- https://raft.github.io/
7+
8+
### 网络隔离与 Learner
9+
10+
- https://fuckcloudnative.io/posts/etcd-server-learner/
11+
- https://youjiali1995.github.io/raft/etcd-raft-cluster-membership-change/

build.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ exports.categoryNameMap = {
1010
database: '数据库',
1111
lsp: 'Language Server Protocol (LSP)',
1212
network: '网络',
13+
algorithm: '算法',
14+
computer: '计算机',
15+
language: '语言设计',
16+
math: '数学',
1317
};

computer/RDMA.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## RDMA
2+
3+
RDMA 的三种硬件实现
4+
5+
- InfiniBand
6+
- RoCE: RDMA over Ethernet
7+
- iWARP: RDMA over TCP
8+
9+
- [RDMA技术简介](https://www.jianshu.com/p/329427415f36)
10+
- [RDMA技术详解(一):RDMA概述](https://zhuanlan.zhihu.com/p/55142557)
11+
- [来点硬核的:什么是RDMA?](https://cloud.tencent.com/developer/article/1420687)

computer/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
记录与计算机硬件相关的知识。

computer/SIMD.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 单指令流多数据流 (SIMD)
2+
3+
单指令流多数据流 (SIMD: Single Instruction Multiple Data) 是一种采用一个控制器来控制多个处理器,同时对一组数据(又称“数据向量”)中的每一个分别执行相同的操作从而实现空间上的并行性的技术。

computer/TLB.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## TLB
2+
3+
内存管理单元 (MMU),或称存储器管理单元,或称分页内存管理单元 (PMMU: Paged Memory Management Unit)。MMU 是一种负责 CPU 的内存访问请求的计算机硬件设备。是 CPU 的一部分。
4+
MMU 的功能包括虚拟地址到物理地址的转换(即虚拟内存管理)、内存保护、中央处理器高速缓存的控制
5+
MMU 使得每个用户进程拥有自己的地址空间,并通过内存访问权限的检查保护每个进程所用的内存不被其他进程破坏。
6+
7+
页表一般都很大,并且存放在内存中,所以 CPU 引入 MMU 后,读取指令、数据需要访问两次内存:首先通过查询页表得到物理地址,然后访问该物理地址读取指令、数据。CPU 每次访问虚拟内存,虚拟地址都必须转换为对应的物理地址。从概念上说,这个转换需要遍历页表,页表是三级页表,就需要 3 次内存访问。就是说,每次虚拟内存访问都会导致 4 次物理内存访问。
8+
为了减少因为 MMU 导致的处理器性能下降,引入了 TLB。
9+
TLB (Translation Lookaside Buffer) 是内存管理单元 (MMU: Memory Management Unit) 用于改进虚拟地址到物理地址转换速度的缓存。TLB 又称“快表”,直译为旁路快表缓冲,也可以理解为页表缓冲,地址变换高速缓存。
10+
11+
- [TLB的作用及工作原理](https://www.cnblogs.com/alantu2018/p/9000777.html)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## CPU 伪共享 (CPU Cache Line False Sharing)
2+
3+
也称 Cache Line Bouncing。
4+
5+
### 检测方法
6+
7+
`perf c2c` 命令。详见[这篇文章][1]
8+
9+
### 解决方案
10+
11+
缓存行填充(也称缓存行对齐)。增加无意义的变量声明,增加冗余空间来填充到一个 Cache Line 的长度。
12+
Java 提供了 `@sun.misc.Contended` 注解来自动填充。
13+
14+
### 参考资料
15+
16+
- [杂谈 什么是伪共享(false sharing)?](https://zhuanlan.zhihu.com/p/65394173)
17+
- [Cache False Sharing Debug][1]
18+
19+
20+
[1]: http://oliveryang.net/2018/01/cache-false-sharing-debug/

computer/cpu-cache.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## CPU 缓存
2+
3+
<!-- MarkdownTOC GFM -->
4+
5+
- [多级缓存](#多级缓存)
6+
- [CPU Cache Line](#cpu-cache-line)
7+
- [Cache Line 映射到主存](#cache-line-映射到主存)
8+
- [CPU 包含策略 (Cache Inclusion Policy)](#cpu-包含策略-cache-inclusion-policy)
9+
- [CPU 写策略 (Write policies)](#cpu-写策略-write-policies)
10+
- [CPU Cache Coherence](#cpu-cache-coherence)
11+
- [嗅探协议](#嗅探协议)
12+
- [Cache Line False Sharing](#cache-line-false-sharing)
13+
- [参考资料](#参考资料)
14+
15+
<!-- /MarkdownTOC -->
16+
17+
### 多级缓存
18+
19+
CPU 采用多级缓存的架构,是效率和成本的权衡结果。
20+
21+
- L1 Cache: 只被一个 CPU 核独享。L1 Cache 分为指令缓存 (Data Cache,简称 L1d) 和数据缓存 (Instruction Cache,简称 L1i),两者可同时被 CPU 访问。
22+
- L2 Cache: 只被一个 CPU 核独享。主要作用为当 CPU 在 L1 中没读取到所需要的数据时再把数据展示给 CPU 筛选
23+
- L3 Cache: 被单个插槽上的所有 CPU 核共享
24+
- 主内存 (Main Memory)
25+
26+
L1/L2/L3 Cache 的存储介质都是静态随机存取存储器 (SRAM),而主内存的存储介质是动态随机存取存储器 (DRAM)。
27+
28+
L1/L2/L3 Cache 也有人分别称为 FLC(First-Level Cache), MLC(Mid-Level Cache), LLC (Last-Level Cache)。
29+
30+
### CPU Cache Line
31+
32+
一个 Cache 由 N 个 Cache Line 组成, 一般大小为 32 或 64 字节。Cache Line 是和内存进行数据交换的最小单位。
33+
34+
(下文简称 Cache Line 为 CL)
35+
36+
L1, L2, L3 Cache。L2 必然包含同核的 L1 的所有 CL,L3 必然包含该 CPU 所有核的 L2 的所有 CL。
37+
38+
### Cache Line 映射到主存
39+
40+
组相联映射。组间采用直接映射,组内为全相联。
41+
42+
43+
### CPU 包含策略 (Cache Inclusion Policy)
44+
45+
表示同一个 CL 读取/删除,在其他层的反应的关系策略。
46+
CPU 包含策略作用在 L1/L2/L3,具体策略分配是厂商实现 CPU 指定的。
47+
48+
有三种策略
49+
50+
- Inclusive Policy: 下层 Cache 的 CL **包含**高层 Cache 的 CL。当下层 Cache 的 CL 被驱逐,上层 Cache 对应的 CL 也被驱逐。
51+
- Exclusive Policy: 下层 Cache 的 CL **不包含**高层 Cache 的 CL。获取 CL 优先放到高层 Cache,不会放到下层 Cache。当上层 Cache 的 CL 被驱逐,只是把 CL 从上层移到下层 Cache。
52+
- Non-Inclusive Non-Exclusive Policy (NINE Policy): 下层 Cache 的 CL **不严格包含,也不严格不包含**高层 Cache 的 CL。NINE Policy 和 Inclusive Policy 行为几乎一致,除了一处:当下层 Cache 的 CL 被驱逐,上层 Cache 对应的 CL 不用驱逐。
53+
54+
具体看[这里的图](https://www.wikiwand.com/en/Cache_inclusion_policy)
55+
56+
### CPU 写策略 (Write policies)
57+
58+
- Write Through
59+
- Write Back
60+
61+
### CPU Cache Coherence
62+
63+
CPU 缓存一致性协议,有两种:嗅探协议和目录协议。
64+
65+
#### 嗅探协议
66+
67+
MESI 协议:
68+
69+
- 失效(Invalid)缓存段,要么已经不在缓存中,要么它的内容已经过时。为了达到缓存的目的,这种状态的段将会被忽略。一旦缓存段被标记为失效,那效果就等同于它从来没被加载到缓存中。
70+
- 共享(Shared)缓存段,它是和主内存内容保持一致的一份拷贝,在这种状态下的缓存段只能被读取,不能被写入。多组缓存可以同时拥有针对同一内存地址的共享缓存段,这就是名称的由来。
71+
- 独占(Exclusive)缓存段,和 S 状态一样,也是和主内存内容保持一致的一份拷贝。区别在于,如果一个处理器持有了某个 E 状态的缓存段,那其他处理器就不能同时持有它,所以叫“独占”。这意味着,如果其他处理器原本也持有同一缓存段,那么它会马上变成“失效”状态。
72+
- 已修改(Modified)缓存段,属于脏段,它们已经被所属的处理器修改了。如果一个段处于已修改状态,那么它在其他处理器缓存中的拷贝马上会变成失效状态,这个规律和 E 状态一样。此外,已修改缓存段如果被丢弃或标记为失效,那么先要把它的内容回写到内存中——这和回写模式下常规的脏段处理方式一样。
73+
74+
- [cache之多核一致性(一) - 总线上没有秘密](https://zhuanlan.zhihu.com/p/94811032)
75+
76+
#### Cache Line False Sharing
77+
78+
Cache Coherence 还会引起 [Cache Line False Sharing 问题](./cpu-cache-line-false-sharing.md)
79+
80+
### 参考资料
81+
82+
- [Wikipedia - CPU缓存](https://www.wikiwand.com/zh-hans/CPU%E7%BC%93%E5%AD%98)
83+
- [Cache是怎么组织和工作的?](https://zhuanlan.zhihu.com/p/31859105)
84+
- [Wikipedia - Cache inclusion policy](https://www.wikiwand.com/en/Cache_inclusion_policy)

0 commit comments

Comments
 (0)