Rust Atomics and Locks 摘录和评注 2023-11-21

内容摘自 <<Rust Atomics and Locks>>.

1 release-acquire 和 fence

1.1 拆分

The store of a release-acquire relationship,

a.store(1, Release);

can be substituted by a release fence followed by a relaxed store:

fence(Release);
a.store(1, Relaxed);

类似的, The load of a release-acquire relationship,

a.load(Acquire);

(草稿)调试k8s网络 2022-11-19

nicolaka/netshoot

$ kubectl run  -ti --rm awakening-fong -n cattle-system --image nicolaka/netshoot:v0.8 -- /bin/bash

执行 ip route add 会出错, 如何 privileged?

处理:

    securityContext:
      privileged: true

无效的: --overrides='{"securityContext": {"privileged": true}}'

nsenter 容器 中执行

使用 netstat -s 检查下是否有丢包统计:

$ netstat -s | grep -E 'overflow|drop'
    123 times the listen queue of a socket overflowed
    456 SYNs to LISTEN sockets dropped

perfbook 03 barrier 2022-10-03

perfbook 指的是 Is Parallel Programming Hard, And, If So, What Can You Do About It? pdf 版本可以从如下网址获取: https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html


本文不打算从原理上来理解, 仅为了快速使用, 故缺失严谨.


5.4.4

第16行执行一条内存屏障,确保任何看见第17行设置READY状态的CPU,也能看见第9行的效果

awakening-fong 注释:

16  smp_mb();
17 WRITE_ONCE(theft, THEFT_READY);

perfbook 01 摘录 2022-09-17

perfbook 指的是 Is Parallel Programming Hard, And, If So, What Can You Do About It? pdf 版本可以从如下网址获取: https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html

5.4.6 Applying Exact Limit Counters

Quick Quiz 5.58: This is ridiculous! We are read-acquiring a reader-writer lock to update the counter? What are you playing at?

答: 这里要强调的是 读锁 允许 多人同时持有,写锁只允许单人持有。 跟 是否进行 读写操作没有必然关系。

Chapter 6 Partitioning and Synchronization Design

一种强制锁范围不重叠的办法。两个单独的双端队列串联在一起,每个队列用自己的锁保护。这意味着数据偶尔会从一个双端队列跑到另一个双端队列。此时必须同时持有两把锁。

awakening-fong: 妙

(草稿)perfbook 02 自问自答 2022-09-17

perfbook 指的是 Is Parallel Programming Hard, And, If So, What Can You Do About It? pdf 版本可以从如下网址获取: https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html

5.3.3 的内容如何理解

可以结合如下问题来理解 Quick Quiz 5.33: p.129 Given that globalreserve counted against us in add_count(), why doesn’t it count for us in sub_count() in Listing 5.7?

答: awakening-fong: add_count()返回0是失败, 认为是 against. 而不是说 访问锁是 against.

add_count 的局部代码:

9  if (globalcountmax -
10      globalcount - globalreserve < delta) {
11      spin_unlock(&gblcnt_mutex);
12      return 0;
13 }