Skip to content

Commit c619493

Browse files
committed
update
1 parent 47fe340 commit c619493

35 files changed

+578
-30
lines changed

.ecrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Exclude": ["*.md"]
3+
}

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
381381
- [BIOS](linux/bios.md)
382382
- [Block Layer](linux/block-layer.md)
383383
- [BootLoader](linux/boot-loader.md)
384-
- [BPF 与 XDP](linux/bpf-xdp.md)
384+
- [eBPF 与 XDP](linux/bpf-xdp.md)
385385
- [btrfs](linux/btrfs.md)
386386
- [内存的 buffer 和 cache](linux/buffer-and-cache-in-memory.md)
387387
- [在容器中构建 Package](linux/build-package-in-container.md)
@@ -468,7 +468,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
468468
- [不需要 root 权限执行 ping](linux/ping-without-sudo.md)
469469
- [管道重定向](linux/pipe-redirect.md)
470470
- [PostmarketOS](linux/postmarketos.md)
471-
- [/proc/interrupts](linux/proc-interrupts.md)
471+
- [进程中断](linux/proc-interrupts.md)
472472
- [进程内存](linux/process-memory.md)
473473
- [命令行中提示用户 Yes/No](linux/read-prompt.md)
474474
- [rm 命令](linux/rm.md)
@@ -507,6 +507,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
507507
- [Welcome Message Banner](linux/welcome-message-banner.md)
508508
- [监听 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)
509509
- [为什么创建 Daemon 进程要 Fork 两次?](linux/why-fork-twice-when-create-daemon-process.md)
510+
- [XDP](linux/xdp.md)
510511
- [ZFS](linux/zfs.md)
511512
- [Zsh 的坑](linux/zsh-pitfalls.md)
512513

@@ -569,9 +570,13 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
569570
- [HTTP Request/Response 网络包](network/http-request-and-response-package.md)
570571
- [NAT](network/nat.md)
571572
- [pfctl](network/pfctl.md)
573+
- [私有网段](network/private-ip.md)
572574
- [Samba](network/samba.md)
573575
- [SDN](network/sdn.md)
574576
- [TCP Buffer 大小](network/tcp-buffer-size.md)
577+
- [TUN/TAP](network/tun-tap.md)
578+
- [虚拟网络设备](network/virtual-network-devices.md)
579+
- [vlan](network/vlan.md)
575580
- [vxlan](network/vxlan.md)
576581

577582
[`⬆ 返回目录`](#toc)

build.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ exports.categoryNameMap = {
2222
vm: '虚拟机',
2323
proverbs: '箴言录',
2424
hardware: '硬件',
25+
ml: '机器学习',
2526
};

docker/dockerfile.md

+47
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,50 @@ CMD ["/home/user/bin/xxx"]
5656
- `RUN apt update && apt install -y --no-install-recommends CMD && rm -rf /var/lib/apt/lists/*`
5757
- alpine 镜像
5858
- `RUN apk update && apk add --no-cache CMD`
59+
60+
### dockerfile 支持 heredoc
61+
62+
```dockerfile
63+
RUN <<EOF
64+
echo "Hello" >> /hello
65+
echo "World!" >> /hello
66+
EOF
67+
68+
RUN <<EOF
69+
apt-get update
70+
apt-get upgrade -y
71+
apt-get install -y ...
72+
EOF
73+
74+
RUN <<EOF
75+
#!/usr/bin/env python3
76+
with open("/hello", "w") as f:
77+
print("Hello", file=f)
78+
print("World", file=f)
79+
EOF
80+
81+
RUN python3 <<EOF
82+
with open("/hello", "w") as f:
83+
print("Hello", file=f)
84+
print("World", file=f)
85+
EOF
86+
87+
RUN python3 <<EOF > /hello
88+
print("Hello")
89+
print("World")
90+
EOF
91+
```
92+
93+
```dockerfile
94+
COPY <<EOF /usr/share/nginx/html/index.html
95+
(your index page goes here)
96+
EOF
97+
98+
COPY <<robots.txt <<humans.txt /usr/share/nginx/html/
99+
(robots content)
100+
robots.txt
101+
(humans content)
102+
humans.txt
103+
```
104+
105+
详见 https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/

docker/podman-netns.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Podman netns
2+
3+
Podman 使用 [slirp4netns](https://github.com/rootless-containers/slirp4netns) 来实现 rootless 容器。
4+
5+
执行 `ps -ef | grep netns` 会看到
6+
7+
```
8+
podman 3042657 1 0 18:46 pts/5 00:00:00 /usr/bin/slirp4netns --disable-host-loopback --mtu=65520 --enable-sandbox --enable-seccomp --enable-ipv6 -c -r 3 --netns-type=path /run/user/1000/netns/rootless-netns-0f5e9301cae49369572e tap0
9+
```
10+
11+
你在宿主机上 `ip a` 是看不到 tap0 的。需要执行 `podman unshare nsenter --net=/run/user/1000/netns/rootless-netns-0f5e9301cae49369572e` 进入进程所在。
12+
`podman unshare` 实际上调用 [unshare](../linux/unshare.md) 命令来创建子网。
13+
因为每个用户所操作的 podman 区间是不一样的。
14+
15+
然后再执行 `ip a` 你就能看到所有 pod 相关的虚拟网络设备。
16+
17+
```
18+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
19+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
20+
inet 127.0.0.1/8 scope host lo
21+
valid_lft forever preferred_lft forever
22+
inet6 ::1/128 scope host
23+
valid_lft forever preferred_lft forever
24+
2: tap0: <BROADCAST,UP,LOWER_UP> mtu 65520 qdisc pfifo_fast state UNKNOWN group default qlen 1000
25+
link/ether 2a:05:eb:55:67:12 brd ff:ff:ff:ff:ff:ff
26+
inet 10.0.2.100/24 brd 10.0.2.255 scope global tap0
27+
valid_lft forever preferred_lft forever
28+
inet6 fd00::2805:ebff:fe55:6712/64 scope global dynamic mngtmpaddr
29+
valid_lft 86125sec preferred_lft 14125sec
30+
inet6 fe80::2805:ebff:fe55:6712/64 scope link
31+
valid_lft forever preferred_lft forever
32+
3: cni-podman1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
33+
link/ether ea:4c:ad:e1:92:2b brd ff:ff:ff:ff:ff:ff
34+
inet 10.89.0.1/24 brd 10.89.0.255 scope global cni-podman1
35+
valid_lft forever preferred_lft forever
36+
inet6 fe80::e84c:adff:fee1:922b/64 scope link
37+
valid_lft forever preferred_lft forever
38+
4: vethd15490c0@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master cni-podman1 state UP group default
39+
link/ether 42:da:15:77:d9:f8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
40+
inet6 fe80::40da:15ff:fe77:d9f8/64 scope link
41+
valid_lft forever preferred_lft forever
42+
10: vethf735a2dc@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master cni-podman1 state UP group default
43+
link/ether ca:05:68:9e:e4:4a brd ff:ff:ff:ff:ff:ff link-netnsid 1
44+
inet6 fe80::c805:68ff:fe9e:e44a/64 scope link
45+
valid_lft forever preferred_lft forever
46+
```

go/gc.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Golang GC
2+
3+
[基本概念](../language/gc.md)
4+
5+
6+
> Go的垃圾收集器从一开始到现在一直在演进,在v1.5版本开始三色标记法作为垃圾回收算法前使用Mark-And-Sweep(标记清除)算法。从v1.5版本Go实现了基于三色标记清除的并发垃圾收集器,大幅度降低垃圾收集的延迟从几百 ms 降低至 10ms 以下。在v1.8又使用混合写屏障将垃圾收集的时间缩短至 0.5ms 以内。
7+
8+
### 回收过程
9+
10+
> 一次完整的垃圾回收会分为四个阶段,分别是标记准备、标记、结束标记以及清理。在标记准备和标记结束阶段会需要 STW,标记阶段会减少程序的性能,而清理阶段是不会对程序有影响的。
11+
12+
https://zhuanlan.zhihu.com/p/105571503

go/go-module.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ Golang 管理模块有两种模式:
1212
- `GO111MODULE=auto` 或不设置 `GO111MODULE` 变量: Golang 自己检测是不是使用 Module-Aware Mode。
1313

1414

15+
## 缓存机制
16+
17+
https://golang.org/ref/mod#module-cache
18+
19+
1520
[1]: https://golang.org/cmd/go/#hdr-Vendor_Directories

go/go-tool.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# go tool
2+
3+
## go tool pprof
4+
5+
## go tool trace

go/golang-learning.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
3. https://tour.go-zh.org/
2424
4. [Draveness - Go 语言设计与实现](https://draveness.me/golang)
2525
5. https://github.com/a8m/golang-cheat-sheet
26+
6. https://go.dev/ref/spec
27+
7. [Go 语言圣经](http://shouce.jb51.net/gopl-zh)
2628

2729
### 命令
2830

go/gorutine.md

+11
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ Gorutine 是 Go 语言实现的一种协程 (Coroutine)。它完全运行在用
1111
- [Golang 调度器 GMP 原理与调度全分析](https://learnku.com/articles/41728) ([链接备份](https://web.archive.org/web/20230301090416/https://learnku.com/articles/41728))
1212
- [Go语言学习 - GMP模型](https://juejin.im/post/6844904034449489933) ([链接备份](https://web.archive.org/web/20221031233444/https://juejin.cn/post/6844904034449489933))
1313
- [图解Go运行时调度器](https://tonybai.com/2020/03/21/illustrated-tales-of-go-runtime-scheduler/) ([链接备份](https://tonybai.com/2020/03/21/illustrated-tales-of-go-runtime-scheduler/))
14+
- [Golang 调度器 GMP 原理与调度全分析](https://learnku.com/articles/41728) ([链接备份](https://web.archive.org/web/20230301090416/https://learnku.com/articles/41728))
1415

1516
### 调度器跟踪
1617

1718
使用 `GODEBUG=schedtrace=DURATION` 环境变量运行 Go 程序以启用调度程序跟踪。(DURATION 是以毫秒为单位的输出周期。)
1819

1920
调度器跟踪详见[这里](https://github.com/golang/go/wiki/Performance#scheduler-trace)
21+
22+
### GMP 模型的阻塞情况
23+
24+
GMP 模型的阻塞可能发生在下面几种情况:
25+
26+
- I/O,select
27+
- block on syscall
28+
- channel
29+
- 等待锁
30+
- runtime.Gosched()

java/gc.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Java GC
2+
3+
[基本概念](../language/gc.md)
4+
5+
https://juejin.im/post/6874810532730404878/
6+
7+
### Minor GC
8+
9+
### Full GC
10+
11+
### 垃圾回收器 (Garbage Collector)
12+
13+
垃圾回收器是垃圾回收算法(标记-清除算法、复制算法、标记-整理算法、火车算法)的具体实现。不同商家、不同版本的 JVM 所提供的垃圾收集器可能会有很在差别。
14+
15+
- CMS (Concurrent Mark Sweep)
16+
- G1
17+
- Serial
18+
- ParNew
19+
- Parallel Scavenge
20+
- Serial Old
21+
- Parallel Old
22+
23+
![](https://user-gold-cdn.xitu.io/2020/5/5/171e4e6bd164f9f7?imageView2/0/w/1280/h/960/format/webp/ignore-error/1)

language/gc.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## 垃圾回收 Garbage Collection (GC)
2+
3+
### 基本概念
4+
5+
- GC 负责回收堆内存,不负责回收栈内存
6+
7+
### 基本算法
8+
9+
- 垃圾定位算法
10+
- 引用计数算法 (Reference Counting)
11+
- 根搜索算法 (GC Roots Tracing)
12+
- 三色标记法
13+
- 垃圾回收算法
14+
- 复制算法 (Copying)
15+
- 标记-清除算法 (Mark-Sweep)
16+
- 标记-整理算法 (Mark-Compact)
17+
- 分代回收算法
18+
- 老年代 (Tenured Generation)
19+
- 新生代 (Young Generation)
20+
- 永久代 (Permanet Generation)
21+
22+
### 可能导致的问题
23+
24+
1. CPU 飙升,周期性毛刺
25+
2. 请求延时增大
26+
27+
### 三色标记法
28+
29+
自己查。随便给个[例子](https://zhuanlan.zhihu.com/p/105495961)
30+
31+
优点是不会引起 STW,并发执行。
32+
33+
缺点是:
34+
35+
1. 无法判断早先被标记为黑色目前是否不可达。
36+
2. 灰色对象断开了白色对象的引用;即灰色对象原来成员变量的引用发生了变化。
37+
3. 黑色对象重新引用了该白色对象;即黑色对象成员变量增加了新的引用。
38+
39+
### 读屏障
40+
41+
### 写屏障
42+
43+
### STW (Stop The World)
44+
45+
STW 会造成延时问题。
46+
47+
### 不同语言的 GC 机制
48+
49+
- [NodeJS](../nodejs/gc.md)
50+
- [Golang](../go/gc.md)
51+
- [Java](../java/gc.md)

linux/bpf-xdp.md

-7
This file was deleted.

linux/bpf-xdp.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./ebpf-and-xdp.md

linux/dmesg.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ dmesg 用来显示或控制内核环缓冲区(kernel-ring buffer)的内容
55
在开机系统引导 (boot) 阶段,内核将与硬件和模块初始化相关的信息填到这个缓冲区中。这些消息也存在 `/var/log/dmesg` 文件里。
66

77
`dmesg` 命令会直接输出所有消息。使用 `dmesg -H` 来滚屏阅读更方便。
8+
9+
## Kernel Ring Buffer
10+
11+
Kernel Ring Buffer 由一块内存区域和两个指针组成,其中一个指向缓冲区的起始位置,另一个则指向当前可写入的位置。当缓冲区满时,新的消息将从缓冲区的起始位置覆盖旧的消息。
12+
13+
Kernel Ring Buffer 的大小是由内核启动参数 log_buf_len 决定的,它指定了内核环形缓冲区的最大大小。
14+
默认情况下,log_buf_len 的值为 16KB 或 1/12 的物理内存大小(以较小者为准)。
15+
16+
`dmesg -n 64K` 可以将 Kernel Ring Buffer 的大小设为 64KB。

linux/ebpf-and-xdp.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## eBPF 与 XDP
22

3+
https://ebpf.io/
4+
5+
eBPF (extended Berkeley Packet Filter) 起源于 BPF,它提供了内核的数据包过滤机制。
6+
7+
XDP 详见[这里](./xdp.md)
8+
39
### 基本概念
410

511
- BPF Map
@@ -48,20 +54,6 @@ BPF 代码运行时编译,不仅需要 kernel header,而且需携带 llvm/cl
4854
- [HOWTO: BCC to libbpf conversion](https://facebookmicrosites.github.io/bpf/blog/2020/02/20/bcc-to-libbpf-howto-guide.html) ([链接备份](https://web.archive.org/web/20221130165544/https://facebookmicrosites.github.io/bpf/blog/2020/02/20/bcc-to-libbpf-howto-guide.html))
4955
- [BPF Portability and CO-RE](https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html) ([链接备份](https://web.archive.org/web/20230120022211/https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html))
5056

51-
### XDP 模式
52-
53-
XDP 支持三种模式,默认使用 `native` 模式。
54-
55-
- Native (XDP_FLAGS_DRV_MODE):XDP BPF 程序运行在网络接口控制器 (NIC) 的早期接收路径(RX 队列)上。
56-
- Offloaded (XDP_FLAGS_HW_MODE):XDP BPF 程序直接在 NIC 中处理报文,而不会使用主机的 CPU。因此,处理报文的成本非常低,性能要远远高于 Native 模式。该模式通常由智能网卡实现,包含多线程,多核流量处理器(以及一个内核的 JIT 编译器,将 BPF 转变为该处理器可以执行的指令)。支持 Offloaded 的驱动通常也支持 Native(某些 BPF 辅助函数通常仅支持native 模式)。
57-
- Generic (XDP_FLAGS_SKB_MODE):对于没有实现 Native 或 Offloaded 模式的 XDP,内核提供了一种处理 XDP 的通用方案。该模式运行在网络栈中,不需要对驱动进行修改。该模式主要用于给开发者测试使用 XDP API 编写的程序,其性能要远低于 Native 或 Offloaded 模式。在生产环境中,建议使用 Native 或 Offloaded模式。
58-
59-
60-
#### 支持 Native 的网卡驱动列表
61-
62-
- https://github.com/xdp-project/xdp-project/blob/master/areas/drivers/README.org
63-
- https://github.com/iovisor/bcc/blob/master/docs/kernel-versions.md#xdp
64-
6557
### BPF Map 文件
6658

6759
map 数据都放在 `/sys/fs/bpf/` 目录下。

0 commit comments

Comments
 (0)