<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Yuchen You</title>
    <link>https://www.whoami-wesleyyou.top/</link>
    <description>Recent content on Yuchen You</description>
    <generator>Hugo</generator>
    <language>zh-CN</language>
    <lastBuildDate>Thu, 05 Nov 2026 20:00:00 +0800</lastBuildDate>
    <atom:link href="https://www.whoami-wesleyyou.top/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>DPDK 模拟物理网卡实现</title>
      <link>https://www.whoami-wesleyyou.top/2026/11/05/computer_system_basics/network/dpdk-dpu-shaper/</link>
      <pubDate>Thu, 05 Nov 2026 20:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/11/05/computer_system_basics/network/dpdk-dpu-shaper/</guid>
      <description>&lt;p&gt;这篇记录一个小东西: 在 BlueField-2 (BF2) 的 Arm 上用 DPDK 写一个逐帧严格限速的整形器 &lt;code&gt;dpu_shaper&lt;/code&gt;, 让一张 100G 的网卡老老实实地扮演一根 10G / 25G 的网线.&lt;/p&gt;
&lt;p&gt;代码 800 来行 C, 修了四个大 bug, 背后都是同一句话: &lt;strong&gt;把限速从网卡里搬出来以后, 发送方就看不见它了&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;实验动机与实现&#34;&gt;实验动机与实现&lt;/h2&gt;
&lt;h3 id=&#34;起因-vf-限速是个假的-25g&#34;&gt;起因: VF 限速是个假的 25G&lt;/h3&gt;
&lt;p&gt;实验要模拟 &amp;ldquo;某个节点网卡变慢了&amp;rdquo; (straggler). 最省事的做法是给它的 VF 设 &lt;code&gt;max_tx_rate&lt;/code&gt;, 长期平均看确实是 25G.&lt;/p&gt;</description>
    </item>
    <item>
      <title>MILP 与 SMT</title>
      <link>https://www.whoami-wesleyyou.top/2026/11/04/computer_system_basics/structure_algorithm/milp-smt/</link>
      <pubDate>Wed, 04 Nov 2026 00:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/11/04/computer_system_basics/structure_algorithm/milp-smt/</guid>
      <description>MILP 的上下界, LP Relaxation, 逻辑约束与 Big-M, 以及 AllGather 建模, SAT/SMT 和程序合成的手写笔记整理.</description>
    </item>
    <item>
      <title>Theseus: Runtime-Adaptive GPU Collective Communication with Hot-Swappable Schedules</title>
      <link>https://www.whoami-wesleyyou.top/2026/11/04/mlsys/theseus/</link>
      <pubDate>Wed, 04 Nov 2026 00:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/11/04/mlsys/theseus/</guid>
      <description>Theseus 的 Dynamic Selection, Hot Swapping 与资源树维护手写阅读笔记.</description>
    </item>
    <item>
      <title>LoRA 与 QLoRA</title>
      <link>https://www.whoami-wesleyyou.top/2026/11/02/mlsys/lora-qlora/</link>
      <pubDate>Mon, 02 Nov 2026 00:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/11/02/mlsys/lora-qlora/</guid>
      <description>LoRA 低秩更新, NF4 分位数量化与 Double Quantization 的手写笔记整理.</description>
    </item>
    <item>
      <title>NCCL 初始化与连接建立</title>
      <link>https://www.whoami-wesleyyou.top/2026/10/19/computer_system_basics/network/nccl-init-connections/</link>
      <pubDate>Mon, 19 Oct 2026 20:10:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/10/19/computer_system_basics/network/nccl-init-connections/</guid>
      <description>&lt;h2 id=&#34;初始化-从硬件拓扑到可用连接&#34;&gt;初始化: 从硬件拓扑到可用连接&lt;/h2&gt;
&lt;h3 id=&#34;先区分-topo-graph-channel-和-connection&#34;&gt;先区分 topo, graph, channel 和 connection&lt;/h3&gt;
&lt;p&gt;NCCL 建立连接的主线可以记成 &lt;strong&gt;发现硬件 → 搜索通信图 → 拼出各 channel 的逻辑邻居 → 为邻居建立 transport 连接&lt;/strong&gt;. 建立好之后, collective kernel 和 proxy 才沿着这些连接推进数据.&lt;/p&gt;
&lt;p&gt;例如两台机器各有两个 rank. NCCL 先知道 GPU 和 NIC 如何连接, 再为某个 channel 选出节点内顺序 &lt;code&gt;[0, 1]&lt;/code&gt; 和 &lt;code&gt;[2, 3]&lt;/code&gt;, 将两段拼成 &lt;code&gt;0 → 1 → 2 → 3 → 0&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>RDMA 基础</title>
      <link>https://www.whoami-wesleyyou.top/2026/10/19/computer_system_basics/network/rdma-basics/</link>
      <pubDate>Mon, 19 Oct 2026 16:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/10/19/computer_system_basics/network/rdma-basics/</guid>
      <description>&lt;h2 id=&#34;资源对象与完成结果&#34;&gt;资源对象与完成结果&lt;/h2&gt;
&lt;h3 id=&#34;从一次接收理解-rdma&#34;&gt;从一次接收理解 RDMA&lt;/h3&gt;
&lt;p&gt;先把 RDMA 理解成应用和网卡之间的一组队列. 应用提交要做的工作, 网卡执行, 再把执行结果放回完成队列. 实际传输的数据放在提前注册的内存中.&lt;/p&gt;
&lt;p&gt;以 A 向 B 发送一条消息为例, B 先准备接收 buffer, 将这段内存注册成 MR, 再往 QP 的 RQ 中提交接收请求. 消息到达后, B 的网卡根据请求把数据写入 buffer, 并向 CQ 写入完成记录. B 的应用取出完成结果后, 就可以处理 buffer 中的数据.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Kimi Linear: An Expressive, Efficient Attention Architecture</title>
      <link>https://www.whoami-wesleyyou.top/2026/09/02/mlsys/LanguageModel/10.kimi-linear/</link>
      <pubDate>Wed, 02 Sep 2026 23:43:10 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/09/02/mlsys/LanguageModel/10.kimi-linear/</guid>
      <description>&lt;h2 id=&#34;整体架构&#34;&gt;整体架构&lt;/h2&gt;
&lt;p&gt;Kimi Linear 将 KDA 和 MLA 放在 Transformer 的 token-mixing 位置, 并采用 &lt;code&gt;3 个 KDA layers + 1 个 MLA layer&lt;/code&gt; 的排列; KDA 用固定大小的 recurrent state 处理历史信息, MLA 则保留 full attention 与 latent KV cache; 每个 token-mixing layer 后仍然连接一个 MoE layer, 整体数据流保持 &lt;code&gt;Norm -&amp;gt; KDA 或 MLA -&amp;gt; residual -&amp;gt; Norm -&amp;gt; MoE -&amp;gt; residual&lt;/code&gt;;&lt;/p&gt;
&lt;h2 id=&#34;kda-layer-的输入-状态更新与输出&#34;&gt;KDA layer 的输入, 状态更新与输出&lt;/h2&gt;
&lt;p&gt;生成第 $t+1$ 个 token 时, KDA layer $l$ 接收两个输入: 当前 token 从上一层传来的 hidden vector $h_t^{(l)}$, 以及本层处理完上一个 token 后留下的 recurrent state $S_{t-1}^{(l)}$; 前者沿模型深度方向在 layers 之间传递, 后者沿 token 时间方向保留在同一个 KDA layer 内;&lt;/p&gt;</description>
    </item>
    <item>
      <title>FreeToken: Efficient Edge-Native MoE Serving with Bandwidth-Adaptive Execution</title>
      <link>https://www.whoami-wesleyyou.top/2026/09/02/mlsys/Paper/FreeToken%20-%20Efficient%20Edge-Native%20MoE%20Serving%20with%20Bandwidth-Adaptive%20Execution/</link>
      <pubDate>Wed, 02 Sep 2026 21:27:27 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/09/02/mlsys/Paper/FreeToken%20-%20Efficient%20Edge-Native%20MoE%20Serving%20with%20Bandwidth-Adaptive%20Execution/</guid>
      <description>&lt;h2 id=&#34;背景&#34;&gt;背景&lt;/h2&gt;
&lt;p&gt;MoE 模型的总参数量虽然很大, 但每个 token 实际只会激活其中少量 experts, 因此 active parameters 远小于总参数量, 这个现象称为 sparse activation; 它让消费级 GPU 具备了计算大规模 MoE 模型的可能性, 因为 GPU 只需要执行当前激活的部分, 不需要同时计算完整的 expert pool;&lt;/p&gt;
&lt;p&gt;但是, 完整 expert pool 仍然可能远大于 GPU 显存, 因此需要主要保存在 host memory 中; FreeToken 希望把个人电脑的 GPU, CPU, memory 和 interconnect 组合成一个完整的 serving system; 当需要的 expert 没有命中 GPU cache 时, 系统可以将 expert weights 搬到 GPU 上计算, 也可以将较小的 activation tensor 传到 CPU 侧直接计算;&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 时序概率建模: 从 Binomial 到 Weibull</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/27/computer_system_basics/math/1.poisson_to_weibull/</link>
      <pubDate>Mon, 27 Jul 2026 17:01:45 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/27/computer_system_basics/math/1.poisson_to_weibull/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;到达过程黑话&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;arrival process (到达过程): 事件在时间轴上一个个冒出来的随机过程&lt;/li&gt;
&lt;li&gt;$N(t)$: 到时刻 $t$ 为止发生了多少次事件 (计数视角)&lt;/li&gt;
&lt;li&gt;$T_k$: 第 $k$ 次事件发生的时刻 (等待视角)&lt;/li&gt;
&lt;li&gt;$\lambda$: rate, 单位时间平均发生几次&lt;/li&gt;
&lt;li&gt;survival function $S(t) = P(T &gt; t)$: &amp;ldquo;撑到 $t$ 还没出事&amp;rdquo; 的概率&lt;/li&gt;
&lt;li&gt;hazard rate $h(t)$: 风险率, 已经活到 $t$ 了, 下一瞬间出事的密度&lt;/li&gt;
&lt;li&gt;shape parameter $k$: Weibull 里控制 hazard 走势的那个形状参数&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Binomial (n 次独立试验, 每次概率 p)
   ↓ n → ∞, p → 0, np = λt 固定
Poisson(λt)          &amp;#34;固定一段时间 t, 数一数发生了几次&amp;#34;
   ↓ 反过来问: 等第 1 次要多久
Exponential(λ)       &amp;#34;间隔时间, 无记忆&amp;#34;
   ↓ 把 k 个间隔加起来
Gamma(k, λ)          &amp;#34;等到第 k 次要多久&amp;#34;
   ↓ 放弃 λ 恒定的假设, 让风险率随时间变
Weibull(k, λ)        &amp;#34;会老化 / 会磨合的那种失效&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;poisson-把二项分布拉到极限&#34;&gt;Poisson: 把二项分布拉到极限&lt;/h2&gt;
&lt;p&gt;先讲怎么来的; 我们把一段长度为 $t$ 的时间切成 $n$ 个极小的格子, 每个格子里最多发生一次事件, 发生的概率是 $p$; 既然平均下来这段时间要发生 $\lambda t$ 次, 那么每格的概率就是&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. Speculative Decoding</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/23/mlsys/LanguageModel/3.speculativedecoding/</link>
      <pubDate>Thu, 23 Jul 2026 14:17:34 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/23/mlsys/LanguageModel/3.speculativedecoding/</guid>
      <description>&lt;h2 id=&#34;speculative-decoding-的朴素思想&#34;&gt;Speculative Decoding 的朴素思想&lt;/h2&gt;
&lt;p&gt;想要加速一个 auto-regressive 模型的推理, 可以先猜测合理的上下文, 再让大模型一次验证多个位置; 比如已经有 prefix, 小模型先猜出 &lt;code&gt;I love cats&lt;/code&gt;, 大模型验证后保留 &lt;code&gt;I love&lt;/code&gt;, 在 &lt;code&gt;cats&lt;/code&gt; 这里拒绝并补出 &lt;code&gt;dogs&lt;/code&gt;, 后面基于 &lt;code&gt;cats&lt;/code&gt; 生成的内容就不能继续保留;&lt;/p&gt;
&lt;p&gt;这里有两个角色: &lt;strong&gt;Draft Model&lt;/strong&gt; 负责快速生成候选, &lt;strong&gt;Target Model&lt;/strong&gt; 负责验证和确定最终输出; 上面的例子是在说明接受前缀和截断的位置, 随机 sampling 下的接受规则还需要下面的概率推导;&lt;/p&gt;</description>
    </item>
    <item>
      <title>7.cachegen</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/16/mlsys/InferenceEngine/7.cachegen/</link>
      <pubDate>Thu, 16 Jul 2026 13:46:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/16/mlsys/InferenceEngine/7.cachegen/</guid>
      <description>&lt;h2 id=&#34;背景&#34;&gt;背景&lt;/h2&gt;
&lt;h3 id=&#34;tokenwise-locality&#34;&gt;Tokenwise locality&lt;/h3&gt;
&lt;h3 id=&#34;layerwise-sensitivity-to-loss&#34;&gt;Layerwise sensitivity to loss&lt;/h3&gt;
&lt;h2 id=&#34;encoding-和-decoding&#34;&gt;Encoding 和 Decoding&lt;/h2&gt;
&lt;h3 id=&#34;delta-encoding&#34;&gt;Delta Encoding&lt;/h3&gt;
&lt;p&gt;我们在构建搜索引擎的底层存储编码格式的时候用过一个 Delta Encoding/Decoding 的思路，将对应 token 坐标通过相对位置来存储，可以让大数字变成较小的相对位移来存储来减少存储量；这里用到了非常类似的思路: 对于一个 token 的值 (KV cache)，我们用相对于前面值的变化量来存储，当然在这里需要一个 microbench 来说明这个存储在 token kv 背景下确实可以减少存储量:&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. FlashAttention</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/15/mlsys/LanguageModel/2.flashattention/</link>
      <pubDate>Wed, 15 Jul 2026 21:30:24 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/15/mlsys/LanguageModel/2.flashattention/</guid>
      <description>&lt;h2 id=&#34;复杂度分析从-flops-到-hbm-ios&#34;&gt;复杂度分析：从 FLOPS 到 HBM IOs&lt;/h2&gt;
&lt;p&gt;传统计算的优化，比如 gemm 的 cublas 实现分析都是专注于减少一个计算中 gpu flops 的数量，但是实际上 gpu 的高速内存 SRAM 和相对低速内存 HBM 的读写 IO 率也是影响整体程序性能的重要的因素；因此本文提出做一个 IO-aware attention kernel 来减少 IO 吞吐数量&lt;/p&gt;
&lt;p&gt;&lt;img alt=&#34;flashattention_problem_statement.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/flashattention_problem_statement.png&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;tiling&#34;&gt;Tiling&lt;/h2&gt;
&lt;p&gt;传统 gemm 中的 tiling 是指每次处理一个 block 而不是完整读写一整个行向量，这样可以提升 io 的连续性从而提升性能；但是这里的 attention 计算不能直接用 gemm 的优化，因为存在一个 需要全局 reduce 的 softmax 函数，并且需要用到全局最大值来做 max trick，这个其实是很不利于 tiling 这样分块的实现的&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. MoE 架构</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/14/mlsys/LanguageModel/1.moe/</link>
      <pubDate>Tue, 14 Jul 2026 11:05:09 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/14/mlsys/LanguageModel/1.moe/</guid>
      <description>&lt;h2 id=&#34;challenge&#34;&gt;Challenge&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;GPU 并不像 CPU 那么适合做 branching 操作，如果我们在 kernel 中写一个 if-else 指令，那么两个 branch 的函数执行都会被放到解释器这里来，导致执行速度慢于完全并行同等操作;&lt;/li&gt;
&lt;li&gt;如果让 batch inference 请求同时通过这个 moe-FFN 层, 这个 batch 内必须统一 expert 而不能分开;&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=&#34;moe_fundamental_structure.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/moe_fundamental_structure.png&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;主要框架&#34;&gt;主要框架&lt;/h2&gt;
&lt;p&gt;标准公式&lt;/p&gt;
&lt;div class=&#34;math-display&#34;&gt;$$&amp;#10;y = \Sigma_{i=1}^{n} G_i(x) E_i(x)&amp;#10;$$&lt;/div&gt;
&lt;p&gt;这里的 $G$ 指的是 gating, 用于将输入的 x 向量映射到 n 个 experts 对应的输出用于表示权重; 这里 G 就是一个可训练的神经网络, 可以写作&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. sglang</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/11/mlsys/InferenceEngine/6.sglang/</link>
      <pubDate>Sat, 11 Jul 2026 20:57:19 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/11/mlsys/InferenceEngine/6.sglang/</guid>
      <description>&lt;p&gt;这篇作品和十多年前的 Spark 的设计非常类似，都是 frontend (DSL) &amp;ndash; runtime codesign 来实现全局的加速;&lt;/p&gt;
&lt;h2 id=&#34;frontend-with-dsl&#34;&gt;Frontend with DSL&lt;/h2&gt;
&lt;h2 id=&#34;runtime-radix-attention&#34;&gt;Runtime (Radix Attention)&lt;/h2&gt;
&lt;h3 id=&#34;解决的问题&#34;&gt;解决的问题&lt;/h3&gt;
&lt;p&gt;还是针对 KV cache 的计算角度，sglang 希望能解决不同 request 之间的 prefix 共享问题，尤其是在 system prompt 存在的情况下，很多时候的 system prompt 是大多数请求共享的，并不需要每次都计算，这样可以节省很多计算量;&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. PagedAttention and the vLLM Engine</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/07/mlsys/InferenceEngine/3.vllm/</link>
      <pubDate>Tue, 07 Jul 2026 23:27:49 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/07/mlsys/InferenceEngine/3.vllm/</guid>
      <description>&lt;h2 id=&#34;kv-cache-优化的讨论&#34;&gt;KV Cache 优化的讨论&lt;/h2&gt;
&lt;p&gt;对于一个 Transformer Block, 我们应该有 token tensor -&amp;gt; projection -&amp;gt; attention -&amp;gt; FFN 这几个核心步骤; 那么使用 kv cache 的话在 decode 阶段可以把 attention 计算的复杂度降低到 $O(N)$，并且这个可以同时利好 projection 和后续的 ffn 让其不再需要处理完整的 prompt 而是只有最后一个新的 token; 因此 kv cache 的 &lt;strong&gt;存在&lt;/strong&gt; 可以极大地优化一个 decode 推理流程;&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Orca: Iteration Level Scheduling and Selective Batching</title>
      <link>https://www.whoami-wesleyyou.top/2026/07/07/mlsys/InferenceEngine/2.orca/</link>
      <pubDate>Tue, 07 Jul 2026 14:04:10 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/07/07/mlsys/InferenceEngine/2.orca/</guid>
      <description>&lt;h2 id=&#34;prefill-阶段的计算复杂度&#34;&gt;Prefill 阶段的计算复杂度&lt;/h2&gt;
&lt;p&gt;工业常见 dense LLM 的 hidden dimension 大概是 4K 到 16K 量级&lt;/p&gt;
&lt;h2 id=&#34;无法-batch-的几种情况&#34;&gt;无法 batch 的几种情况&lt;/h2&gt;
&lt;p&gt;其实卡住 batch 的原因都是在 attention 模块的计算部分&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;两个进程都在 prefill 阶段但是二者张量的形状不同;
&lt;ul&gt;
&lt;li&gt;prefill 阶段二者都要计算完整的 $softmax(\frac{QK^t}{\sqrt{d_k}})V$, 如果要一起计算就需要 $X.shape(-1)$ 和 $X.shape(-2)$ 分别相等，也就是张量形状一致;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;两个进程都在 decode 阶段但是二者的 token id 不同;
&lt;ul&gt;
&lt;li&gt;decode 阶段计算是最后一个 token 对应的 query 去和前面所有的 K 和 V 做匹配，如果二者的 index 不同，说明其前面的 K 和 V 的行数 (sequence id/维度) 不同，从而导致形状不同&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;两个进程处在不同的 p/d 阶段;
&lt;ul&gt;
&lt;li&gt;计算量不同，一个是矩阵 times 向量; 一个是矩阵 times 矩阵&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;orca-的局限性&#34;&gt;Orca 的局限性&lt;/h2&gt;
&lt;p&gt;Orca 的设计目的是实现 iteration level scheduling 的问题，一次 iteration 就是 transformer 完整的模块吐出一个 token 的粒度，那么在这个粒度内部，如果存在 prefill 和 decode 并行的情况，那么我们会注意到问题:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Mem0 - Building Production-Ready AI Agents with Scalable Long-Term Memory</title>
      <link>https://www.whoami-wesleyyou.top/2026/06/26/agentsys/memory/Mem0%20-%20Building%20Production-Ready%20AI%20Agents%20with%20Scalable%20Long-Term%20Memory/</link>
      <pubDate>Fri, 26 Jun 2026 03:09:58 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/06/26/agentsys/memory/Mem0%20-%20Building%20Production-Ready%20AI%20Agents%20with%20Scalable%20Long-Term%20Memory/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;Mem0 记忆管线的黑话&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;extraction phase: 从新一轮对话里提炼候选事实, 写入路径的第一步&lt;/li&gt;
&lt;li&gt;update phase: 候选事实和已有记忆对账, 决定 ADD / UPDATE / DELETE / NOOP&lt;/li&gt;
&lt;li&gt;$\Omega$: extraction 吐出的候选记忆集合&lt;/li&gt;
&lt;li&gt;$S$: 异步刷新的全局对话摘要, 提供&amp;quot;远景&amp;quot;&lt;/li&gt;
&lt;li&gt;tool call: LLM 自己选操作并执行的 function-calling 接口&lt;/li&gt;
&lt;li&gt;Mem0$^g$: 把记忆表示从自然语言换成知识图谱的变体&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;mem0-在-memory-光谱里的位置&#34;&gt;Mem0 在 memory 光谱里的位置&lt;/h2&gt;
&lt;p&gt;agent memory 这一堆框架, 区分它们最有用的是两个轴: 记忆的&lt;strong&gt;表示&lt;/strong&gt; (自然语言 / 向量 / 图 / 时序图) 和记忆的&lt;strong&gt;生命周期&lt;/strong&gt; (写入 $\rightarrow$ 检索 $\rightarrow$ 更新 $\rightarrow$ 遗忘);&lt;/p&gt;</description>
    </item>
    <item>
      <title>ZooKeeper: 不发钥匙, 改立公告板的协调服务</title>
      <link>https://www.whoami-wesleyyou.top/2026/06/20/computer_system_basics/ds/13.zookeeper/</link>
      <pubDate>Sat, 20 Jun 2026 14:30:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/06/20/computer_system_basics/ds/13.zookeeper/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;术语别名&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;handle: Chubby 里 client &lt;code&gt;open&lt;/code&gt; 一个 path 后拿到的, 绑定 session 的远程对象引用; 不是 session 本身, 是 session 内部的一个对象级句柄;&lt;/li&gt;
&lt;li&gt;znode: ZooKeeper 状态树上的一个节点, 既能当目录又能存一小坨 data, 带 version;&lt;/li&gt;
&lt;li&gt;ephemeral / sequential: 临时节点 (session 一断自动删) / 顺序节点 (创建时由 ZK 追加一个全局单调的编号), 选主 recipe 的两块积木;&lt;/li&gt;
&lt;li&gt;Zab: ZooKeeper Atomic Broadcast, ZK 内部的 leader-based 原子广播协议, 跟 Paxos / Raft 同级但不是同一个;&lt;/li&gt;
&lt;li&gt;A-linearizability: ZooKeeper 自己定义的一致性, 写线性 + 同一 client 的请求按发送序进入全局顺序 (per-client FIFO);&lt;/li&gt;
&lt;li&gt;wait-free: 一个 client 可以同时挂多个 in-flight 请求, 不用等上一个回包就发下一个 (能 pipeline);&lt;/li&gt;
&lt;li&gt;control plane / data plane: 控制面 (谁是 master, 配置是啥, 谁还活着) / 数据面 (真流量怎么转发);&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;定位-三家放一起-真正的分水岭在哪&#34;&gt;定位: 三家放一起, 真正的分水岭在哪&lt;/h2&gt;
&lt;p&gt;这篇接着 &lt;a href=&#34;https://www.whoami-wesleyyou.top/2026/06/10/computer_system_basics/ds/11.chubby/&#34;&gt;11.chubby&lt;/a&gt; 和 &lt;a href=&#34;https://www.whoami-wesleyyou.top/2026/06/09/computer_system_basics/ds/12.etcd/&#34;&gt;12.etcd&lt;/a&gt; 往下说; 把 Chubby, ZooKeeper, etcd 摆到一张桌子上, 第一直觉会想&amp;quot;它们内部共识协议不一样啊, Paxos / Zab / Raft&amp;quot;, 但这恰恰&lt;strong&gt;不是&lt;/strong&gt;最该盯的地方; 三家内部都是同一套路子: leader-based replicated state machine, 都要全局顺序 + quorum commit 来护住自己那点 metadata;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Google Chubby: 解耦控制数据平面的分布式锁系统</title>
      <link>https://www.whoami-wesleyyou.top/2026/06/10/computer_system_basics/ds/11.chubby/</link>
      <pubDate>Wed, 10 Jun 2026 00:22:06 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/06/10/computer_system_basics/ds/11.chubby/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;术语别名&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;cell: 一个故障隔离单元, 通常 1 master + 5 replica;&lt;/li&gt;
&lt;li&gt;coarse-grained lock: 粗粒度锁, 持有时间小时/天级 (典型如&amp;quot;我是这个集群的 master&amp;quot;), 跟毫秒级临界区互斥的 fine-grained lock 相对;&lt;/li&gt;
&lt;li&gt;advisory lock: 建议锁, 系统不强制, 靠&amp;quot;守规矩的应用&amp;quot;自觉遵守;&lt;/li&gt;
&lt;li&gt;safety / liveness: 安全性(&amp;ldquo;坏事永不发生&amp;rdquo;, 比如绝不脑裂) / 活性(&amp;ldquo;好事最终发生&amp;rdquo;, 比如最终能达成决定);&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;论文定位&#34;&gt;论文定位&lt;/h2&gt;
&lt;blockquote&gt;&lt;p&gt;Mike Burrows, &amp;ldquo;The Chubby lock service for loosely-coupled distributed systems&amp;rdquo;, OSDI 2006, Google;&lt;/p&gt;
&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>etcd: 把 Raft 包装成 k8s 的事实数据源</title>
      <link>https://www.whoami-wesleyyou.top/2026/06/09/computer_system_basics/ds/12.etcd/</link>
      <pubDate>Tue, 09 Jun 2026 22:57:07 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/06/09/computer_system_basics/ds/12.etcd/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;术语别名&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;etcd: 一个分布式、强一致、高可用的 KV 存储, 底层用 Raft 做共识, Go 写的, 现属 CNCF, 是 k8s 唯一的事实数据源 (source of truth);&lt;/li&gt;
&lt;li&gt;revision: etcd 集群级、全局单调递增的版本号, 每次成功的写/事务 +1, 是整个 keyspace 的&amp;quot;全局时钟&amp;quot;;&lt;/li&gt;
&lt;li&gt;MVCC: Multi-Version Concurrency Control, 多版本并发控制, 写不覆盖旧值而是生成新版本, 让读写互不阻塞;&lt;/li&gt;
&lt;li&gt;Watch: 订阅某个 key/区间从指定 revision 起的变更, 按序、不丢地推给客户端;&lt;/li&gt;
&lt;li&gt;Lease: 带 TTL 的 key, 客户端要不断续约 (keepalive), 断了自动删, 拿来做心跳/选主;&lt;/li&gt;
&lt;li&gt;Txn: etcd 的迷你事务, If/Then/Else, 本质是基于 revision 的 CAS (compare-and-swap);&lt;/li&gt;
&lt;li&gt;compaction: 压缩, 丢弃某 revision 之前的历史版本来回收空间, 压缩点同时也是 Watch 能回放的最早边界;&lt;/li&gt;
&lt;li&gt;reconcile: 调谐, 比较&amp;quot;期望状态&amp;quot;和&amp;quot;实际状态&amp;quot;、采取动作把差距抹平的幂等操作;&lt;/li&gt;
&lt;li&gt;List-Watch: 先全量拉一次基线 (List) 再持续追增量 (Watch) 的模式, k8s informer 的核心范式;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;从-raft-到-etcd-中间多了什么&#34;&gt;从 Raft 到 etcd: 中间多了什么&lt;/h2&gt;
&lt;p&gt;上回书我们学完了 Raft, 知道 Raft 解决的是「一组节点如何就一条有序日志达成一致」; 它是个 replicated state machine 的框架, 但它不规定状态机到底是什么, 只保证所有副本以相同顺序看到相同的 log entry;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Vpn from WireGuard Impl — 从论文批判到 Go 手写隧道</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/31/computer_system_basics/network/security/Vpn%20from%20WireGuard%20Impl/</link>
      <pubDate>Sun, 31 May 2026 18:10:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/31/computer_system_basics/network/security/Vpn%20from%20WireGuard%20Impl/</guid>
      <description>&lt;blockquote&gt;&lt;p&gt;这篇把两段东西并在一起读：&lt;br&gt;
&lt;strong&gt;上半场（理论与动机）&lt;/strong&gt; 是读 WireGuard 论文（NDSS 2017）整理出来的——VPN 三代演进、论文怎么把 IPsec 当反派批判、为什么 VPN 必须走 UDP、为什么 Go 也能写出一个完整 VPN；&lt;br&gt;
&lt;strong&gt;下半场（动手实现）&lt;/strong&gt; 是顺着这套理论真正写起来的个人项目 &lt;code&gt;mini-vpn-go&lt;/code&gt;（用户态 VPN，从零手写、逐 phase 演进，最终对标 WireGuard），目前跑通到 Phase 2 的明文 IP-in-UDP 隧道。&lt;br&gt;
源码：&lt;code&gt;~/Desktop/tun_example/phase2/&lt;/code&gt;（仓库名是 &lt;code&gt;tun_example&lt;/code&gt;，但 Go module 是 &lt;code&gt;github.com/1WesleyYou/mini-vpn-go&lt;/code&gt;）。&lt;/p&gt;
&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>0. 从 Minimax 到 MCTS - 经典博弈树搜索基础</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/26/agentsys/orchestration/0.mcts/</link>
      <pubDate>Tue, 26 May 2026 05:59:28 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/26/agentsys/orchestration/0.mcts/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;博弈树搜索黑称&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;game tree (博弈树): 把所有可能走法画成的有根树, 每个 node 是 state, 每条 edge 是 action&lt;/li&gt;
&lt;li&gt;zero-sum game: 一方 gain = 另一方 loss, 两边目标完全对立&lt;/li&gt;
&lt;li&gt;Minimax: 假设对手最优时自己能保证拿到的最佳 outcome&lt;/li&gt;
&lt;li&gt;Alpha-Beta Pruning: Minimax 的剪枝加速版&lt;/li&gt;
&lt;li&gt;MCTS (Monte Carlo Tree Search): 用随机采样 + 统计估计替代完整树搜索&lt;/li&gt;
&lt;li&gt;UCT (Upper Confidence bounds for Trees): MCTS 的 Selection 阶段公式&lt;/li&gt;
&lt;li&gt;rollout / playout / simulation: 从 leaf 出发 random play 到终局, 拿 1 个 noisy sample&lt;/li&gt;
&lt;li&gt;Markov property: 给定当前 state, 未来跟历史无关 — MCTS / minimax 都依赖这个&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;为什么要写这一篇&#34;&gt;为什么要写这一篇&lt;/h2&gt;
&lt;p&gt;读 LATS (Language Agent Tree Search) 之前必须先理解 MCTS, 而 MCTS 的设计逻辑只有放在 minimax / alpha-beta 的演化脉络里看才看得透; 这篇是为读 ReAct + Reflexion - Reasoning Acting and Verbal Reinforcement Learning 后续补 LATS 段做的前置阅读;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Unix 电源管理</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/25/computer_system_basics/os/7.%20Unix%20%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86/</link>
      <pubDate>Mon, 25 May 2026 00:00:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/25/computer_system_basics/os/7.%20Unix%20%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86/</guid>
      <description>&lt;h2 id=&#34;状态机心智模型&#34;&gt;状态机心智模型&lt;/h2&gt;
&lt;p&gt;任何 sleep / lock / logout / hibernate 操作, 本质都是在调 4 个开关的不同组合; 判断&amp;quot;这个操作干了什么&amp;quot;只要看这 4 件事:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;用户进程还在不在?&lt;/strong&gt; (Chrome, IDE, SSH 连接是否还活着);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CPU 还在不在执行指令?&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RAM 还通不通电?&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;磁盘上有没有内存镜像?&lt;/strong&gt; (用来还原的);&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;对照表-从轻到重&#34;&gt;对照表 (从轻到重)&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;操作&lt;/th&gt;
					&lt;th&gt;用户进程&lt;/th&gt;
					&lt;th&gt;CPU&lt;/th&gt;
					&lt;th&gt;RAM&lt;/th&gt;
					&lt;th&gt;磁盘镜像&lt;/th&gt;
					&lt;th&gt;唤醒/恢复&lt;/th&gt;
					&lt;th&gt;功耗&lt;/th&gt;
					&lt;th&gt;典型场景&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;熄屏 (DPMS)&lt;/td&gt;
					&lt;td&gt;跑&lt;/td&gt;
					&lt;td&gt;跑&lt;/td&gt;
					&lt;td&gt;通电&lt;/td&gt;
					&lt;td&gt;—&lt;/td&gt;
					&lt;td&gt;瞬间 (动鼠标)&lt;/td&gt;
					&lt;td&gt;省 ~10W (只关显示器)&lt;/td&gt;
					&lt;td&gt;短暂离开几分钟&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;锁屏 (lock)&lt;/td&gt;
					&lt;td&gt;跑&lt;/td&gt;
					&lt;td&gt;跑&lt;/td&gt;
					&lt;td&gt;通电&lt;/td&gt;
					&lt;td&gt;—&lt;/td&gt;
					&lt;td&gt;输密码&lt;/td&gt;
					&lt;td&gt;同平时&lt;/td&gt;
					&lt;td&gt;离开座位防别人乱碰&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Suspend (S3 / s2idle)&lt;/td&gt;
					&lt;td&gt;冻结&lt;/td&gt;
					&lt;td&gt;停&lt;/td&gt;
					&lt;td&gt;自刷新通电&lt;/td&gt;
					&lt;td&gt;—&lt;/td&gt;
					&lt;td&gt;1-3s&lt;/td&gt;
					&lt;td&gt;电池 1-3%/小时&lt;/td&gt;
					&lt;td&gt;合盖, 临时离开&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Hibernate (S4)&lt;/td&gt;
					&lt;td&gt;冻结&lt;/td&gt;
					&lt;td&gt;停&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;断电&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;整块写到 swap&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;10-30s&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;过夜, 长时间不用&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Hybrid sleep&lt;/td&gt;
					&lt;td&gt;冻结&lt;/td&gt;
					&lt;td&gt;停&lt;/td&gt;
					&lt;td&gt;通电&lt;/td&gt;
					&lt;td&gt;同时写盘&lt;/td&gt;
					&lt;td&gt;RAM 没掉就秒开, 掉了从盘恢复&lt;/td&gt;
					&lt;td&gt;1-3%/小时 + 一次写入&lt;/td&gt;
					&lt;td&gt;台式机怕断电&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Logout&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;全部杀掉&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;跑&lt;/td&gt;
					&lt;td&gt;通电&lt;/td&gt;
					&lt;td&gt;—&lt;/td&gt;
					&lt;td&gt;重新登录, 所有 app 从头开&lt;/td&gt;
					&lt;td&gt;同平时&lt;/td&gt;
					&lt;td&gt;换用户用机器&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Shutdown (S5)&lt;/td&gt;
					&lt;td&gt;全杀&lt;/td&gt;
					&lt;td&gt;停&lt;/td&gt;
					&lt;td&gt;断电&lt;/td&gt;
					&lt;td&gt;—&lt;/td&gt;
					&lt;td&gt;完整冷启动 30s+&lt;/td&gt;
					&lt;td&gt;0&lt;/td&gt;
					&lt;td&gt;不用了 / 要搬动&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;容易混的几对&#34;&gt;容易混的几对&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Suspend vs Hibernate&lt;/strong&gt; — 同是&amp;quot;睡眠&amp;quot;, 但&lt;strong&gt;断电后果完全不同&lt;/strong&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>MemGPT - Towards LLMs as Operating Systems</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/20/agentsys/memory/MemGPT%20-%20Towards%20LLMs%20as%20Operating%20Systems/</link>
      <pubDate>Wed, 20 May 2026 06:09:26 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/20/agentsys/memory/MemGPT%20-%20Towards%20LLMs%20as%20Operating%20Systems/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;MemGPT 的 OS 类比词典&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;main context: LLM 的 context window, 类比物理 RAM&lt;/li&gt;
&lt;li&gt;external context: 向量库 / 关系库 / 日志, 类比 disk&lt;/li&gt;
&lt;li&gt;function call: 模型主动触发的 I/O, 类比 system call&lt;/li&gt;
&lt;li&gt;queue manager: FIFO 驱逐器, 类比 page replacement policy&lt;/li&gt;
&lt;li&gt;heartbeat: 定时唤醒, 类比 timer interrupt&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;context-window-的硬上限&#34;&gt;Context Window 的硬上限&lt;/h2&gt;
&lt;p&gt;现有商用 LLM 每次 forward 能看到的 token 数是有限的, 比如 GPT-4 turbo 是 128K, Llama-2-chat 是 4K; 一旦 input + output 超出这个窗口, 后续内容要么被截断, 要么只能靠外部检索 (classic RAG) 在推理前硬塞进去;&lt;/p&gt;</description>
    </item>
    <item>
      <title>ZeRO - memory optimizations toward training trillion parameter models</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/ZeRO%20-%20memory%20optimizations%20toward%20training%20trillion%20parameter%20models/</link>
      <pubDate>Wed, 20 May 2026 06:00:30 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/ZeRO%20-%20memory%20optimizations%20toward%20training%20trillion%20parameter%20models/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;并行理论的黑称&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;Vertical Split: 竖切, PP&lt;/li&gt;
&lt;li&gt;Horizontal Split: 横切, TP&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;消耗显存的模块分类&#34;&gt;消耗显存的模块分类&lt;/h2&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Part&lt;/th&gt;
					&lt;th&gt;Category&lt;/th&gt;
					&lt;th&gt;Included Items&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;1&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;Model&lt;/strong&gt; states&lt;/td&gt;
					&lt;td&gt;optimizer states, gradients, parameters&lt;/td&gt;
					&lt;td&gt;For large models, the &lt;strong&gt;majority&lt;/strong&gt; of the memory is occupied by model states.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;2&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;Residual&lt;/strong&gt; states&lt;/td&gt;
					&lt;td&gt;activation, temporary buffers, unusable fragmented memory&lt;/td&gt;
					&lt;td&gt;The &lt;strong&gt;remaining&lt;/strong&gt; memory is consumed by residual states.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;model-state-不足分析--zero-dp-性能&#34;&gt;Model State 不足分析 + ZeRO-DP 性能&lt;/h2&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Parallelism Method&lt;/th&gt;
					&lt;th&gt;Why Compute Efficiency Is High / Low&lt;/th&gt;
					&lt;th&gt;Why Memory Efficiency Is High / Low&lt;/th&gt;
					&lt;th&gt;Core Mechanism&lt;/th&gt;
					&lt;th&gt;Main Problem&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Data Parallelism (DP)&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;High compute efficiency&lt;/strong&gt; because each GPU runs the full model &lt;strong&gt;independently&lt;/strong&gt; on its own mini-batch, so computation is &lt;strong&gt;large-grained and continuous&lt;/strong&gt;, and communication is mainly limited to gradient synchronization.&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;Low memory efficiency&lt;/strong&gt; because each GPU stores a full copy of all model states, including parameters, gradients, and optimizer states.&lt;/td&gt;
					&lt;td&gt;Replicate the full model on every GPU, split data across GPUs, then synchronize gradients.&lt;/td&gt;
					&lt;td&gt;Heavy memory redundancy across GPUs.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Model Parallelism (MP)&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;Low compute efficiency&lt;/strong&gt; because one model computation is split across multiple GPUs, which introduces fine-grained coordination, frequent synchronization, and expensive communication on the critical path.&lt;/td&gt;
					&lt;td&gt;&lt;strong&gt;High memory efficiency&lt;/strong&gt; because each GPU stores only a partition of the model states instead of the full model.&lt;/td&gt;
					&lt;td&gt;Partition the model itself across GPUs so each GPU holds only part of the parameters / states.&lt;/td&gt;
					&lt;td&gt;Communication overhead, synchronization cost, and reduced scalability.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ZeRO-DP&lt;/td&gt;
					&lt;td&gt;Tries to &lt;strong&gt;retain the high compute efficiency of DP&lt;/strong&gt; by preserving DP-style computation granularity and communication pattern as much as possible.&lt;/td&gt;
					&lt;td&gt;Tries to &lt;strong&gt;achieve the high memory efficiency of MP&lt;/strong&gt; by partitioning model states across data-parallel processes instead of fully replicating them.&lt;/td&gt;
					&lt;td&gt;Keep DP-style training flow, but partition optimizer states, gradients, and eventually parameters to remove redundancy.&lt;/td&gt;
					&lt;td&gt;More complex state management and dynamic communication scheduling.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;img alt=&#34;ZeRO_model_state_compression_results.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/ZeRO_model_state_compression_results.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/Taming%20Throughput-Latency%20Tradeoff%20in%20LLM%20Inference%20with%20Sarathi-Serve/</link>
      <pubDate>Wed, 20 May 2026 06:00:23 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/Taming%20Throughput-Latency%20Tradeoff%20in%20LLM%20Inference%20with%20Sarathi-Serve/</guid>
      <description>&lt;p&gt;Sarathi-Serve 把 prefill 分块, 再与正在运行的 decode 请求混合调度, 目标是兼顾吞吐与 token 生成延迟. 这里讨论的是同一 serving 系统中的调度方式, prefill/decode 可以在同一个 batch 中执行. &lt;a href=&#34;https://www.usenix.org/conference/osdi24/presentation/agrawal&#34;&gt;原论文, OSDI 2024&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;prefill-vs-decode&#34;&gt;Prefill vs. Decode&lt;/h2&gt;
&lt;h3 id=&#34;prefill-阶段做了什么&#34;&gt;Prefill 阶段做了什么&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;prefill = 对整个 prompt 做一次完整的 transformer forward.&lt;/strong&gt;&lt;br&gt;
包括了:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;对所有输入 token 一起做 embedding&lt;/li&gt;
&lt;li&gt;过每一层的 attention&lt;/li&gt;
&lt;li&gt;过每一层的 FFN&lt;/li&gt;
&lt;li&gt;同时把每层对应的 K/V 写入 KV cache&lt;/li&gt;
&lt;li&gt;最后根据最后位置的 hidden state 过 lm head, 得到 next-token logits&lt;/li&gt;
&lt;li&gt;采样 / greedy / top-k / top-p, 选出第一个输出 token&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;较长的 prompt 提供了足够多可以一起计算的 token, 能提高矩阵运算的算术强度. 在论文讨论的配置下, prefill 通常表现为 &lt;strong&gt;compute-bound&lt;/strong&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Megatron-LM - Training Multi-Billion Parameter Language Models Using Model Parallelism</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/Megatron-LM%20-%20Training%20Multi-Billion%20Parameter%20Language%20Models%20Using%20Model%20Parallelism/</link>
      <pubDate>Wed, 20 May 2026 05:34:48 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/Megatron-LM%20-%20Training%20Multi-Billion%20Parameter%20Language%20Models%20Using%20Model%20Parallelism/</guid>
      <description>&lt;h2 id=&#34;attention-计算的线性代数问题&#34;&gt;Attention 计算的线性代数问题&lt;/h2&gt;
&lt;h3 id=&#34;attention-和-ffn-的关系&#34;&gt;attention 和 FFN 的关系&lt;/h3&gt;
&lt;p&gt;如果记某层输入为 x, 那么可以粗略理解成:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;attention 输出: 给 x 补充上下文信息, 像&amp;quot;开会听别人说话&amp;quot;&lt;/li&gt;
&lt;li&gt;FFN 输出: 给 x 补充局部计算后的新特征, - 像&amp;quot;你自己在脑子里消化, 归纳, 形成判断&amp;quot;&lt;br&gt;
如果我们尝试&lt;strong&gt;把一个 FFN 层变成一个 attention 层&lt;/strong&gt;, 结果就是可能会更加适合长距离语义传输但是缺少本地语义特征变换器&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;多层-attention-ffn-结构&#34;&gt;多层 attention-FFN 结构&lt;/h3&gt;
&lt;p&gt;可以理解为不断重复&amp;quot;交换信息 $\rightarrow$ 消化信息 $\rightarrow$ 再交换 $\rightarrow$ 再消化&amp;quot;&lt;br&gt;
也就是说各自对本 token 处于上下文的含义理解之后再次进行交换分享，让整体的文意理解更加深刻&lt;/p&gt;</description>
    </item>
    <item>
      <title>GPipe - efficient training of giant neural networks using pipeline parallelism</title>
      <link>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/GPipe%20-%20efficient%20training%20of%20giant%20neural%20networks%20using%20pipeline%20parallelism/</link>
      <pubDate>Wed, 20 May 2026 05:34:29 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/05/20/mlsys/Paper/GPipe%20-%20efficient%20training%20of%20giant%20neural%20networks%20using%20pipeline%20parallelism/</guid>
      <description>&lt;h2 id=&#34;神经网络基础&#34;&gt;神经网络基础&lt;/h2&gt;
&lt;p&gt;&lt;img alt=&#34;nano-MLP&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/nano-MLP.svg&#34;&gt;&lt;br&gt;
如图是一个基础的神经网络结构, 我们这里首先要明确几个函数:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;每一层内部的计算是 $h_i := \sigma(z_i)$, $z_i := W_i h_{i-1} + b_i$&lt;/li&gt;
&lt;li&gt;我们最终的输出函数是 $L :=$loss(sample; forward)&lt;/li&gt;
&lt;li&gt;forward: 指的是从输入样本数据 $h_0$ 到 最终输出 $\sigma(z_2)$ 的所有计算过程&lt;/li&gt;
&lt;li&gt;backward: 从 $L$ 开始不断计算每一层中的 $\frac{\partial L}{\partial W_i}$ 和 $\frac{\partial L}{\partial b_i}$ 的方向梯度, 然后用这个来不断更新 $W_i,\ b_i$&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;现在来拆解一下反向传播的过程: 基本根据的是莱布尼茨链式法则 (chain-rule)&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. Unix ping 与 ICMP 协议</title>
      <link>https://www.whoami-wesleyyou.top/2026/04/25/computer_system_basics/network/6.%20Unix%20ping%20%E4%B8%8E%20ICMP%20%E5%8D%8F%E8%AE%AE/</link>
      <pubDate>Sat, 25 Apr 2026 13:50:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/04/25/computer_system_basics/network/6.%20Unix%20ping%20%E4%B8%8E%20ICMP%20%E5%8D%8F%E8%AE%AE/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;术语别名&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;ICMP: Internet Control Message Protocol, IP 层的&amp;quot;控制/反馈&amp;quot;协议;&lt;/li&gt;
&lt;li&gt;RTT: Round-Trip Time, 一来一回的总时延;&lt;/li&gt;
&lt;li&gt;Echo Request / Echo Reply: ICMP type 8 / type 0, 就是 ping 用到的两种报文;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;icmp-协议与报文&#34;&gt;ICMP 协议与报文&lt;/h2&gt;
&lt;h3 id=&#34;前置-icmp-在协议栈中的位置&#34;&gt;前置: ICMP 在协议栈中的位置&lt;/h3&gt;
&lt;p&gt;ICMP 经常被人当成&amp;quot;网络层之上的小协议&amp;quot;, 但它实际上是 &lt;strong&gt;IP 协议的一个直接附庸&lt;/strong&gt;, 跑在 IP 之上, 但属于 network layer 的控制平面;&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. Docker 网络栈协议</title>
      <link>https://www.whoami-wesleyyou.top/2026/04/24/computer_system_basics/network/5.%20Docker%20%E7%BD%91%E7%BB%9C%E6%A0%88%E5%8D%8F%E8%AE%AE/</link>
      <pubDate>Fri, 24 Apr 2026 16:44:13 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/04/24/computer_system_basics/network/5.%20Docker%20%E7%BD%91%E7%BB%9C%E6%A0%88%E5%8D%8F%E8%AE%AE/</guid>
      <description>&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;术语别名&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;NIC: Network Interface Card, 物理网卡, 真正的硬件;&lt;/li&gt;
&lt;li&gt;net_device: Linux 内核里描述&amp;quot;一张网卡&amp;quot;的统一抽象, 虚拟和物理共用同一个数据结构;&lt;/li&gt;
&lt;li&gt;虚拟网卡: 没有对应物理硬件、纯软件模拟的 net_device, 例如 lo / veth / tap / tun / bridge;&lt;/li&gt;
&lt;li&gt;tap / tun: 给用户态进程收发包用的虚拟网卡, VM 和 VPN 的标配;&lt;/li&gt;
&lt;li&gt;netns: Linux network namespace, 内核提供的网络栈隔离机制;&lt;/li&gt;
&lt;li&gt;veth pair: virtual ethernet pair, 一对虚拟网卡, 一端发, 另一端收, 是连接两个 netns 的通道;&lt;/li&gt;
&lt;li&gt;bridge: 内核虚拟二层交换机, 把若干网卡拉到同一广播域;&lt;/li&gt;
&lt;li&gt;DNAT / SNAT: destination / source NAT, iptables 用来改包的 dst/src IP, 是端口映射和&amp;quot;出口走主机 IP&amp;quot;的核心;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;h2 id=&#34;linux-网络设备与隔离基础&#34;&gt;Linux 网络设备与隔离基础&lt;/h2&gt;
&lt;h3 id=&#34;前置-a-物理网卡-nic-与虚拟网卡到底是什么&#34;&gt;前置 A: 物理网卡 (NIC) 与虚拟网卡到底是什么&lt;/h3&gt;
&lt;p&gt;聊 Docker 网络之前必须先把&amp;quot;网卡&amp;quot;这个词拆开, 否则后面 veth, tap, bridge 这些会一片混乱;&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. Distributed Data Parallel</title>
      <link>https://www.whoami-wesleyyou.top/2026/03/19/mlsys/1.%20Distributed%20Data%20Parallel/</link>
      <pubDate>Thu, 19 Mar 2026 12:45:37 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/03/19/mlsys/1.%20Distributed%20Data%20Parallel/</guid>
      <description>&lt;h2 id=&#34;ddp-是什么&#34;&gt;DDP 是什么&lt;/h2&gt;
&lt;p&gt;DDP(Distributed Data Parallel)是 &lt;a href=&#34;https://docs.pytorch.org/tutorials/intermediate/ddp_tutorial.html&#34;&gt;PyTorch 官方提供的分布式数据并行训练机制&lt;/a&gt;;&lt;/p&gt;
&lt;p&gt;它的核心思想是:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;让多个训练进程各自持有同一个模型的副本, 分别处理不同的数据子集, 并在反向传播阶段自动同步梯度, 从而保持所有模型副本的一致更新;&lt;/p&gt;
&lt;/blockquote&gt;&lt;h2 id=&#34;ddp-要解决什么问题&#34;&gt;DDP 要解决什么问题&lt;/h2&gt;
&lt;p&gt;深度学习训练通常面临两个核心限制:&lt;/p&gt;</description>
    </item>
    <item>
      <title>0. 基本 GPU 架构</title>
      <link>https://www.whoami-wesleyyou.top/2026/01/14/mlsys/0.%20%E5%9F%BA%E6%9C%AC%20GPU%20%E6%9E%B6%E6%9E%84/</link>
      <pubDate>Wed, 14 Jan 2026 13:52:09 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2026/01/14/mlsys/0.%20%E5%9F%BA%E6%9C%AC%20GPU%20%E6%9E%B6%E6%9E%84/</guid>
      <description>&lt;h2 id=&#34;data-level-parallelism-dlp&#34;&gt;Data-Level Parallelism (DLP)&lt;/h2&gt;
&lt;p&gt;在前面的工作中我们主要学习的 并行架构 就是 pipelining&lt;br&gt;
简单的做法就是并行使用多个 核 core 或者使用多个硬件结构实现并行, 但是这里要讨论的是 数据层面的并行&lt;br&gt;
在固有的处理器中, 我们计算如下公式&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;++&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;n&#34;&gt;z&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;很显然这一步可以用矩阵和向量等式进行优化&lt;br&gt;
即表达式 $\vec z = A\cdot \vec x + \vec y$&lt;br&gt;
那么接下来的问题就是如何用硬件快速计算向量&lt;/p&gt;</description>
    </item>
    <item>
      <title>10. Tradeoffs btw</title>
      <link>https://www.whoami-wesleyyou.top/2025/12/14/computer_system_basics/ds/10.tradeoff/</link>
      <pubDate>Sun, 14 Dec 2025 17:02:26 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/12/14/computer_system_basics/ds/10.tradeoff/</guid>
      <description>&lt;h2 id=&#34;平衡的背景&#34;&gt;平衡的背景&lt;/h2&gt;
&lt;p&gt;利用冗余(replicas)来降低尾延迟(tail latency), 以及它和 Paxos 共识, load / sharding 之间的关系;&lt;br&gt;
核心是: 复制本来是为了容错/可用性, 但你也可以把它当成&amp;quot;多条独立路径/多台机器&amp;quot;的并行机会, 用来对抗偶发慢请求;&lt;/p&gt;</description>
    </item>
    <item>
      <title>8. Sharding, Facebook and Implementation</title>
      <link>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/8.sharding/</link>
      <pubDate>Sat, 13 Dec 2025 20:25:03 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/8.sharding/</guid>
      <description>&lt;h2 id=&#34;分片-sharding&#34;&gt;分片 (Sharding)&lt;/h2&gt;
&lt;p&gt;分片是分布式系统设计中的一个关键概念, 它与复制(Replication)一起, 构成了构建大规模系统的基础;&lt;/p&gt;
&lt;h3 id=&#34;分片的本质与目标&#34;&gt;分片的本质与目标&lt;/h3&gt;
&lt;p&gt;分片的本质在于解决单一机器的&lt;strong&gt;限制&lt;/strong&gt;和&lt;strong&gt;不可靠性&lt;/strong&gt;问题,;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;复制(Replication)&lt;/strong&gt;: 通过复制数据来使机器&lt;strong&gt;可靠(reliable)&lt;/strong&gt;, 提高容错性;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;分片(Sharding)&lt;/strong&gt;: 通过分割数据来提高机器的容量限制 (raise the machine&amp;rsquo;s limits);
&lt;ul&gt;
&lt;li&gt;分片适用于任何存储系统, 通常是通过将 &lt;strong&gt;键空间(key space)&lt;/strong&gt; 分割到多个复制对(例如主/备份对)来实现;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;facebook-架构中的分片应用&#34;&gt;Facebook 架构中的分片应用&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;复制存储&lt;/strong&gt;: 数据库在所有数据中心之间进行&lt;strong&gt;复制(replicated)&lt;/strong&gt;, 可以想象每个数据中心都包含一份完整的数据拷贝,;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;数据库分割&lt;/strong&gt;: 数据库被分割成多个&lt;strong&gt;分片(shards)&lt;/strong&gt;, 每个数据元素都属于一个特定的分片,;&lt;br&gt;
    - &lt;strong&gt;领导者/跟随者&lt;/strong&gt;: 每个分片都有一个数据中心作为其&lt;strong&gt;领导者(leader)&lt;/strong&gt;, 其余的中心是&lt;strong&gt;跟随者(followers)&lt;/strong&gt;;&lt;br&gt;
    - &lt;strong&gt;数量&lt;/strong&gt;: 分片的数量通常&lt;strong&gt;远多于(many more)&lt;strong&gt;数据中心的数量;&lt;br&gt;
    - &lt;strong&gt;负载均衡&lt;/strong&gt;: 分片被分配到不同的数据中心以实现&lt;/strong&gt;负载均衡(load balance)&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;写入和排序&lt;/strong&gt;:&lt;br&gt;
    - 对某一元素的更新操作总是发送给该元素所在分片的&lt;strong&gt;领导者(shard leader)&lt;/strong&gt;;&lt;br&gt;
    - 分片领导者负责提供&lt;strong&gt;写入的排序(write ordering) 和 序列化(serialized)&lt;/strong&gt;;&lt;br&gt;
    - &lt;strong&gt;sync&lt;/strong&gt;: &lt;strong&gt;写入&lt;/strong&gt; 领导者的操作是&lt;strong&gt;同步(synchronous)&lt;/strong&gt; 的, 当写入返回时, 对象就被持久存储了;&lt;br&gt;
    - &lt;strong&gt;async&lt;/strong&gt;: 领导者会将更新发送给跟随者, 但这是 &lt;strong&gt;异步(asynchronously)&lt;/strong&gt; 进行的;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;这种分片和异步复制的结合, 使得 Facebook 能够实现低延迟的写入, 但同时也意味着其他数据中心(跟随者)可能会看到&lt;strong&gt;旧值(old values)&lt;/strong&gt;, 这 &lt;strong&gt;不具备线性一致性&lt;/strong&gt;;&lt;/p&gt;</description>
    </item>
    <item>
      <title>7. Eventual Consistency</title>
      <link>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/7.eventual_consistency/</link>
      <pubDate>Sat, 13 Dec 2025 17:00:03 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/7.eventual_consistency/</guid>
      <description>&lt;h2 id=&#34;简单介绍&#34;&gt;简单介绍&lt;/h2&gt;
&lt;p&gt;最终一致性位于一致性谱系的末端, 比线性一致性(Linearizability), 顺序一致性和因果一致性都要弱;&lt;br&gt;
如果对某一数据项不再有新的更新写入, 那么在经过一段时间后, 所有未来的读取操作都将反映最新的写入结果&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;没有时间限制&lt;/strong&gt;: 系统对收敛到一致状态所需的时间没有界限,;这个时间长短取决于通信模式的可用性(例如, 如果节点长期不通信, 收敛时间就会很长);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;保证最终顺序&lt;/strong&gt;: EC 仍然要求更新最终以相同的顺序应用到所有副本上,;这通常是通过逻辑时钟等机制来实现的, 允许更新先作为临时更新本地应用, 然后在同步时根据逻辑时间戳进行回滚和重放,;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;bayou-模型-sosp-1995&#34;&gt;Bayou 模型 (SOSP 1995)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;没有中心化存储: 所有的节点都被视为客户端,;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;始终接受更新&lt;/strong&gt;: 客户端总是接受用户发出的更新操作, 这保证了高可用性和活性;&lt;/li&gt;
&lt;li&gt;日志记录: 所有更新都会被记录在本地日志中;&lt;/li&gt;
&lt;li&gt;点对点同步: 客户端之间会定期进行 &lt;strong&gt;成对(pair-wise)&lt;/strong&gt; 的更新交换;&lt;/li&gt;
&lt;li&gt;临时更新: 更新通常是暂时的(tentative), 可以解决它们之间的冲突;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;举例说明最终一致性&#34;&gt;举例说明最终一致性&lt;/h3&gt;
&lt;p&gt;假设有一个房间日程安排应用程序(Room scheduler app running on smartphones)&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. 从 FLP 不可能到 CAP 和 PACELC</title>
      <link>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/6.cap/</link>
      <pubDate>Sat, 13 Dec 2025 16:12:15 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/12/13/computer_system_basics/ds/6.cap/</guid>
      <description>&lt;h2 id=&#34;分布式系统的不稳定性&#34;&gt;分布式系统的不稳定性&lt;/h2&gt;
&lt;p&gt;综合我们前几个章节的内容, 我们可以总结出分布式系统中的不稳定性主要源于以下几个方面:&lt;/p&gt;
&lt;h3 id=&#34;故障模型-failure-model&#34;&gt;故障模型 (Failure Model)&lt;/h3&gt;
&lt;p&gt;在这个模型中, 对节点和网络特性的定义如下:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;节点(Nodes):
&lt;ul&gt;
&lt;li&gt;它们可以无限期地失败;&lt;/li&gt;
&lt;li&gt;它们在恢复时不会丢失持久状态;&lt;/li&gt;
&lt;li&gt;对任何特定的计算, 它们都没有时间限制;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;网络(Network):
&lt;ul&gt;
&lt;li&gt;网络可以丢弃 &lt;strong&gt;drop&lt;/strong&gt; 或延迟 &lt;strong&gt;latency&lt;/strong&gt; 消息;&lt;/li&gt;
&lt;li&gt;消息可能被无限期地延迟;&lt;/li&gt;
&lt;li&gt;网络也可能对消息进行重新排序;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;异步模型-asynchronous-model&#34;&gt;异步模型 (Asynchronous Model)&lt;/h3&gt;
&lt;p&gt;上述的故障模型被称为异步模型; 在该模型下, 核心挑战在于:&lt;/p&gt;</description>
    </item>
    <item>
      <title>9. 分布式事务系统与 Spanner</title>
      <link>https://www.whoami-wesleyyou.top/2025/11/28/computer_system_basics/ds/9.spanner/</link>
      <pubDate>Fri, 28 Nov 2025 20:55:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/11/28/computer_system_basics/ds/9.spanner/</guid>
      <description>&lt;h2 id=&#34;分布式事务系统-distributed-transaction&#34;&gt;分布式事务系统 Distributed Transaction&lt;/h2&gt;
&lt;p&gt;根据分布式数据库系统的类似要求, 我们设计的分布式系统要支持 &lt;strong&gt;ACID&lt;/strong&gt; 准则:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Atomicity (原子性)&lt;/strong&gt;: 事务要么全部完成, 要么全部不做;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency (一致性)&lt;/strong&gt;: 事务执行前后, 数据库必须处于一致状态;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolation (隔离性)&lt;/strong&gt;: 并发执行的事务彼此隔离, 互不干扰;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability (持久性)&lt;/strong&gt;: 一旦事务提交, 其结果是永久性的, 即使系统崩溃也不会丢失;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;如何区分-linearizability-和-serializability&#34;&gt;如何区分 Linearizability 和 Serializability?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Linearizability (线性一致性)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;每个操作看起来像是瞬间发生的, 并且所有的 read 都会反映已经发生的所有 write 的结果&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Serializability (可串行化)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;并发执行的事务的结果与某个串行执行的顺序相同&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strict Serializability&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;结合了线性一致性和可串行化的概念&lt;/li&gt;
&lt;li&gt;也就是外界看到的顺序和实际执行的顺序是一致的&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;isolation-问题与二相锁-2pl&#34;&gt;Isolation 问题与二相锁 (2PL)&lt;/h3&gt;
&lt;p&gt;一个常见的 isolation 冲突问题: 两个 client 处理线程同时尝试修改一个 entry, 可能会互相影响, 在传统 OS 思路上, 应该用 &lt;code&gt;mutex&lt;/code&gt; 来保护这个 entry; 但是这个和我们的 OS 设计有很大不同:&lt;br&gt;
回忆 482 p4 的文件系统中锁的使用: 用了读写锁来保护每个 block, 并不需要担心太多, 这是因为我们的文件系统实际上是一个 tree 结构, 而 tree 其天然就是一个 acyclic graph 结构, 也就是有向无环图, 所以其不容易产生死锁; 而如果一个数据库系统中, tuple 本身的存放并不符合一个 tree 结构, 那么就很容易产生死锁问题; 所以在分布式存储系统中, 为了解决这个 &amp;ldquo;&lt;strong&gt;无序上锁导致死锁&lt;/strong&gt;&amp;rdquo; 的问题, 工程界引入了 &lt;strong&gt;二相锁 (Two-Phase Locking, 2PL)&lt;/strong&gt; 的概念:&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. Transaction and ACID DB</title>
      <link>https://www.whoami-wesleyyou.top/2025/11/28/computer_system_basics/db/5.transaction/</link>
      <pubDate>Fri, 28 Nov 2025 16:50:38 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/11/28/computer_system_basics/db/5.transaction/</guid>
      <description>&lt;h2 id=&#34;acid-准则&#34;&gt;ACID 准则&lt;/h2&gt;
&lt;p&gt;在讨论支持并发的文件系统 (包括 482 p4 NFS, DBMS 等) 的时候, 我们往往会提到一个非常核心的准则: &lt;strong&gt;ACID 准则&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Atomicity (原子性)&lt;/strong&gt;: 事务是一个不可分割的工作单位, 要么全部完成, 要么全部不做;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency (一致性)&lt;/strong&gt;: 事务的执行必须使数据库从一个一致性状态转变到另一个一致性状态;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolation (隔离性)&lt;/strong&gt;: 并发执行的事务彼此之间是隔离的, 一个事务的中间状态对其他事务不可见;
&lt;ul&gt;
&lt;li&gt;两个事务并发的时候不能互相冲突&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability (持久性)&lt;/strong&gt;: 一旦事务提交, 它对数据库的修改就是永久性的, 即使系统崩溃也不会丢失.
&lt;ul&gt;
&lt;li&gt;更多是从 recovery 恢复角度来讲的, 也就是尽量能在任何崩溃情况下都不丢数据;具体看 [Logging](#Log 日志结构) 章节和 &lt;a href=&#34;&#34;&gt;Recovery&lt;/a&gt; 章节&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;并发控制的数据库系统&#34;&gt;并发控制的数据库系统&lt;/h2&gt;
&lt;h3 id=&#34;并发控制与隔离性的基础&#34;&gt;并发控制与隔离性的基础&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;事务 (Transaction)&lt;/strong&gt;:  事务是 DBMS 中变化的基本单位;它是在数据库上执行的一系列操作(如 SQL 查询), 以完成某种高级功能;
&lt;ul&gt;
&lt;li&gt;事务的抽象视图是读取和写入操作序列(例如 R(A),W(B),&amp;hellip;);&lt;/li&gt;
&lt;li&gt;事务始于 &lt;code&gt;BEGIN&lt;/code&gt; 命令, 止于 &lt;code&gt;COMMIT&lt;/code&gt;(保存所有更改)或 &lt;code&gt;ABORT&lt;/code&gt;(撤销所有更改, 如同从未执行过);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;并发的动机:  允许独立事务并发执行是一种(潜在地)更好的方法;
&lt;ul&gt;
&lt;li&gt;目标是为了减少用户的响应时间和提高资源利用率/吞吐量;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;隔离性 (Isolation):  是 ACID 属性之一, 要求事务的执行必须表现得像是单独运行一样(&amp;ldquo;as if alone&amp;rdquo;);
&lt;ul&gt;
&lt;li&gt;DBMS 通过交错事务的动作(对数据库对象的读/写)来实现并发;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;并发的挑战:  操作的任意交错可能导致永久不一致性(这是不好的);&lt;br&gt;
II. 调度的形式化与正确性标准&lt;/li&gt;
&lt;li&gt;调度 (Schedule) 的正确性标准:  判断调度的正确性在于它是否等价于某种串行执行;&lt;/li&gt;
&lt;li&gt;串行调度 (Serial Schedule):  不交错不同事务动作的调度;&lt;/li&gt;
&lt;li&gt;等价调度 (Equivalent Schedules):  对于任何数据库状态, 执行第一个调度的效果与执行第二个调度的效果是相同的;&lt;/li&gt;
&lt;li&gt;可串行化调度 (Serializable Schedule):  等价于某些串行执行的调度;
&lt;ul&gt;
&lt;li&gt;如果每个事务都保持一致性, 则每个可串行化调度也保持一致性;&lt;/li&gt;
&lt;li&gt;可串行化提供了 DBMS 在调度操作时额外的灵活性, 而更大的灵活性意味着更好的并行性;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;并发控制协议:  这是 DBMS 决定来自多个事务的操作的正确交错方式的机制;
&lt;ul&gt;
&lt;li&gt;协议分为悲观 (Pessimistic)(事先防止问题)和乐观 (Optimistic)(假设冲突罕见, 事后处理)两类;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;冲突与冲突可串行化-conflict-serializable&#34;&gt;冲突与冲突可串行化 Conflict Serializable&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;冲突操作 (Conflicting Operations):  实现高效等价性的形式化概念依赖于&amp;quot;冲突&amp;quot;操作;
&lt;ul&gt;
&lt;li&gt;两个操作冲突必须满足三个条件: 它们来自不同的事务; 它们作用于同一个对象; 并且其中至少有一个是写入操作;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;交错执行异常 (Interleaved Execution Anomalies):
&lt;ul&gt;
&lt;li&gt;读-写冲突 (R-W Conflicts):  例如, 不可重复读 (Unrepeatable Reads);&lt;/li&gt;
&lt;li&gt;写-读冲突 (W-R Conflicts):  例如, 读取未提交数据(&amp;ldquo;脏读&amp;rdquo;, Dirty Reads);&lt;/li&gt;
&lt;li&gt;写-写冲突 (W-W Conflicts):  例如, 覆盖未提交数据 (Overwriting Uncommitted Data);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;冲突等价 (Conflict Equivalent):  两个调度冲突等价, 当且仅当它们涉及相同事务的相同动作, 并且每对冲突动作的排序方式相同;&lt;/li&gt;
&lt;li&gt;冲突可串行化 (Conflict Serializability):  调度 S 如果与某个串行调度冲突等价, 则 S 是冲突可串行化的;
&lt;ul&gt;
&lt;li&gt;直观上, 如果可以通过交换不冲突的连续操作将调度 S 转换为串行调度, 则 S 是冲突可串行化的;&lt;/li&gt;
&lt;li&gt;大多数 DBMS 尝试支持冲突可串行化;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;依赖图与视图可串行化-precedence-graph&#34;&gt;依赖图与视图可串行化 Precedence Graph&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;前驱图 (Precedence Graph):  用于快速判断冲突可串行化的算法;
&lt;ul&gt;
&lt;li&gt;图中的每个事务是一个节点;&lt;/li&gt;
&lt;li&gt;判定规则:  一个调度是冲突可串行化的, 当且仅当它的依赖图是无环的 (acyclic);图中的环揭示了问题;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;视图可串行化 (View Serializability):  可串行化的另一种(较弱的)概念;
&lt;ul&gt;
&lt;li&gt;视图等价 (View Equivalent):  需满足三个条件: 1. 事务读取的初始值保持不变; 2. 事务读取的由另一个事务写入的值保持不变; 3. 事务写入的最终值保持不变;&lt;/li&gt;
&lt;li&gt;视图可串行化允许比冲突可串行化略多的调度, 包括&amp;quot;盲写 (blind writes)&amp;quot;;&lt;/li&gt;
&lt;li&gt;实践限制:  视图可串行化难以高效地强制执行;来源指出, 没有 DBMS 可以支持视图可串行化;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;二相锁-2-phase-locking-2pl&#34;&gt;二相锁 2 Phase Locking (2PL)&lt;/h2&gt;
&lt;h2 id=&#34;log-日志结构&#34;&gt;Log 日志结构&lt;/h2&gt;
&lt;h2 id=&#34;恢复-recovery&#34;&gt;恢复 Recovery&lt;/h2&gt;
&lt;h3 id=&#34;non-fuzzy-checkpointing&#34;&gt;Non-Fuzzy Checkpointing&lt;/h3&gt;
&lt;p&gt;也就是最基本的 checkpointing 机制, 其步骤如下:&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. Database Storage Structure</title>
      <link>https://www.whoami-wesleyyou.top/2025/11/06/computer_system_basics/db/4.storage/</link>
      <pubDate>Thu, 06 Nov 2025 20:46:22 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/11/06/computer_system_basics/db/4.storage/</guid>
      <description>&lt;h2 id=&#34;database-storage&#34;&gt;Database Storage&lt;/h2&gt;
&lt;h3 id=&#34;disk-based-architecture磁盘架构&#34;&gt;Disk-Based Architecture(磁盘架构)&lt;/h3&gt;
&lt;p&gt;DBMS 假定数据库的主存储位置在非易失性磁盘 (Disk / SSD);&lt;br&gt;
系统组件负责在 volatile memory(主存) 与 non-volatile storage(磁盘) 之间移动数据;&lt;/p&gt;
&lt;h4 id=&#34;storage-hierarchy存储层次&#34;&gt;Storage Hierarchy(存储层次)&lt;/h4&gt;
&lt;p&gt;CPU Registers &amp;lt; CPU Cache &amp;lt; DRAM &amp;lt; SSD &amp;lt; HDD &amp;lt; Network Storage&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. Consensus: Paxos Made Simple (not to me)</title>
      <link>https://www.whoami-wesleyyou.top/2025/10/16/computer_system_basics/ds/5.paxos/</link>
      <pubDate>Thu, 16 Oct 2025 19:22:07 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/10/16/computer_system_basics/ds/5.paxos/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;上回书我们说到, PB 复制存储的设计对比 Replicated State Machine (RSM) 有 Fault Tolerant 方向的极大优点, 也就是 RSM 在某个节点卡住的时候会导致整个系统卡顿, 因为 RSM 利用了 Lamport Clock 逻辑顺序的 握手机制来达到实际上的全局一致顺序, 如果局部卡死我们这里的握手就无法达成, 逻辑链就断掉了&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. Primary-Backup Storage System Design and Implementation (PBSSDI)</title>
      <link>https://www.whoami-wesleyyou.top/2025/10/13/computer_system_basics/ds/4.lexical_pb_vs/</link>
      <pubDate>Mon, 13 Oct 2025 11:05:15 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/10/13/computer_system_basics/ds/4.lexical_pb_vs/</guid>
      <description>&lt;p&gt;本文是针对 UMich EECS491 (这课&lt;del&gt;抄了&lt;/del&gt;致敬 MIT CS 6.824) 的 project2 的设计思路和实现的总结, 也可以作为一般的 primary-backup 1-fault-tolerant distributed storage system 的设计参考.&lt;/p&gt;
&lt;p&gt;本文不会涉及具体的实现细节, 只会涉及一些 high-level 的设计思路 &lt;del&gt;如果有 JI/GC 同学当了 IA/GSI 希望不要举报我&lt;/del&gt;&lt;/p&gt;
&lt;h2 id=&#34;lexical-confinement-串行逻辑链&#34;&gt;Lexical Confinement: 串行逻辑链&lt;/h2&gt;
&lt;p&gt;在分布式系统的高并发请求中并不会完全像我们在单机操作系统中看到的 performance&lt;br&gt;
是最重要的, 在分布式系统中 consistency 才是最重要的, 为了避免各种不同步的分布式&lt;br&gt;
failure 导致的不一致问题以及编码实现的复杂性, 我们可以通过串行化的方式来简化&lt;/p&gt;</description>
    </item>
    <item>
      <title>21. The Design and Implementation of a Log-Structured File System</title>
      <link>https://www.whoami-wesleyyou.top/2025/10/06/computer_system_basics/os/historical/21.lfs/</link>
      <pubDate>Mon, 06 Oct 2025 13:07:17 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/10/06/computer_system_basics/os/historical/21.lfs/</guid>
      <description>&lt;h2 id=&#34;design-for-file-systems-of-the-1990s&#34;&gt;Design for File Systems of the 1990&amp;rsquo;s&lt;/h2&gt;
&lt;p&gt;文件系统的设计受到两种力量驱动:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;技术 (Technology)&lt;/strong&gt;: 提供基本的硬件能力与性能边界;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;工作负载 (Workload)&lt;/strong&gt;: 决定系统需要高效完成的操作类型;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;本节总结了 1990 年代的技术变迁及其对文件系统设计的影响, 并说明为何当时的传统文件系统难以适应这些变化, 从而引出了 &lt;strong&gt;Sprite LFS(Log-Structured File System)&lt;/strong&gt; 的设计动机;&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. Normalization</title>
      <link>https://www.whoami-wesleyyou.top/2025/10/02/computer_system_basics/db/3.normalization/</link>
      <pubDate>Thu, 02 Oct 2025 21:43:37 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/10/02/computer_system_basics/db/3.normalization/</guid>
      <description>&lt;h2 id=&#34;为什么需要规范化&#34;&gt;为什么需要规范化&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;坏表的典型问题
&lt;ul&gt;
&lt;li&gt;冗余 redundancy: 比如 供应商地址, 商品描述被重复存储&lt;/li&gt;
&lt;li&gt;插入异常: 插入供应商必须附带商品信息, 关联不大的两个信息要一起插入&lt;/li&gt;
&lt;li&gt;删除异常: 删除商品时可能导致供应商信息丢失&lt;/li&gt;
&lt;li&gt;更新异常: 修改供应商地址需要更新多行&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Normalization 目标&lt;/strong&gt;: 避免冗余, 找到不同属性之间的依赖性和继承关系&lt;/p&gt;</description>
    </item>
    <item>
      <title>20. Lottery Scheduling: Flexible Proportional-Share Resource Management</title>
      <link>https://www.whoami-wesleyyou.top/2025/10/01/computer_system_basics/os/historical/20.lottery_scheduling/</link>
      <pubDate>Wed, 01 Oct 2025 20:38:57 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/10/01/computer_system_basics/os/historical/20.lottery_scheduling/</guid>
      <description>&lt;h2 id=&#34;lottery-scheduling-基本机制&#34;&gt;Lottery Scheduling 基本机制&lt;/h2&gt;
&lt;h3 id=&#34;resource-rights-资源权利&#34;&gt;Resource Rights (资源权利)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;彩票 (ticket)&lt;/strong&gt; 表示资源权利, 具有 &lt;strong&gt;三个性质&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;抽象 (abstract): 与具体机器细节无关;&lt;/li&gt;
&lt;li&gt;相对 (relative): 票所代表的份额随竞争情况 (总彩票数量) 动态变化;&lt;/li&gt;
&lt;li&gt;统一 (uniform): 异构资源都能抽象为 tickets; 比如各种 CPU, I/O 设备;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;lotteries-抽签调度&#34;&gt;Lotteries (抽签调度)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;每次调度就是一次抽签, 任务的获胜概率: $p = \frac{t}{T}$, 其中 t = 本任务票数, T = 总票数;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;获胜次数服从 &lt;strong&gt;binomial distribution&lt;/strong&gt;; 等待第一次获胜的时间服从 &lt;strong&gt;geometric distribution&lt;/strong&gt;;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;长期看, 任务的资源份额 $\approx$ 票份额; 因此保证概率公平 (probabilistic fairness);&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;任何持有 &lt;strong&gt;非零&lt;/strong&gt; 票数的任务都会在有限时间内赢得抽签, 因此不会出现饿死 (starvation);&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;问题: 如果一个任务的彩票数量很少, 为什么不会 starvation? 它被运行的概率不是应该很低吗?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;回答: 只要任务持有的票数大于零, 它在每次抽签中都有非零的获胜概率;虽然概率可能很小, 但等待时间服从几何分布, 期望为 1/p, 是有限的;因此平均响应时间有限, 任务最终一定会运行, 不会像传统优先级调度中那样被永久饿死;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>19. Scheduler Activations: Effective Kernel Support  for the User-Level Management of Parallelism</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/30/computer_system_basics/os/historical/19.scheduler_activation/</link>
      <pubDate>Tue, 30 Sep 2025 21:23:07 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/30/computer_system_basics/os/historical/19.scheduler_activation/</guid>
      <description>&lt;h2 id=&#34;背景&#34;&gt;背景&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;并行计算的效果, 取决于创建和管理并行的开销; 开销大的话即使 coarse grained parallelism 也不划算; 开销小的话, 即使 fine grained parallelism 也划算;&lt;/li&gt;
&lt;li&gt;传统 UNIX 进程 = 单地址空间 + 单执行流;&lt;/li&gt;
&lt;li&gt;设计目标是单核多道程序环境(multiprogramming), 适合粗粒度并行, 不适合细粒度并行;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;线程支持的两种方式&#34;&gt;线程支持的两种方式&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;用户级线程 (User-level threads)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;通过 runtime library 库实现(不改内核);&lt;/li&gt;
&lt;li&gt;优点:
&lt;ul&gt;
&lt;li&gt;性能好: 上下文切换, 创建销毁的代价接近过程调用;&lt;/li&gt;
&lt;li&gt;灵活: 可以按语言/应用需求定制;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;缺点:
&lt;ul&gt;
&lt;li&gt;内核对线程不可见, 仍然只认识&amp;quot;进程&amp;quot;;&lt;/li&gt;
&lt;li&gt;进程就像虚拟 CPU, 被内核调度到物理 CPU 上;&lt;/li&gt;
&lt;li&gt;遇到 I/O 阻塞, 页面缺页, 多道并发 时, 线程库感知不到真实 CPU 情况, 导致性能下降甚至错误;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;内核级线程 (Kernel threads)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;内核直接提供多线程支持, 每个线程对内核可见, 内核负责调度;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;优点:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;与系统资源和调度机制直接集成, 没有&amp;quot;virtual/real processor 错位&amp;quot;的问题;&lt;/li&gt;
&lt;li&gt;不会出现用户级线程那种 &amp;ldquo;一挂全挂&amp;rdquo;(比如一个线程阻塞整个进程);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;缺点:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;内核操作比用户空间 heavyweight 得多;&lt;/li&gt;
&lt;li&gt;性能明显比用户级线程差 (通常差一个数量级);&lt;/li&gt;
&lt;li&gt;对于很多并行程序仍然&amp;quot;太重&amp;quot;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ULT 库会在程序启动时调用内核 API(比如现代系统里 pthread_create())来创建一批内核线程;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;数量一般与物理 CPU 数接近, 用来&amp;quot;占位&amp;quot;, 相当于&amp;quot;虚拟 CPU 池&amp;quot;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ULT 线程 &lt;strong&gt;绑定&lt;/strong&gt; 在这些 KLT 上运行&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;每个内核线程里跑的是用户线程库的调度循环;&lt;/li&gt;
&lt;li&gt;库自己决定哪个用户线程在这个内核线程里执行;&lt;/li&gt;
&lt;li&gt;所以用户线程确实是基于内核线程执行的;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Memory Resource Management in VMware ESX Server</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/29/computer_system_basics/os/historical/18.vmware_esx_mem/</link>
      <pubDate>Mon, 29 Sep 2025 13:19:27 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/29/computer_system_basics/os/historical/18.vmware_esx_mem/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;VMware ESX Server is a thin software layer designed to multiplex hardware resources efficiently among virtual machines. The current system virtualizes the Intel IA-32 architecture&lt;/p&gt;
&lt;p&gt;In contrast, ESX Server manages system hardware directly, providing significantly higher I/O performance and complete control over resource management.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;machine addr: real hardware address&lt;/li&gt;
&lt;li&gt;physical addr: guest OS&amp;rsquo;s address&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pmap&lt;/code&gt;: data structure for each VM that maps physical addr to machine addr (ppn -&amp;gt; mpn)
&lt;ul&gt;
&lt;li&gt;注意这就是 EPT 的功能, 只是 2002 年 Intel 还没有 EPT 技术&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;reclamation-mechanisms&#34;&gt;Reclamation Mechanisms&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;每个虚拟机都会有一个 constant max size (Virtual Mem), 也就是一旦启动之后就不会变了&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;overcommit-过量使用后收回页替换机制&#34;&gt;Overcommit: 过量使用后收回页替换机制&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;如果出现 ESX 宿主机承诺了过量的内存页使用量, 就会出现问题: 如何回收? 如果使用基于 pmap 的额外页表机制, 就还要改一下接口, 也就是撤回的页必须以 (VM, Vaddr) 这样的 tuple 形式才能让 ESX 实现页的撤回, 也就是 &lt;strong&gt;Meta-level Page Replacement&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;但是 ESX/VMM 层并不能知道哪个页更适合 evict, 这只有 guest OS 才知道&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Double Paging Problem&lt;/strong&gt;: 这样设计也会导致 double paging 的问题, VMM 撤回了某个特定的 (VM, page), 但是该 VM 在同时也在对应 page 写入了新的内容, 这样就会出现 inconsistency&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;balloon-机制&#34;&gt;Balloon 机制&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&#34;esx_balloon.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/esx_balloon.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>3.PB-Replication &amp; Linearizability</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/25/computer_system_basics/ds/3.PB-Replication%20&amp;%20Linearizability/</link>
      <pubDate>Thu, 25 Sep 2025 21:20:55 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/25/computer_system_basics/ds/3.PB-Replication%20&amp;%20Linearizability/</guid>
      <description>&lt;h2 id=&#34;visibility-可见性&#34;&gt;Visibility 可见性&lt;/h2&gt;
&lt;p&gt;这是分布式设计的一个核心概念, 也就是只有让用户看到的结果才是重要的, 无所谓系统内部在某一个时刻某一个进程/node 的状态是什么样的&lt;/p&gt;
&lt;p&gt;这篇笔记在讨论主备复制的情况的时候, 我们的目标是在拥有 2 台主机(不一定都可用)的单位分布式系统中维持 one fault-tolerant, 也就是说允许一个节点失败, 但是系统整体不宕机&lt;/p&gt;</description>
    </item>
    <item>
      <title>My VM is Lighter (and Safer) than your Container</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/23/computer_system_basics/os/historical/15.vm_lighter_than_container/</link>
      <pubDate>Tue, 23 Sep 2025 19:03:49 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/23/computer_system_basics/os/historical/15.vm_lighter_than_container/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;背景&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;容器(Docker/LXC)在工业界广泛应用: Google, AWS, Azure, GCP 都依赖容器;&lt;/li&gt;
&lt;li&gt;容器优势:
&lt;ul&gt;
&lt;li&gt;快速实例化(毫秒~百毫秒)&lt;/li&gt;
&lt;li&gt;高密度运行(单机可数千~上万实例)&lt;/li&gt;
&lt;li&gt;内存占用小, 镜像体积小&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;问题&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;安全性不足:
&lt;ul&gt;
&lt;li&gt;容器暴露 &lt;strong&gt;400+ syscalls&lt;/strong&gt;, 内核攻击面巨大;&lt;/li&gt;
&lt;li&gt;隔离性不如 VM, 常需要&amp;quot;容器运行在 VM 内&amp;quot;来补强;&lt;/li&gt;
&lt;li&gt;资源滥用(fork bomb, 文件描述符耗尽)可导致宿主机 DoS;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;目标&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;结合容器的轻量性与 VM 的强隔离;&lt;/li&gt;
&lt;li&gt;需求:
&lt;ul&gt;
&lt;li&gt;毫秒级实例化&lt;/li&gt;
&lt;li&gt;高密度运行&lt;/li&gt;
&lt;li&gt;小镜像/低内存占用&lt;/li&gt;
&lt;li&gt;快速挂起/恢复&lt;/li&gt;
&lt;li&gt;保持 VM 的硬件隔离安全性&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;贡献&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;分析 Xen 性能瓶颈, 重构控制面:
&lt;ul&gt;
&lt;li&gt;移除 XenStore (&lt;strong&gt;noxs&lt;/strong&gt;), 消除中心化瓶颈;&lt;/li&gt;
&lt;li&gt;新工具链 &lt;strong&gt;chaos/libchaos&lt;/strong&gt; + &lt;strong&gt;split toolstack&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;提出 &lt;strong&gt;Tinyx&lt;/strong&gt; 工具, 生成极小 Linux VM; 支持 unikernel;&lt;/li&gt;
&lt;li&gt;实现 &lt;strong&gt;LightVM&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>The Turtles Project: Design and Implementation of Nested Virtualization</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/22/computer_system_basics/os/historical/14.turtle_IBM/</link>
      <pubDate>Mon, 22 Sep 2025 12:50:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/22/computer_system_basics/os/historical/14.turtle_IBM/</guid>
      <description>&lt;p&gt;Authors: Muli Ben-Yehuda et al., IBM Research / IBM Linux Technology Center&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1-背景与动机&#34;&gt;1. 背景与动机&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;传统虚拟化 (single-level)&lt;/strong&gt;: 一个 hypervisor (L0) 管理多个 VM, 每个 VM 运行 OS;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;嵌套虚拟化 (nested virtualization)&lt;/strong&gt;: 允许一个 hypervisor (L1) 作为 guest 运行, 并且还能继续运行自己的 VM (L2);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;需求来源&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;现代操作系统自带虚拟化功能&lt;/strong&gt;(Windows XP mode in Win7, Linux 内置 KVM);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IaaS 场景&lt;/strong&gt;: 云提供商 (L0) 希望用户能运行自己的 hypervisor (L1), 自己管理 VM (L2);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;研究和测试&lt;/strong&gt;: 嵌套虚拟化方便调试/benchmark hypervisor;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;安全性&lt;/strong&gt;: 可以研究/防御 hypervisor-level rootkit;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;iaas-infrastructure-as-a-service&#34;&gt;IaaS (Infrastructure as a Service)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;云计算三层服务之一: IaaS / PaaS / SaaS;&lt;/li&gt;
&lt;li&gt;IaaS = 提供虚拟化的计算资源(VM, 存储, 网络);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;例子&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;AWS EC2: 创业公司快速租用 VM, 按需扩展;&lt;/li&gt;
&lt;li&gt;Google Cloud GPU: 科研人员租用 A100 GPU VM;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;与论文关系: 云提供商必须支持 nested virtualization, 才能让用户在 VM 内运行自己的 hypervisor;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-虚拟化理论基础&#34;&gt;2. 虚拟化理论基础&lt;/h2&gt;
&lt;h3 id=&#34;popekgoldberg-1974&#34;&gt;Popek–Goldberg (1974)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;三大条件&lt;/strong&gt;: 等价性 (equivalence), 资源控制 (resource control), 效率 (efficiency);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;定理&lt;/strong&gt;: 如果架构中所有 &lt;strong&gt;sensitive 指令&lt;/strong&gt; 都是 &lt;strong&gt;privileged 指令&lt;/strong&gt;, 则该架构是可虚拟化的;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;影响&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;解释了早期 x86 &lt;strong&gt;不可完全虚拟化&lt;/strong&gt; $\rightarrow$ VMware 使用二进制翻译绕过;&lt;/li&gt;
&lt;li&gt;推动了 Intel/AMD 添加 VT-x / SVM 硬件扩展;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3-两种嵌套虚拟化模型&#34;&gt;3. 两种嵌套虚拟化模型&lt;/h2&gt;
&lt;h3 id=&#34;1-multi-level-support&#34;&gt;1) Multi-level support&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;硬件直接支持多层 hypervisor;&lt;/li&gt;
&lt;li&gt;Trap 从 L2 直接交给 L1;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;例子&lt;/strong&gt;: IBM System z;&lt;/li&gt;
&lt;li&gt;高效, 但硬件设计复杂; 且一般多层的支持都是有限的, 如只支持两层, 这篇论文是在理论上支持任意层数的嵌套虚拟化, 因此更高层的虚拟化实际上还是依赖于单层虚拟化的软件支持逻辑: &lt;strong&gt;compress&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;2-single-level-support&#34;&gt;2) Single-level support&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;硬件只有一层 root mode (L0);&lt;/li&gt;
&lt;li&gt;所有 trap(无论来自 L1, L2, L3)&lt;strong&gt;都掉到 L0&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;L0 决定是否转发给 L1;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;例子&lt;/strong&gt;: x86 的 Intel VT-x (VMX), AMD SVM;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiplexing single-level&lt;/strong&gt;: L0 将唯一的一层虚拟化能力&amp;quot;复用&amp;quot;, 对上层 L1/L2 进行模拟;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-cpu-虚拟化-vmx&#34;&gt;4. CPU 虚拟化 (VMX)&lt;/h2&gt;
&lt;h3 id=&#34;vmx--l0&#34;&gt;VMX &amp;amp; L0&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;VMX&lt;/strong&gt; = Intel VT-x 的指令扩展集;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L0&lt;/strong&gt; = 唯一运行在 VMX root mode 的 hypervisor;&lt;/li&gt;
&lt;li&gt;所有 VMExit/VMEntry 都必须经过 L0;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Trap 流程&lt;/strong&gt;: Single-level support: L2 trap $\rightarrow$ L0 trap handler $\rightarrow$ L0 转发给 L1;&lt;/p&gt;</description>
    </item>
    <item>
      <title>A Comparison of Software and Hardware Techniques for x86 Virtualization</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/21/computer_system_basics/os/historical/13.x86virt_comp/</link>
      <pubDate>Sun, 21 Sep 2025 20:22:43 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/21/computer_system_basics/os/historical/13.x86virt_comp/</guid>
      <description>&lt;p&gt;The main technical contributions of this paper are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a review of VMware Workstation&amp;rsquo;s software VMM, focusing on performance properties of the virtual instruction execution engine;&lt;/li&gt;
&lt;li&gt;a review of the emerging hardware support, identifying performance trade-offs;&lt;/li&gt;
&lt;li&gt;a quantitative performance comparison of a software and a hardware VMM.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Establishes &lt;strong&gt;three essential characteristics&lt;/strong&gt; for system software to be considered a VMM&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Fidelity(保真性)&lt;/strong&gt; Software on the VMM executes identically to its execution on hardware, barring timing effects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance(高性能)&lt;/strong&gt; An overwhelming majority of guest instructions are executed by the hardware without the intervention of the VMM.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Safety(安全性)&lt;/strong&gt; The VMM manages all hardware resources.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;1-基础概念&#34;&gt;1. 基础概念&lt;/h2&gt;
&lt;h3 id=&#34;vmm-vs-hypervisor&#34;&gt;VMM vs Hypervisor&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;VMM (Virtual Machine Monitor)&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;来自 Popek &amp;amp; Goldberg (1974), 强调核心虚拟化功能(trap &amp;amp; emulate, BT, shadow structures);&lt;/li&gt;
&lt;li&gt;负责虚拟机执行控制;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Hypervisor&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;工程上更常用的术语, 指整个虚拟化层;&lt;/li&gt;
&lt;li&gt;包含 VMM, 同时提供调度, 资源分配, 设备模型, 管理接口;&lt;/li&gt;
&lt;li&gt;Type 1(bare-metal, 如 Xen, ESXi), Type 2(hosted, 如 VMware Workstation);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Xen and the Art of Virtualization</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/os/historical/12.xen/</link>
      <pubDate>Mon, 15 Sep 2025 20:16:57 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/os/historical/12.xen/</guid>
      <description>&lt;h2 id=&#34;背景&#34;&gt;背景&lt;/h2&gt;
&lt;p&gt;应用设计需要一个稳定的环境, 而传统的 OS 隔离技术不足以支持这种要求, 比如一个程序消耗了大量的算力并且被 scheduler 赋予了非常高的优先级, 或者系统被程序攻击了, 从而被某个其他进程消耗了很多资源导致当前进程的性能受损, 因此需要更高层的 VM 设计来实现工业界需要的 isolation 级别&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Lamport Clock, RSM</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/ds/2.lamport_clock/</link>
      <pubDate>Mon, 15 Sep 2025 17:12:02 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/ds/2.lamport_clock/</guid>
      <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;p&gt;本简报回顾了分布式系统中逻辑时钟的核心概念, 其在处理事件排序方面的必要性, 以及它如何解决传统时间戳的局限性;重点介绍了&amp;quot;先行发生&amp;quot; (&lt;strong&gt;Happens-Before&lt;/strong&gt;) 关系, Lamport 逻辑时钟的构造与规则, 以及如何通过扩展逻辑时钟实现分布式系统中的全序 (Total Ordering);&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Relational Algebra to SQL Grammar</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/db/2.sql/</link>
      <pubDate>Mon, 15 Sep 2025 14:27:17 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/db/2.sql/</guid>
      <description>&lt;h2 id=&#34;relational-algebra&#34;&gt;Relational Algebra&lt;/h2&gt;
&lt;h3 id=&#34;选择-selection-from&#34;&gt;选择 (Selection), FROM&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: S/$\sigma$ (sigma), $S_{\text{condition}}(\text{relation})$&lt;/li&gt;
&lt;li&gt;用法: 从关系中选择满足特定逻辑条件的行(元组)的子集;&lt;/li&gt;
&lt;li&gt;条件构成: 条件是 bool combitation ($\wedge$ 表示 AND,$\vee$ 表示 OR)的项;每个项的形式为 &lt;code&gt;Attr1 &amp;lt;oper&amp;gt; Attr2&lt;/code&gt; 或 &lt;code&gt;Attr &amp;lt;oper&amp;gt; value&lt;/code&gt;, 其中 &lt;code&gt;&amp;lt;oper&amp;gt;&lt;/code&gt; 包括 {&amp;gt;, $\ge$, =, $\le$, &amp;lt;};&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;$\sigma_{country=&#39;USA&#39; $\wedge$ sport=&amp;lsquo;gymnastics&amp;rsquo;}(Athlete): 从 Athlete 关系中选择国家为 &amp;lsquo;USA&amp;rsquo; 且运动为 &amp;lsquo;gymnastics&amp;rsquo; 的运动员;&lt;/li&gt;
&lt;li&gt;对应的SQL语句示例: &lt;code&gt;SELECT * FROM Athlete WHERE sport = &#39;gymnastics&#39; AND country = &#39;USA&#39;&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;投影-projection-select&#34;&gt;投影 (Projection), SELECT&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: $\pi$ (pi)&lt;/li&gt;
&lt;li&gt;用法: 从关系中 &lt;strong&gt;选择特定的列&lt;/strong&gt; (attributes), 并舍弃不需要的列;此操作还会移除重复的元组, 因为经典关系模型是一个 Set, set 属性确保没有重复的;&lt;/li&gt;
&lt;li&gt;语法: $\pi$ Attr_list(relation)&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;$\pi_{sport, country}(Athlete)$: 从 Athlete 关系中选择 &amp;lsquo;sport&amp;rsquo; 和 &amp;lsquo;country&amp;rsquo; 列;&lt;/li&gt;
&lt;li&gt;对应的SQL语句示例: &lt;code&gt;SELECT sport, country FROM Athlete&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;集合差-set-difference&#34;&gt;集合差 (Set-Difference)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: - (Minus)&lt;/li&gt;
&lt;li&gt;用法: 返回属于第一个关系但不属于第二个关系的元组;&lt;/li&gt;
&lt;li&gt;输入条件: 两个关系必须是 &lt;strong&gt;Union-Compatible&lt;/strong&gt; 的, 即具有相同 number 和 type 的 attritbutes, 并且 same order;&lt;/li&gt;
&lt;li&gt;结果字段名: 使用第一个输入关系的字段名;&lt;/li&gt;
&lt;li&gt;语法: Relation1 - Relation2&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;name - AthleteName: 返回 name 关系中的 record, 但不在 AthleteName 关系中, 即找出不是运动员的名字;&lt;/li&gt;
&lt;li&gt;对应的SQL语句示例: &lt;code&gt;SELECT * FROM name MINUS SELECT * FROM AthleteName&lt;/code&gt;; (在某些系统中也称为 EXCEPT);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;并集-union&#34;&gt;并集 (Union)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: $\cup$&lt;/li&gt;
&lt;li&gt;用法: 返回属于第一个关系或属于第二个关系的元组;&lt;/li&gt;
&lt;li&gt;输入条件: 同 Minus 的要求, 两个关系必须是 &lt;strong&gt;Union-Compatible&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;语法: Relation1 $\cup$ Relation2&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$\sigma$color=&#39;red&#39; Boats $\cup$ $\sigma$color=&#39;green&#39; Boats&lt;/code&gt;: 返回颜色为红色或绿色的船只;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;重命名-rename&#34;&gt;重命名 (Rename)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: r/$\rho$ (rho)&lt;/li&gt;
&lt;li&gt;用法: 用于重命名关系或关系中的属性;&lt;/li&gt;
&lt;li&gt;用例:
&lt;ul&gt;
&lt;li&gt;作为简写;&lt;/li&gt;
&lt;li&gt;执行自连接(Self-joins), 也就是利用同一个表两次需要重命名;&lt;/li&gt;
&lt;li&gt;当两个关系具有相同字段名时进行区分, 比如 Student.name 和 Employee.name 就需要重命名;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;语法: $\rho_{AFTER}(BEFORE)$ 或 $\rho$(AFTER, BEFORE) (重命名关系); 也可以重命名列, 如 A1.aid name1;&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;$\rho$(A1, Athlete) $\times$ $\rho$(A2, Athlete): 将 Athlete 关系重命名为 A1 和 A2, 用于自连接;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;笛卡尔积-cross-product--cartesian-product&#34;&gt;笛卡尔积 (Cross-Product / Cartesian Product)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: $\times$&lt;/li&gt;
&lt;li&gt;用法: 允许我们将两个关系组合起来;结果是第一个关系的每一行与第二个关系的每一行组合;&lt;/li&gt;
&lt;li&gt;结果模式: 包含来自两个关系的所有字段, 名称默认继承(如果需要, 可以使用表名进行消歧);&lt;/li&gt;
&lt;li&gt;语法: Relation1 $\times$ Relation2&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;Athlete $\times$ Olympics: 将 Athlete 关系中的每一行与 Olympics 关系中的每一行组合;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;连接-join&#34;&gt;连接 (Join)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: $\bowtie$&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conditional Join or $\Theta$-Join&lt;/strong&gt;: R $\bowtie_{condition}$ S, 其中 c 是连接条件, 先做cross product, 然后在结果上应用一个选择条件 condition;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Equijoin&lt;/strong&gt;: R $\bowtie$ S, 其中连接条件是 R 和 S 之间所有 &lt;strong&gt;同名属性的相等&lt;/strong&gt;;等价于 natural join;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Natural Join&lt;/strong&gt;: R $\bowtie$ S, 自动基于所有 &lt;strong&gt;同名属性&lt;/strong&gt; 进行连接;如果没有同名属性, 则结果等价于笛卡尔积;&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;$\pi$sname($\sigma$bid=103(Reserves) $\bowtie$ Sailors): 查找预订了船只 #103 的水手的名字;这里隐式地使用了连接, 将 Reserves 和 Sailors 根据共享属性 sid 进行连接;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;交集-intersection&#34;&gt;交集 (Intersection)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: $\cap$&lt;/li&gt;
&lt;li&gt;用法: 从基本操作构建的附加操作, 非常有用;返回同时属于两个关系的元组;&lt;/li&gt;
&lt;li&gt;语法: Relation1 $\cap$ Relation2&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;$\pi$sname(Tempred $\cap$ Tempgreen $\bowtie$ Sailors): 查找预订了红色和绿色船只的水手的名字;Tempred 包含预订红色船只的水手 sid, Tempgreen 包含预订绿色船只的水手 sid;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;除法-division&#34;&gt;除法 (Division)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;符号: /&lt;/li&gt;
&lt;li&gt;用法: 通常用于处理&amp;quot;找到所有满足某个条件 (&lt;strong&gt;for all&lt;/strong&gt;) 的实体&amp;quot;这类查询;例如, &amp;ldquo;找到预订了所有船只的水手&amp;rdquo;;&lt;/li&gt;
&lt;li&gt;定义: 如果关系 A 有两个字段 x 和 y, 关系 B 只有一个字段 y, 那么 A/B = {&lt;x&gt; | $\forall$&lt;y&gt;$\in$ B, &amp;lt;x, y&amp;gt;$\in$A}; 对于 B 中的每一个 y 元组(例如船只), A 中都存在一个 &amp;lt;x,y&amp;gt; 元组, 所有这样的 x 元组的集合;&lt;/li&gt;
&lt;li&gt;语法: RelationA / RelationB&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;假设 sailor 表是一个 (sid, bid) 表示水手-船只租赁关系;&lt;/li&gt;
&lt;li&gt;$\rho_{sids}$($\pi_{sid}$, bid(Reserves) / $\pi$bid(Boats)) $\bowtie$ Sailors: 查找预订了所有船只的水手的名字;&lt;br&gt;
理解这些算符对于理解SQL查询处理至关重要;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;sql-grammar&#34;&gt;SQL Grammar&lt;/h2&gt;
&lt;h3 id=&#34;constraints&#34;&gt;Constraints&lt;/h3&gt;
&lt;p&gt;对于一个变量如果有数值要求, 可以使用 CHECK 约束;例如:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Disco: Running Commodity Operating Systems on Scalable Multiprocessors</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/os/historical/11.disco/</link>
      <pubDate>Mon, 15 Sep 2025 13:17:28 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/15/computer_system_basics/os/historical/11.disco/</guid>
      <description>&lt;p&gt;这篇论文是 VMware 的基石论文&lt;/p&gt;
&lt;h2 id=&#34;历史背景和硬件&#34;&gt;历史背景和硬件&lt;/h2&gt;
&lt;p&gt;在上世纪 90 年代, 硬件设计已经非常厉害了, 但是多个商业系统跑在一个硬件机器上非常困难, 因此这篇论文设计了一个模式:&lt;br&gt;
在 hardware 和 os 之间添加一个中间层, &lt;strong&gt;类似&lt;/strong&gt; 于一个 vmm 来进行隔离&lt;/p&gt;
&lt;p&gt;这里的硬件背景:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Stanford FLASH shared memory multiprocessor&lt;/li&gt;
&lt;li&gt;experimental cache coherent non-uniform memory architecture (ccNUMA)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;传统的不足&#34;&gt;传统的不足&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;硬件的革新需要 significant OS changes&lt;/li&gt;
&lt;li&gt;OS 本体代码量过大并不适合修改来适配硬件&lt;/li&gt;
&lt;li&gt;buggy/incompatible system software can significantly impact the success of such machines&lt;/li&gt;
&lt;li&gt;commodity OS system software 具有 constraints + inflexibility 的缺点&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;关键词&#34;&gt;关键词&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;scalable&lt;/strong&gt;: 设计的系统可以适配不同的(未来的)硬件
&lt;ul&gt;
&lt;li&gt;意味着系统设计能随着处理器数量的增加(几十到几百个 CPU)依然保持良好性能&lt;/li&gt;
&lt;li&gt;传统系统只有少量 cpu 并且用一条总线通信, 但是随着 cpu 数量增加, 总线会成为瓶颈&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UMA&lt;/strong&gt;: 统一内存访问, 所有 cpu 访问内存的速度相同, 也就是用上文的总线通信, 随着 cpu 数量增加, 总线压力增大, 性能下降&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NUMA&lt;/strong&gt;: 非统一内存访问, 每个 cpu 有自己的本地内存, 访问本地内存速度快, 访问其他 cpu 的内存速度慢, 这样随着 cpu 数量增加, 性能下降不明显&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ccNUMA 的 cc&lt;/strong&gt;: cache-coherent, 每个 cpu 有自己的缓存, 但是缓存之间需要保持一致性, 这样可以提高性能,但是也增加了复杂度
&lt;ul&gt;
&lt;li&gt;常见方式是 &lt;strong&gt;目录协议 (directory-based coherence)&lt;/strong&gt;, 每个内存块有一个目录记录谁缓存了它, 当有更新时通知或失效这些缓存&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;flexible&lt;/strong&gt;: 可以适配不同的 OS (注意 scalable 强调的是硬件的多样性, flexible 强调的是软件的多样性)
&lt;ul&gt;
&lt;li&gt;系统能支持多样化的使用场景, 工作负载和配置, 而不是只能针对单一情况优化&lt;/li&gt;
&lt;li&gt;这里着重强调对 variety of workloads 的支持, 例如 cpu 密集型, io 密集型, 内存密集型等&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;commodity OS&lt;/strong&gt;: 现成的, 广泛使用的操作系统, 例如 Linux, Windows, 能应对各种应用场景, 但缺乏针对特定硬件的优化&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;specialized OS&lt;/strong&gt;: 针对特定硬件或应用场景优化的操作系统, 例如实时操作系统, 嵌入式系统, 但缺乏通用性&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;shared memory multiprocessor&lt;/strong&gt;: 多个处理器可以访问同一块内存
&lt;ul&gt;
&lt;li&gt;所有处理器访问 同一个全局内存地址空间(不像分布式系统那样各有独立内存);
&lt;ul&gt;
&lt;li&gt;好处: 编程模型更简单(多个 CPU 看起来就像在同一个大内存上操作);&lt;/li&gt;
&lt;li&gt;问题: 容易出现 内存访问冲突 和 一致性问题;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLASH 硬件&lt;/strong&gt;: 多个节点, 每个节点有 CPU, 内存和 I/O, 通过高速互连组成; 采用目录协议保持缓存一致性, 因此对软件呈现的是一个 共享内存多处理器, 带有 NUMA 特性&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;vm-方案的缺点&#34;&gt;VM 方案的缺点&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Overheads(性能开销)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;需要软件模拟特权指令, 虚拟化 I/O, 带来额外异常处理和执行开销;&lt;/li&gt;
&lt;li&gt;每个 VM 都要复制 OS 和应用的代码/数据, 还会重复维护大内存结构(如文件系统 buffer cache), 导致内存浪费;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;Resource Management (资源管理问题)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;VMM 缺乏操作系统的高层语义, 只能&amp;quot;盲目&amp;quot;调度;&lt;/li&gt;
&lt;li&gt;例如无法区分 idle loop (busy waiting 对 vmm 层透明) 与有效计算, 可能浪费 CPU 时间; 也无法知道某页内存是否已不再使用, 导致内存分配效率低;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;Communication and Sharing(通信与共享困难)&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;不同 VM 之间的文件, 磁盘, 应用难以共享;&lt;/li&gt;
&lt;li&gt;例如在 VM/370 上, 一个用户的虚拟磁盘若被一个 VM 占用, 另一个 VM 无法访问;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;作者观点: 虽然这些缺点依然存在, 但通过结合现代操作系统对分布式环境的支持, 以及 VMM 的新设计技巧, 它们的影响可以大大减轻;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Mach: A New Kernel Foundation For UNIX Development</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/6.Mach/</link>
      <pubDate>Sat, 13 Sep 2025 16:04:59 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/6.Mach/</guid>
      <description>&lt;h2 id=&#34;mach-system&#34;&gt;Mach System&lt;/h2&gt;
&lt;h3 id=&#34;硬件平台-hardware&#34;&gt;硬件平台 (Hardware)&lt;/h3&gt;
&lt;p&gt;Mach 最初运行在 DEC VAX 系列机器上, 后来被移植到 IBM RT PC, Sun-3 (68k), Encore Multimax, Sequent Symmetry 等多处理器系统;&lt;br&gt;
这些平台通常配备 &lt;strong&gt;数 MB 到数十 MB 的内存 (RAM)&lt;/strong&gt;, &lt;strong&gt;数百 MB 到数 GB 的磁盘存储&lt;/strong&gt;, 以当时标准算是中高端配置;&lt;br&gt;
通过这些硬件, Mach 展示了良好的可移植性和对对称多处理器 (SMP) 的支持, 并能在有限资源下探索虚拟内存与分布式操作系统的先进机制;&lt;/p&gt;</description>
    </item>
    <item>
      <title>On μ-Kernel Construction</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/7.micro-Kernel/</link>
      <pubDate>Sat, 13 Sep 2025 16:04:51 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/7.micro-Kernel/</guid>
      <description>&lt;h2 id=&#34;on--kernel-construction&#34;&gt;On $\mu$-Kernel Construction&lt;/h2&gt;
&lt;p&gt;传统观点是, 微内核是 &lt;em&gt;inefficient&lt;/em&gt; 和 &lt;em&gt;not sufficiently flexible&lt;/em&gt; 的, 但是本文说明相反观点, 并展示微内核可以达到 macro kernel 的 efficiency&lt;br&gt;
以及为什么当前已有的 measurement 很难说明这一点&lt;/p&gt;
&lt;h3 id=&#34;设计目标&#34;&gt;设计目标&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;微内核支持 modular&lt;/li&gt;
&lt;li&gt;外部系统可以使用 micro kernel 提供的 mechanism&lt;/li&gt;
&lt;li&gt;微内核系统更加 flexible 和 tailorable&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;明确-target&#34;&gt;明确 target&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;决定整个 $\mu$-kernel 的能力的不应该是 performance, 而应该是 functionality&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;也就是说尽量不要把指令放进内核, 除非纯外部执行无法完成指定任务&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;系统应该能支持 protection&lt;/li&gt;
&lt;li&gt;independence principle: 不同 sub system 之间不应该有任何互相影响和 corruption&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;这里的子系统指的是进程, 也就是用户态的资源分割单位&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;4&#34;&gt;
&lt;li&gt;integrity principle: 不同子系统之间应该有 address 联系, 也就是进程能通过地址来互相通信&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;address-space&#34;&gt;Address Space&lt;/h3&gt;
&lt;p&gt;从硬件来看地址空间就是 virtual addr 到 physical addr 的映射, 这是通过 TLB 和 page table 来实现的&lt;/p&gt;</description>
    </item>
    <item>
      <title>Exokernel: An Operating System Architecture for Application-Level Resource Management</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/9.exokernel/</link>
      <pubDate>Sat, 13 Sep 2025 16:04:42 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/9.exokernel/</guid>
      <description>&lt;h1 id=&#34;exokernel-an-operating-system-architecture-for-application-level-resource-management&#34;&gt;Exokernel: An Operating System Architecture for Application-Level Resource Management&lt;/h1&gt;
&lt;p&gt;“Dawson R. Engler, M. Frans Kaashoek, and James O’Toole Jr. M.I.T. Laboratory for Computer Science” (&lt;a href=&#34;#ZgotmplZ&#34;&gt;Engler 等, p. 251&lt;/a&gt;) (&lt;a href=&#34;#ZgotmplZ&#34;&gt;pdf&lt;/a&gt;)&lt;/p&gt;
&lt;h2 id=&#34;motivation&#34;&gt;Motivation&lt;/h2&gt;
&lt;p&gt;传统的 general OS kernel 只能提供给最广泛的用户态程序一个中庸的最优解，然而随着软件界的发展，越来越需要一种对各种不同的软件有各自 customized 方案的特殊化优化&lt;/p&gt;</description>
    </item>
    <item>
      <title>Plan 9 from Bell Labs</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/5.Plan9_9P/</link>
      <pubDate>Sat, 13 Sep 2025 16:04:35 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/13/computer_system_basics/os/historical/5.Plan9_9P/</guid>
      <description>&lt;h2 id=&#34;plan-9-system-bell-lab&#34;&gt;Plan 9 System (Bell Lab)&lt;/h2&gt;
&lt;h3 id=&#34;硬件设备&#34;&gt;硬件设备&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;目标环境: 便宜的小型机(办公室个人使用)+ 集中管理的大型服务器(file server, cpu server)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;分布式环境设计, 强调网络互联和资源共享&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;UTF-8&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;/proc&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;rfork&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;&lt;p&gt;硬件存储抽象&lt;br&gt;
软件文件系统抽象&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;包括网络的分布式一致性&lt;br&gt;
创新点&lt;/p&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;h3 id=&#34;设计目标&#34;&gt;设计目标&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;maintainence: 分布式的个人 pc 进行 administer 一个系统的开销太大太困难了&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;也就是通过 centralized administration 来实现集中管理&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;统一接口: 一切皆文件, 通过 9P 协议访问&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;每个进程拥有独立的命名空间, 可通过 &lt;code&gt;bind&lt;/code&gt; 和 &lt;code&gt;mount&lt;/code&gt; 重新组合&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;支持透明分布式: 远程资源与本地资源无差别&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;简洁内核, 核心任务是 9P 消息的 &lt;strong&gt;multiplex/demultiplex&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>The Performance of μ-Kernel-Based Systems</title>
      <link>https://www.whoami-wesleyyou.top/2025/09/08/computer_system_basics/os/historical/8.L4/</link>
      <pubDate>Mon, 08 Sep 2025 16:30:05 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/09/08/computer_system_basics/os/historical/8.L4/</guid>
      <description>&lt;h2 id=&#34;motivation-和论文目标&#34;&gt;Motivation 和论文目标&lt;/h2&gt;
&lt;p&gt;守旧派往往认为, 第一代 $\mu$-kernel  微内核具有非常低的 performance/flexibility, 但是本文希望能测试第二代微内核的性能和灵活性, 实验手段是测试一些老的系统性能测试以及加上一些新的有针对的测试&lt;/p&gt;
&lt;p&gt;微内核的优点之一是, 内核小巧, 部件坏的概率小&lt;/p&gt;
&lt;p&gt;微内核只提供 mechanism 但是不提供 policy, 但是也需要上面一层安全控制的 pager, FS 等资源, 这些往往依赖于 UNIX Server 实现&lt;/p&gt;</description>
    </item>
    <item>
      <title>0. Golang Tutorial</title>
      <link>https://www.whoami-wesleyyou.top/2025/08/31/computer_system_basics/ds/0.go_tuto/</link>
      <pubDate>Sun, 31 Aug 2025 14:37:15 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/08/31/computer_system_basics/ds/0.go_tuto/</guid>
      <description>&lt;h2 id=&#34;goroutine&#34;&gt;Goroutine&lt;/h2&gt;
&lt;p&gt;在 java/c++ 中我们要实现并发编程的时候, 我们通常需要自己维护一个线程池, 并且需要自己去包装一个又一个的任务, 同时需要自己去调度线程执行任务并维护上下文切换, 这一切通常会耗费程序员大量的心智;那么能不能有一种机制, 程序员只需要定义很多个任务, 让系统去帮助我们把这些任务分配到 CPU 上实现并发执行呢?&lt;/p&gt;</description>
    </item>
    <item>
      <title>1.design_purpose</title>
      <link>https://www.whoami-wesleyyou.top/2025/08/30/computer_system_basics/ds/1.design_purpose/</link>
      <pubDate>Sat, 30 Aug 2025 18:13:48 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/08/30/computer_system_basics/ds/1.design_purpose/</guid>
      <description>&lt;h2 id=&#34;什么是分布式系统&#34;&gt;什么是分布式系统?&lt;/h2&gt;
&lt;p&gt;一个分布式系统, 从物理上说是 用户 -network- 多台服务器主机 形成的一个特殊的系统&lt;/p&gt;
&lt;p&gt;如果对这个模型进行抽象, 其实就是 单个terminal 和 多个 process 之间的通信,&lt;br&gt;
其中, 这些 process 空间上分离, 通过网络进行通信, 不应该存在明显延迟, 并且命运不同(一台主机挂了不应该影响其他主机)&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. Database Management System</title>
      <link>https://www.whoami-wesleyyou.top/2025/08/30/computer_system_basics/db/1.dbms/</link>
      <pubDate>Sat, 30 Aug 2025 16:39:30 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/08/30/computer_system_basics/db/1.dbms/</guid>
      <description>&lt;h2 id=&#34;dbms-database-management-system&#34;&gt;DBMS (Database Management System)&lt;/h2&gt;
&lt;p&gt;A software package designed to store and manage databases. Often loosely called&lt;br&gt;
a database.&lt;/p&gt;
&lt;p&gt;传统的数据管理, 往往是结合 csv&lt;br&gt;
格式文件来将数据存储起来, 并且允许通过各种约束条件查找,&lt;br&gt;
但是假设存在一个学生数据库系统, 包括 姓名, 年龄, id,&lt;br&gt;
成绩等字段, 如果原始数据的存储方式是分成两个 文件, 一个存储 姓名到 id&lt;br&gt;
的映射, 另一个存储 id 到成绩的映射, 那么采用传统的 c++ 等语言来查找数据,&lt;br&gt;
会存在很多问题, 例如, atomic 的操作, 很难在确保 performance 的前提下能保证&lt;br&gt;
consistency&lt;/p&gt;</description>
    </item>
    <item>
      <title>7. Gray Failure the Achilles&#39; Heel of Cloud-Scale Systems</title>
      <link>https://www.whoami-wesleyyou.top/2025/06/01/computer_system_basics/os/OrderLab/7.%20Gray%20Failure%20the%20Achilles%27%20Heel%20of%20Cloud-Scale%20Systems/</link>
      <pubDate>Sun, 01 Jun 2025 17:16:15 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/06/01/computer_system_basics/os/OrderLab/7.%20Gray%20Failure%20the%20Achilles%27%20Heel%20of%20Cloud-Scale%20Systems/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;这篇文章系统性地提出并定义了云计算系统中的&amp;quot;灰色故障&amp;quot;(Gray Failure)问题, 认为它是当前云基础设施高可用性的一大障碍&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;gray failure&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;component failures whose manifestations are fairly subtle&lt;br&gt;
and thus defy quick and definitive detection&lt;/p&gt;
&lt;p&gt;系统某部分发生了轻微但持续的问题, 这些问题不易被传统故障检测机制发现, 但已经影响了应用层的性能和可用性;它不同于&amp;quot;失败即停&amp;quot; (fail-stop) 故障, 后者更易被监测和处理&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. Fail Stutter Fault Tolerance</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/31/computer_system_basics/os/OrderLab/6.%20Fail%20Stutter%20Fault%20Tolerance%202001/</link>
      <pubDate>Sat, 31 May 2025 18:32:49 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/31/computer_system_basics/os/OrderLab/6.%20Fail%20Stutter%20Fault%20Tolerance%202001/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;h3 id=&#34;背景问题缺陷&#34;&gt;背景问题缺陷&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Byzantine 模型假设组件可能出现任意错误甚至恶意行为, &lt;strong&gt;过于复杂难以实施&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;Fail-stop 模型假设组件要么正常工作, 要么完全停止, 虽然简单易用, 但&lt;strong&gt;忽视了现代硬件中常见的&amp;quot;性能故障&amp;quot;&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;本文特点&#34;&gt;本文特点&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Fail-Stutter 模型&lt;/strong&gt;&lt;/em&gt;: a realistic and yet tractable fault model that accounts for both absolute failure and a new range of performance failures common in modern components.&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. Fail-Slow at Scale</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/27/computer_system_basics/os/OrderLab/5.%20Fail-Slow%20at%20Scale/</link>
      <pubDate>Tue, 27 May 2025 15:11:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/27/computer_system_basics/os/OrderLab/5.%20Fail-Slow%20at%20Scale/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;这篇论文 &lt;em&gt;Fail-Slow at Scale: Evidence of Hardware Performance Faults in Large Production Systems&lt;/em&gt; 由Haryadi S. Gunawi等人发表在第16届USENIX文件与存储技术会议(FAST 2018)上&lt;/p&gt;
&lt;p&gt;系统性地揭示了在大规模生产系统中&amp;quot;fail-slow&amp;quot;(故障-缓慢)硬件现象的存在与影响;这类故障指的是硬件仍在运行, 但其性能严重退化, 未达到应有的标准;&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. Metastable Failures in Distributed Systems</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/22/computer_system_basics/os/OrderLab/3.%20Metastable%20Failures%20in%20Distributed%20Systems/</link>
      <pubDate>Thu, 22 May 2025 21:38:11 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/22/computer_system_basics/os/OrderLab/3.%20Metastable%20Failures%20in%20Distributed%20Systems/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;metastable failures 亚稳态故障&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;a failure pattern in distributed systems&lt;/p&gt;
&lt;p&gt;Currently, metastable failures manifest themselves as &lt;em&gt;black swan events(黑天鹅事故)&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;they are &lt;strong&gt;outliers&lt;/strong&gt;(异常事故) because nothing in the past points to their possibility&lt;/li&gt;
&lt;li&gt;have a &lt;strong&gt;severe impact&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;much easier to explain in hindsight(事后) than to predict.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Although instances of metastable failures can &lt;strong&gt;look different at the surface&lt;/strong&gt;, deeper analysis shows that they can be understood within the &lt;strong&gt;same framework&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;By reviewing experiences from a decade of operating &lt;strong&gt;hyperscale distributed systems&lt;/strong&gt;, we identify a class of failures that can &lt;strong&gt;disrupt&lt;/strong&gt; them, even when there are &lt;strong&gt;no hardware failures, configuration errors, or software bugs&lt;/strong&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. Metastable Failures in the Wild</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/22/computer_system_basics/os/OrderLab/4.%20Metastable%20Failures%20in%20the%20Wild/</link>
      <pubDate>Thu, 22 May 2025 21:33:26 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/22/computer_system_basics/os/OrderLab/4.%20Metastable%20Failures%20in%20the%20Wild/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;这篇文章是基于 MetaStable Failures in Distributed Systems 的升级, in the wild 指的是不可控的实际世界&lt;/p&gt;
&lt;p&gt;In this work, we study the prevalence(患病率) of such failures in the wild by scouring(冲刷) over publicly available incident reports from many organizations, ranging from hyperscalers to small companies&lt;/p&gt;
&lt;p&gt;In this paper, we make four contributions that extend the work of Bronson et al. and increase our understanding of metastable failures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A study of metastable failures in the wild that confirms metastable failures are universally observed and comprise a substantial fraction of the most severe outages (Section 2).&lt;/li&gt;
&lt;li&gt;An improved model that categorizes two types of triggers and two types of amplification mechanisms, which better explains how metastable failures happen (Section 3).&lt;/li&gt;
&lt;li&gt;An insider view at Twitter of a new type of metastable failure where garbage collection acts as an amplification mechanism (Section 4).&lt;/li&gt;
&lt;li&gt;Three example applications on which metastable failures are experimentally reproduced, which helps researchers propose and test solutions to metastable failures (Section 5).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;metastability-in-the-wild&#34;&gt;Metastability in the Wild&lt;/h2&gt;
&lt;p&gt;这一段主要讲了作者对近年来各大小厂的故障并且进行了原因分析和类型总结概括:&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Predictive and Adaptive Failure Mitigation to Avert Production Cloud VM Interruptions</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/13/computer_system_basics/os/OrderLab/2.%20Predictive%20and%20Adaptive%20Failure%20Mitigation%20to%20Avert%20Production%20Cloud%20VM%20Interruptions/</link>
      <pubDate>Tue, 13 May 2025 16:01:27 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/13/computer_system_basics/os/OrderLab/2.%20Predictive%20and%20Adaptive%20Failure%20Mitigation%20to%20Avert%20Production%20Cloud%20VM%20Interruptions/</guid>
      <description>&lt;p&gt;When a failure occurs in production systems, the highest priority is to quickly mitigate(缓解) it.&lt;/p&gt;
&lt;p&gt;Failure Mitigation (FM) is done in a reactive and &lt;strong&gt;ad-hoc way&lt;/strong&gt;, namely taking some &lt;strong&gt;fixed actions&lt;/strong&gt; only after a severe symptom is observed.&lt;/p&gt;
&lt;p&gt;Propose a &lt;strong&gt;preventive&lt;/strong&gt; and &lt;strong&gt;adaptive&lt;/strong&gt; failure mitigation service, &lt;em&gt;&lt;strong&gt;NARYA&lt;/strong&gt;&lt;/em&gt;, that is integraed in a production cloud, Microsoft Azure’s compute platform&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Narya predicts imminent(迫在眉睫的) host failures based on multi-layer system signals&lt;/li&gt;
&lt;li&gt;then decides smart mitigation actions&lt;/li&gt;
&lt;li&gt;&lt;em&gt;goal&lt;/em&gt;: avert(避免) VM failures&lt;/li&gt;
&lt;li&gt;Narya&amp;rsquo;s decision engine takes a novel online experimentation approach to continually explore the best mitigation action.
&lt;ul&gt;
&lt;li&gt;enhances the adaptive decision capability through reinforcement learning.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;key question&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. AIOpsLab: A Holistic Framework to Evaluate AI Agents for Enabling Autonomous Clouds</title>
      <link>https://www.whoami-wesleyyou.top/2025/05/12/computer_system_basics/os/OrderLab/1.%20AIOpsLab%20A%20Holistic%20Framework%20to%20Evaluate%20AI%20Agents%20for%20Enabling%20Autonomous%20Clouds/</link>
      <pubDate>Mon, 12 May 2025 22:03:24 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/05/12/computer_system_basics/os/OrderLab/1.%20AIOpsLab%20A%20Holistic%20Framework%20to%20Evaluate%20AI%20Agents%20for%20Enabling%20Autonomous%20Clouds/</guid>
      <description>&lt;p&gt;AI for IT Operations (AIOps) aims to automate complex operational tasks, such as fault localization and root cause analysis&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;traditional: ddressing isolated operational tasks&lt;/li&gt;
&lt;li&gt;LLM and AI agents: enabling end-to-end and multitask automation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Target&lt;/strong&gt;&lt;/em&gt;: self-healing cloud systems, a paradigm we term &lt;strong&gt;AgentOps&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&#34;aiopslab&#34;&gt;AIOpsLab&lt;/h2&gt;
&lt;p&gt;a framework that not only deploys micro-service cloud environments, injects faults, generates workloads, and exports telemetry(遥测得的) data but also orchestrates these components and provides interfaces for interacting with and evaluating agents.&lt;/p&gt;
&lt;p&gt;The ultimate goal of &lt;strong&gt;AIOps&lt;/strong&gt;(different from AgentOps) is to create autonomous self-healing clouds, where AI-driven approaches can detect, localize, and mitigate faults with minimal human intervention.&lt;/p&gt;</description>
    </item>
    <item>
      <title>9. 数字取证 Digital-Forensics</title>
      <link>https://www.whoami-wesleyyou.top/2025/04/02/computer_system_basics/network/security/9.%20%E6%95%B0%E5%AD%97%E5%8F%96%E8%AF%81%20Digital-Forensics/</link>
      <pubDate>Wed, 02 Apr 2025 16:45:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/04/02/computer_system_basics/network/security/9.%20%E6%95%B0%E5%AD%97%E5%8F%96%E8%AF%81%20Digital-Forensics/</guid>
      <description>&lt;h2 id=&#34;数字取证流程digital-forensics-process&#34;&gt;数字取证流程(Digital Forensics Process)&lt;/h2&gt;
&lt;h3 id=&#34;四个核心阶段&#34;&gt;四个核心阶段&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;识别(Identification)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;确定存储关键数据的物理/数字对象(如计算机, 硬盘, 移动设备, 外接媒体等);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;收集(Collection)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;保护证据完整性, 建立&lt;strong&gt;链式监管(Chain of Custody)&lt;/strong&gt;, 记录证据哈希(Hash of Image)以验证来源;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;分析(Analysis)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;检查文件系统, 日志, 内存等, 恢复删除文件(Deleted Files)或&lt;strong&gt;残留数据(Slack Space)&lt;/strong&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;报告(Reporting)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;形成专家报告, 提供法律证据(Legal Evidence);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;数据收集与保存data-collection--preservation&#34;&gt;数据收集与保存(Data Collection &amp;amp; Preservation)&lt;/h2&gt;
&lt;h3 id=&#34;数据来源&#34;&gt;数据来源&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;computer&lt;/li&gt;
&lt;li&gt;other harddrive&lt;/li&gt;
&lt;li&gt;monitor&lt;/li&gt;
&lt;li&gt;keyboard and mouse&lt;/li&gt;
&lt;li&gt;media (dvd, cd, usb)&lt;/li&gt;
&lt;li&gt;printer&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;digital forensics did not replace traditional (physical) forensic analysis&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;需要确保数据的原始性, 任何经过操作的数据都不能完全展示当时的情况, 因此需要创建&lt;br&gt;
forensic image (carefully created copy) 来进行保存&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Principle for collecting evidence&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Maintain a chain of custody
&lt;ul&gt;
&lt;li&gt;physically secure items of evidence&lt;/li&gt;
&lt;li&gt;track possession step by step&lt;/li&gt;
&lt;li&gt;keep documentation (hash image) to trace evidence to the src&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Priotize collection by volatility
&lt;ul&gt;
&lt;li&gt;脆弱的数据首先保存&lt;/li&gt;
&lt;li&gt;RAM &amp;gt; disk &amp;gt; external media&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;21-法医镜像forensic-image&#34;&gt;2.1 法医镜像(Forensic Image)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义&lt;/strong&gt;: 全盘位对位拷贝(Bit-for-Bit Copy), 保留所有数据(包括删除文件, slack/internal fragmentation 空间);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;工具&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;dd if=/path/to/forensic/src of=/path/to/store&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;需使用 &lt;strong&gt;写阻止器(Write-Blocker)&lt;/strong&gt; 防止修改原始数据; (只允许 read)
&lt;ul&gt;
&lt;li&gt;从而防止分析的 pc 篡改数据&lt;/li&gt;
&lt;li&gt;一般会额外计算一个 hash 来确保数据的完整性&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;22-内存取证live-memory-forensics&#34;&gt;2.2 内存取证(Live-Memory Forensics)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;只将 ram 里面的数据进行复制
&lt;ul&gt;
&lt;li&gt;利用了 thunderbolt&lt;br&gt;
(由英特尔(Intel)和苹果(Apple)共同开发的一种高速数据传输接口技术, 它集数据传输, 视频输出和供电于一体)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;冷启动攻击(Cold-Boot Attack)&lt;/strong&gt;: 通过物理重启并快速镜像未擦除的RAM数据;
&lt;ul&gt;
&lt;li&gt;一般情况下电脑重启会擦除 RAM 中的数据&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;虚拟化快照(VM Snapshot)&lt;/strong&gt;: 同时捕获内存与磁盘状态;&lt;/li&gt;
&lt;li&gt;对于不可以重启的OS, 可以考虑 freeze disk+ram (mem chip) 并且移存至其他硬件设备&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;23-移动设备取证mobile-device-forensics&#34;&gt;2.3 移动设备取证(Mobile Device Forensics)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;挑战&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;可能会被 无线电波 radio 连接进行数据篡改&lt;/li&gt;
&lt;li&gt;远程擦除防御: 使用 &lt;strong&gt;法拉第袋(Faraday Bag)&lt;/strong&gt; 屏蔽无线信号;&lt;/li&gt;
&lt;li&gt;硬件级加密(Hardware-Backed Security)与取证工具对抗;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3-存储结构与取证线索storage-structure--clues&#34;&gt;3. 存储结构与取证线索(Storage Structure &amp;amp; Clues)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;低级别存储(Low-Level Storage)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;块(Blocks)&lt;/strong&gt;: 存储设备基本单元(通常4KB);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;文件系统(Filesystem)&lt;/strong&gt;: 通过 &lt;strong&gt;索引节点(I-Node)&lt;/strong&gt; 管理文件元数据(Metadata)与块指针;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;删除与残留数据&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;删除文件&lt;/strong&gt;: 仅移除I-Node, 实际数据保留至被覆盖;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;碎片(Fragmentation)&lt;/strong&gt;: 文件扩展导致的数据块分散, 可能暴露历史操作痕迹;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;通过读取这些残留数据, 可以获得以前的数据, 这也是为什么可以删除恢复的原因&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;取证工具与技术forensic-tools--techniques&#34;&gt;取证工具与技术(Forensic Tools &amp;amp; Techniques)&lt;/h2&gt;
&lt;h3 id=&#34;取证的起始步&#34;&gt;取证的起始步&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;如果当前设备开机了: 不能关机, 直接 image 当前状态
&lt;ul&gt;
&lt;li&gt;关机会导致部分有用的数据丢失&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;如果当前设备关机了: 不能开机, 直接用 write-blocker&lt;br&gt;
等设备和额外的存储设备将当前数据转存复制&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;常用工具&#34;&gt;常用工具&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Encase&lt;/strong&gt;: 商业级取证软件, 支持快速搜索与分析;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Autopsy&lt;/strong&gt;: 开源工具, 提供案例管理与数据恢复功能;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;数据隐藏技术data-hiding-techniques&#34;&gt;数据隐藏技术(Data Hiding Techniques)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;加密(Encryption)&lt;/strong&gt;: 需密钥解密数据(如全盘加密);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;混淆(Obfuscation)&lt;/strong&gt;: 修改代码结构以隐藏功能(常见于恶意软件), 使其难以被人类或自动化工具理解或分析;
&lt;ul&gt;
&lt;li&gt;通过改变代码结构, 插入无关逻辑, 打乱变量名等手段来干扰逆向工程&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;隐写术(Steganography)&lt;/strong&gt;: 在图像/音频的LSB(Least Significant Bits)中嵌入隐藏信息;
&lt;ul&gt;
&lt;li&gt;文件的&amp;quot;冗余&amp;quot;或&amp;quot;最低有效位&amp;quot;里嵌入信息;表面上文件看似正常, 但实际包含了隐藏内容&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;水印(Watermarking)&lt;/strong&gt;: 在文件中添加抗移除标记(用于追踪或反盗版);
&lt;ul&gt;
&lt;li&gt;在文件中嵌入可追溯的标记或&amp;quot;签名&amp;quot;, 即使文件被复制或部分修改, 也能识别其来源或所有者&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;反取证技术anti-forensic-techniques&#34;&gt;反取证技术(Anti-Forensic Techniques)&lt;/h2&gt;
&lt;h3 id=&#34;安全删除secure-deletion&#34;&gt;安全删除(Secure Deletion)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;挑战&lt;/strong&gt;: 闪存(Flash)因磨损均衡(Wear-Leveling)难以完全覆盖历史数据;
&lt;ul&gt;
&lt;li&gt;即使使用&amp;quot;安全擦除&amp;quot;或&amp;quot;覆盖写&amp;quot;等方法, 也可能在某些缓存, 日志, 交换分区, 备份或未覆盖到的磁盘扇区里留下残留&lt;/li&gt;
&lt;li&gt;磨损均衡: flash 可用范围会大于 os (一些 os 认为无法写入的内存可以被 flash&lt;br&gt;
访问)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;策略&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;加密数据后丢弃密钥;
&lt;ul&gt;
&lt;li&gt;这样没有 erase key 的困难&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;与其事后再尝试彻底删除数据, 不如在一开始就尽量避免数据被写入存储设备;&lt;/li&gt;
&lt;li&gt;例如使用只在内存中运行, 不落盘的应用; 或采用端到端加密并减少日志记录; 或使用一次性匿名账号等方式, 尽量减少数据在系统上留下痕迹&lt;/li&gt;
&lt;li&gt;物理销毁介质(如研磨芯片);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;全盘加密full-disk-encryption-fde&#34;&gt;全盘加密(Full Disk Encryption, FDE)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;实现&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;protects data at rest by encrypting every sector of a storage partition&lt;br&gt;
using a secret key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;风险&lt;/strong&gt;: 冷启动攻击可窃取内存中的解密密钥;&lt;/li&gt;
&lt;li&gt;攻击模型:
&lt;ul&gt;
&lt;li&gt;当物理设备被控制, 攻击者拥有物理权限但是没有key&lt;/li&gt;
&lt;li&gt;Windows Bitlocker&lt;/li&gt;
&lt;li&gt;MacOS FileVault&lt;/li&gt;
&lt;li&gt;similar iOS and Android Features&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;如何存储密钥?
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;密钥存储&lt;/strong&gt;: 通过密码派生函数(KDF)或可信平台模块(TPM)保护密钥;
&lt;ul&gt;
&lt;li&gt;KDF: $key = E_{kdf(p)}(k)$, 其中 p 为用户指定的 PIN,  而 k 表示给硬盘&lt;br&gt;
sector 加密的密钥
&lt;ul&gt;
&lt;li&gt;缺点: 如果 boot 分区被加密了 OS 无法打开直到用户输入了 pin, OS&lt;br&gt;
不开启则用户用不了 gui; server 没有 interface, os&lt;br&gt;
没有开启则用户无法远程访问之&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;TPM: 给密钥加密通过一个可以信赖的中间平台 (trusted platform module),&lt;br&gt;
这个平台防篡改, 并且测量 boot-time code, 这个平台只有在 kernel&lt;br&gt;
没有被更改的情况下会发送key
&lt;ul&gt;
&lt;li&gt;缺点: 启动的时候会将密钥复制到 ram 中, 会被 cold-boot attack&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;预防数据记录&#34;&gt;预防数据记录&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tails Linux&lt;/strong&gt;: 默认只读模式, 避免写入敏感数据;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;浏览器无痕模式(Incognito Mode)&lt;/strong&gt;: 不保存历史与缓存;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>4. 数据链路层</title>
      <link>https://www.whoami-wesleyyou.top/2025/04/02/computer_system_basics/network/4.%20%E6%95%B0%E6%8D%AE%E9%93%BE%E8%B7%AF%E5%B1%82/</link>
      <pubDate>Wed, 02 Apr 2025 13:31:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/04/02/computer_system_basics/network/4.%20%E6%95%B0%E6%8D%AE%E9%93%BE%E8%B7%AF%E5%B1%82/</guid>
      <description>&lt;h2 id=&#34;链路层与以太网&#34;&gt;链路层与以太网&lt;/h2&gt;
&lt;h3 id=&#34;性质&#34;&gt;性质&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;基本职能&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;成帧 Framing&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;encapsulate network layer data 数据链路层会将来自网络层(第三层)的数据进行分组, 添加头部和尾部信息, 以形成一个个帧(Frame)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;链路访问 Link Access&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Medium access control (MAC) protocol defines when to transmit frames 在多点接入的介质 (例如共享式以太网, 无线网络等) 中, 多个设备可能需要同时传输数据&lt;/li&gt;
&lt;li&gt;需要负责决定什么时候由哪一个设备向链路发送数据&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;可靠交付 Reliable Delivery&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Primarily for mediums with high error rates (wireless)&lt;/li&gt;
&lt;li&gt;某些网络环境中可能会受到干扰而导致帧丢失或损坏&lt;/li&gt;
&lt;li&gt;数据链路层可以提供重传, 确认等机制, 确保帧能可靠地到达接收方
&lt;ul&gt;
&lt;li&gt;虽然TCP/IP协议栈中大多由传输层(TCP)来保证可靠性, 但一些链路层协议(如PPP)也会提供基本的可靠性功能&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;差错检测与纠正 Error detection and correction&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;帧的尾部通常会包含检错码(例如CRC校验), 用于检测帧在传输过程中是否出错&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt=&#34;link_layer_frame_concept.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/link_layer_frame_concept.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. File System</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/26/computer_system_basics/os/6.%20File%20System/</link>
      <pubDate>Wed, 26 Mar 2025 14:56:38 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/26/computer_system_basics/os/6.%20File%20System/</guid>
      <description>&lt;h2 id=&#34;文件系统抽象-file-system-abstraction&#34;&gt;文件系统抽象 File System Abstraction&lt;/h2&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;attribute&lt;/th&gt;
					&lt;th&gt;Hardware Reality&lt;/th&gt;
					&lt;th&gt;OS abstraction&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;interface&lt;/td&gt;
					&lt;td&gt;heterogeneous&lt;/td&gt;
					&lt;td&gt;uniform&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;storage objects&lt;/td&gt;
					&lt;td&gt;a few (disks)&lt;/td&gt;
					&lt;td&gt;many (files)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;name structure&lt;/td&gt;
					&lt;td&gt;simple numeric name (id)&lt;/td&gt;
					&lt;td&gt;rich name (symbolic, hierarchical, unified)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;access speed&lt;/td&gt;
					&lt;td&gt;slow&lt;/td&gt;
					&lt;td&gt;fast&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;crash resilience&lt;/td&gt;
					&lt;td&gt;unreliable&lt;/td&gt;
					&lt;td&gt;reliable&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;硬件层到-os-的转变方式&#34;&gt;硬件层到 os 的转变方式&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Heterogeneity
&lt;ul&gt;
&lt;li&gt;原因: many i/o devices, each with its own idiosyncrasy&lt;/li&gt;
&lt;li&gt;Solution: abstraction
&lt;ul&gt;
&lt;li&gt;build a common interface (Application 层和 File System 层之间设置统一接口 POSIX)&lt;/li&gt;
&lt;li&gt;write device driver for each device
&lt;ul&gt;
&lt;li&gt;Linux src code 70% is drivers&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Disk interface
&lt;ul&gt;
&lt;li&gt;硬件接口表现为 linear array of &lt;strong&gt;sectors (扇区)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;扇区为最小的物理存储单位, 每个扇区为512字节 (typically)&lt;/li&gt;
&lt;li&gt;write atomically, 要么全部写入要么全部没有写入&lt;/li&gt;
&lt;li&gt;4KB in advanced format disk&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;disk 会将逻辑 sector 映射到物理 sector
&lt;ul&gt;
&lt;li&gt;逻辑 sector: 由 OS 决定&lt;/li&gt;
&lt;li&gt;物理 sector: 由 disk 决定&lt;/li&gt;
&lt;li&gt;os 不知道 mapping&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;机械硬盘结构-disk-geometrystructure&#34;&gt;机械硬盘结构 Disk Geometry/Structure&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Platter: 磁盘盘片
&lt;ul&gt;
&lt;li&gt;Data is stored by inducing &lt;strong&gt;magnetic changes&lt;/strong&gt; to it&lt;/li&gt;
&lt;li&gt;Each platter has 2 sides, each called a &lt;strong&gt;surface&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Spindle: 磁盘主轴
&lt;ul&gt;
&lt;li&gt;围绕 spindle 旋转&lt;/li&gt;
&lt;li&gt;Spindle rotates the platters at a constant speed (unit RPM)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Track: 磁道
&lt;ul&gt;
&lt;li&gt;A circular path on a platter (&lt;strong&gt;Concentric circles of sectors&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;All tracks at the same distance from the spindle form a &lt;strong&gt;cylinder&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;每个 surface 包含上千个 track&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Cylinder: 柱面
&lt;ul&gt;
&lt;li&gt;A stack of tracks of fixed radius&lt;/li&gt;
&lt;li&gt;Heads record and sense data along cylinders&lt;br&gt;
(不同层的head指向同一个 xy 坐标位置)&lt;/li&gt;
&lt;li&gt;Generally only one head active at a time&lt;/li&gt;
&lt;li&gt;分区的最小单位&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ext2&lt;/code&gt; 文件系统分区结构体:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;struct&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;partition&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;drive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// 0x80 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cylinder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sys_type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;//分区类型 5为扩展分区 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;end_head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;end_sector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u8&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;end_cylinder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u32&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;start_sector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;//起始扇区开始计数的第n个扇区 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;u32&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nr_sectors&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;//分区中的扇区个数 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;磁盘分区是告诉操作系统&amp;quot;我这块磁盘在此分区可以访问的区域是A柱面到B柱面之间的块&amp;quot;,&lt;br&gt;
这样操作系统就知道它可以在所指定的块内进行文件数据的读, 写, 查找等操作;磁盘分区即指定分区的起始与结束柱面&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;机械硬盘访问-disk-的方式&#34;&gt;机械硬盘访问 disk 的方式&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;流程&lt;/strong&gt;: Seek, Rotate, Transfer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Seek&lt;/strong&gt;: 移动磁头到指定 track
&lt;ul&gt;
&lt;li&gt;花费时间: 1-10ms&lt;/li&gt;
&lt;li&gt;是一个物理运动过程, 很难减少时间&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotate&lt;/strong&gt;: 等待 disk 旋转到读写头的位置上
&lt;ul&gt;
&lt;li&gt;花费时间: 取决于 rpm 转速, 一般 $(rpm/2)^{-1}$ 用来表示平均等待时间&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transfer&lt;/strong&gt;: 读写数据
&lt;ul&gt;
&lt;li&gt;最终的 io 操作&lt;/li&gt;
&lt;li&gt;非常快, 依赖于 rpm 和 sector density&lt;/li&gt;
&lt;li&gt;能达到 100 MB/s 的最大传输速度&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;优化-io-性能&#34;&gt;优化 i/o 性能&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;General Strategy&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Avoid doing I/O (disk is slow)
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;方法&lt;/strong&gt;: 使用 write-back cache&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Reduce overhead (particularly seek time)
&lt;ul&gt;
&lt;li&gt;放置数据的位置很重要&lt;/li&gt;
&lt;li&gt;disk 角度要用更好的 scheduler 来改变内存访问顺序&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Amortize overhead over larger requests&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disk Scheduling&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;FIFO: 容易出现左右不断摇摆的情况, 读写头路程过大&lt;/li&gt;
&lt;li&gt;SSTF (Shortest seek time first):
&lt;ul&gt;
&lt;li&gt;选取距离目前读写头最近的 track 访问&lt;/li&gt;
&lt;li&gt;优点: 减少 seek time&lt;/li&gt;
&lt;li&gt;缺点: 会导致 starvation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;SCAN: 电梯调度算法
&lt;ul&gt;
&lt;li&gt;Sweep across disk, servicing all requests passed&lt;/li&gt;
&lt;li&gt;Like SSTF, but next seek must be in same direction&lt;/li&gt;
&lt;li&gt;Switch directions only if no further requests&lt;/li&gt;
&lt;li&gt;优点: 避免 starvation&lt;/li&gt;
&lt;li&gt;缺点: 会导致某些 track 无法访问&lt;/li&gt;
&lt;li&gt;CSCAN: only sweep in one direction&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Amortizing Overhead&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Efficiency = transfer time / (overhead + transfer time)&lt;/li&gt;
&lt;li&gt;为了达到 50%  efficiency,&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;&lt;p&gt;固态硬盘的结构 Solid State Disk (SSD, flash memory)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Increasing popular storage medium&lt;/li&gt;
&lt;li&gt;remembering data by storing charge
&lt;ul&gt;
&lt;li&gt;Low power consumption&lt;/li&gt;
&lt;li&gt;No mechanical seek time (better random read performance)&lt;/li&gt;
&lt;li&gt;Better shock resistance (抗冲击性)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;limited times of overwrite possible&lt;/li&gt;
&lt;li&gt;limited durability&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>8. 隐私权限 privacy</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/24/computer_system_basics/network/security/8.%20%E9%9A%90%E7%A7%81%E6%9D%83%E9%99%90%20privacy/</link>
      <pubDate>Mon, 24 Mar 2025 10:05:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/24/computer_system_basics/network/security/8.%20%E9%9A%90%E7%A7%81%E6%9D%83%E9%99%90%20privacy/</guid>
      <description>&lt;h2 id=&#34;数据隐私概述&#34;&gt;数据隐私概述&lt;/h2&gt;
&lt;h3 id=&#34;数据生成与收集&#34;&gt;数据生成与收集&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;数据爆炸&lt;/strong&gt;: 每天生成约2.5千亿字节数据(如社交媒体互动, 在线购物记录)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;数据聚合者&lt;/strong&gt;: 如Acxiom和Oracle, 整合多源数据构建用户画像并出售&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;隐私的定义&#34;&gt;隐私的定义&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;经典定义&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;隔离权&lt;/strong&gt;(Louis Brandeis): 免受他人侵扰的权利&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;控制权&lt;/strong&gt;: 选择何时, 如何共享个人信息的控制能力&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;保密权&lt;/strong&gt;(Richard Posner): 隐藏可能对自身不利的信息&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;自由基础&lt;/strong&gt;: 隐私是言论自由与个人自主的前提&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;隐私侵犯案例&#34;&gt;隐私侵犯案例&lt;/h2&gt;
&lt;h3 id=&#34;医疗数据泄露&#34;&gt;医疗数据泄露&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;案例&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Jane Doe因雇主获知其携带亨廷顿病基因被解雇&lt;/li&gt;
&lt;li&gt;Kate Smith基因突变检测结果导致健康保险费飙升&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;商业数据滥用&#34;&gt;商业数据滥用&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Target预测怀孕&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;通过购物模式预测用户怀孕状态, 误向未成年少女发送婴儿用品优惠券&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strava热图泄露军事基地&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;用户运动轨迹数据暴露美军在叙利亚, 阿富汗的军事基地位置&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;匿名化失效&#34;&gt;匿名化失效&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GIC链接攻击&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;通过马萨诸塞州选民登记数据(公开)与匿名医疗数据关联, 重新识别州长 William Weld&lt;/li&gt;
&lt;li&gt;关键信息: 出生日期 + 5位 zip 可识别69%美国人, 9位 zip 可识别97%&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Netflix匿名数据集破解&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;结合公开的IMDb评分数据, 重新识别用户观影记录&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;数据匿名化的局限&#34;&gt;数据匿名化的局限&lt;/h2&gt;
&lt;h3 id=&#34;匿名化流程&#34;&gt;匿名化流程&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;步骤&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;移除直接标识符(&lt;strong&gt;PII&lt;/strong&gt; Personal Information Identifier, 如姓名, 身份证号)&lt;/li&gt;
&lt;li&gt;保留准标识符(&lt;strong&gt;QID&lt;/strong&gt;, 如邮编, 年龄, 性别)和敏感属性(&lt;strong&gt;SA&lt;/strong&gt; Sensitive Attribute, 如疾病)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;示例&lt;/strong&gt;:
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;QID(邮编, 年龄, 性别)&lt;/th&gt;
					&lt;th&gt;SA(疾病)&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;47627, 59, F&lt;/td&gt;
					&lt;td&gt;卵巢癌&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;匿名化的脆弱性&#34;&gt;匿名化的脆弱性&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;链接攻击(Linkage Attack)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;利用公共数据(如选民登记, 社交媒体)与匿名数据集结合, 重新识别个体&lt;/li&gt;
&lt;li&gt;关键技术: 准标识符组合的唯一性&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;四-隐私保护法规&#34;&gt;四, 隐私保护法规&lt;/h2&gt;
&lt;h3 id=&#34;全球隐私法规&#34;&gt;全球隐私法规&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;欧盟&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GDPR&lt;/strong&gt;(通用数据保护条例): 严格限制数据收集与处理, 赋予用户&amp;quot;被遗忘权&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;美国&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CCPA&lt;/strong&gt;(加州消费者隐私法): 允许用户查询, 删除个人数据&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HIPAA&lt;/strong&gt;(健康保险流通与责任法案): 保护医疗信息隐私&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;印度&lt;/strong&gt;: &lt;strong&gt;DPDPA&lt;/strong&gt;(数字个人数据保护法): 规范企业数据使用&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;加拿大&lt;/strong&gt;: &lt;strong&gt;PIPEDA&lt;/strong&gt;(个人信息保护与电子文档法)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;政策趋势&#34;&gt;政策趋势&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;拜登行政令&lt;/strong&gt;: 推动人工智能安全与隐私保护&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AI法案&lt;/strong&gt;(欧盟): 限制高风险AI系统的数据使用&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;隐私与效用的权衡&#34;&gt;隐私与效用的权衡&lt;/h2&gt;
&lt;h3 id=&#34;核心问题&#34;&gt;核心问题&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;数据效用&lt;/strong&gt;: 数据分析(如医疗研究, 商业推荐)需依赖详细信息&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;隐私风险&lt;/strong&gt;: 详细数据易导致重新识别与滥用&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;解决方案方向&#34;&gt;解决方案方向&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;差分隐私(Differential Privacy)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;添加噪声使个体数据不可区分, 同时保留整体统计特性&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;数据聚合(Aggregation)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;发布群体统计结果(如平均值), 避免暴露个体记录&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;数据匿名化与攻击风险&#34;&gt;数据匿名化与攻击风险&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;数据匿名化(Data Anonymization)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;移除个人可识别信息(PII, Personally Identifiable Information)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;链接攻击(Linkage Attack)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;结合公开信息(如邮编, 生日, 性别)可重新识别个体, 破坏匿名化效果&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;聚合数据的隐私漏洞&#34;&gt;聚合数据的隐私漏洞&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;聚合数据风险(Aggregation Risks)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;统计查询(如计数, 均值)可能泄露个体信息&lt;/li&gt;
&lt;li&gt;示例:
&lt;ul&gt;
&lt;li&gt;查询1(A1=103)与查询2(A2=102)的差值揭示唯一用户的偏好&lt;/li&gt;
&lt;li&gt;2010年美国人口普查中, 46%人口记录通过统计数据库被重构&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;重构攻击reconstruction-attack&#34;&gt;重构攻击(Reconstruction Attack)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;核心原理&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;利用多个统计约束(如中位数, 均值)反推原始数据&lt;/li&gt;
&lt;li&gt;使用数学建模与SAT求解器(SAT Solver)生成满足所有约束的变量组合&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;案例&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;虚构区块统计表(Table 1)中, 通过年龄中位数(30)和均值(44)限制, 从317,750种组合中筛选出30种可能&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;机器学习模型的信息泄露&#34;&gt;机器学习模型的信息泄露&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;训练数据记忆(Training Data Memorization)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;模型可能泄露训练数据细节(如GPT-2生成包含真实电话号码的文本)&lt;/li&gt;
&lt;li&gt;Carlini等人研究(2021): 从大语言模型中提取训练数据&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;隐私与效用的权衡privacyutility-tradeoff&#34;&gt;隐私与效用的权衡(Privacy/Utility Tradeoff)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;核心矛盾&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;数据的&lt;strong&gt;有用性分析&lt;/strong&gt;必然泄露部分个体信息&lt;/li&gt;
&lt;li&gt;多次分析或发布导致信息泄露累积&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;信息恢复基本定律(Fundamental Law of Information Recovery)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;过多精确回答将彻底破坏隐私(Dinur &amp;amp; Nissim, 2003)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;差分隐私differential-privacy-dp&#34;&gt;差分隐私(Differential Privacy, DP)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;随机算法满足ε-DP, 当对相邻数据集(D, D&amp;rsquo;)的输出概率比满足:&lt;br&gt;

$$\frac{Pr[M(D)=o]}{Pr[M(D&#39;)=o]} \leq e^\epsilon$$&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;隐私参数\epsilon&lt;/strong&gt;: $\epsilon$ 越小, 隐私保护越强&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;核心特性&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;自动选择退出(Automatic Opt-out)&lt;/strong&gt;: 个体数据是否参与对输出影响微小;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;合理否认(Plausible Deniability)&lt;/strong&gt;: 输出无法确定个体真实数据;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;噪声注入(Noise Addition)&lt;/strong&gt;: 通过拉普拉斯分布(Laplace Distribution)添加可控噪声;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;应用案例&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;谷歌Chrome, COVID-19社区流动报告&lt;/li&gt;
&lt;li&gt;2020年美国人口普查采用DP保护数据&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;差分隐私实现机制&#34;&gt;差分隐私实现机制&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;拉普拉斯机制(Laplace Mechanism)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;对查询函数 \( f(D) \) 添加噪声:&lt;br&gt;

$$M(D) = f(D) + v$$&lt;ul&gt;
&lt;li&gt;$v$ 服从拉普拉斯分布 $\text{Lap}(\mu, b)$, 参数 $b = \frac{\Delta f}{\epsilon}$, $\Delta f$ 为函数敏感度;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;随机响应(Randomized Response)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;随机化应答流程
&lt;ul&gt;
&lt;li&gt;先掷一次, 如果是正面(head), 则&amp;quot;如实回答&amp;quot;问题&lt;/li&gt;
&lt;li&gt;如果是反面, 再掷一次骰子, 正面回答 yes, 反面回答 no&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>7. 访问权限控制攻击 Access Control</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/20/computer_system_basics/network/security/7.%20%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6%E6%94%BB%E5%87%BB%20Access%20Control/</link>
      <pubDate>Thu, 20 Mar 2025 12:58:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/20/computer_system_basics/network/security/7.%20%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6%E6%94%BB%E5%87%BB%20Access%20Control/</guid>
      <description>&lt;h2 id=&#34;访问控制基础-access-control-basics&#34;&gt;访问控制基础 Access Control Basics&lt;/h2&gt;
&lt;h3 id=&#34;核心概念&#34;&gt;核心概念&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;安全模型(Security Model)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;系统抽象, 用于描述和制定安全策略&lt;/li&gt;
&lt;li&gt;三要素: 主体(Subject), 客体(Object), 操作(Operation)
&lt;ul&gt;
&lt;li&gt;主体 Subject: users, Android Apps, Web Origins&lt;/li&gt;
&lt;li&gt;客体: &lt;strong&gt;resources&lt;/strong&gt;, including 文件, 目录, 数据库表, 设备(如UNIX文件, 进程)&lt;/li&gt;
&lt;li&gt;操作: 读, 写, 执行, 调用等&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;安全策略(Security Policy)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;定义访问控制矩阵, 明确主体对客体的权限
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;主体/客体&lt;/th&gt;
					&lt;th&gt;文件1&lt;/th&gt;
					&lt;th&gt;文件2&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Alice&lt;/td&gt;
					&lt;td&gt;读&lt;/td&gt;
					&lt;td&gt;读/写&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Bob&lt;/td&gt;
					&lt;td&gt;读&lt;/td&gt;
					&lt;td&gt;无权限&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;安全机制(Security Mechanism)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;实现安全策略的技术(如操作系统内核, 加密)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>6. binary 二进制攻击</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/12/computer_system_basics/network/security/6.%20binary%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%94%BB%E5%87%BB/</link>
      <pubDate>Wed, 12 Mar 2025 12:58:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/12/computer_system_basics/network/security/6.%20binary%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%94%BB%E5%87%BB/</guid>
      <description>&lt;h2 id=&#34;控制劫持基础control-hijacking-basics&#34;&gt;控制劫持基础(Control Hijacking Basics)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义&lt;/strong&gt;: 通过&lt;strong&gt;二进制利用(Binary Exploitation)&lt;strong&gt;破坏应用程序的信任边界, 典型手段为&lt;/strong&gt;内存损坏(Memory Corruption)&lt;/strong&gt;;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;目标&lt;/strong&gt;: 实现远程代码执行(Remote Code Execution, RCE)或提权(Privilege Escalation);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;常见攻击类型&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;缓冲区溢出(Buffer Overflow)&lt;/li&gt;
&lt;li&gt;格式化字符串攻击(Format String)&lt;/li&gt;
&lt;li&gt;整数溢出(Integer Overflow)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;内存与汇编基础memory--assembly-fundamentals&#34;&gt;内存与汇编基础(Memory &amp;amp; Assembly Fundamentals)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;内存布局&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;x64&lt;/code&gt; 架构的每一个 entry 尺寸为 64b = 8B;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;代码段(Text Segment)&lt;/strong&gt;: 存储可执行指令;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;数据段(Data Segment)&lt;/strong&gt;: 存储全局变量;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;堆(Heap)&lt;/strong&gt;: 动态分配内存;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;栈(Stack)&lt;/strong&gt;: 管理函数调用与局部变量(后进先出);
&lt;ul&gt;
&lt;li&gt;从高地址向低地址增长;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0xffffffff&lt;/code&gt; -&amp;gt; &lt;code&gt;0x00000000&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$rsp&lt;/code&gt; 地址小于等于 &lt;code&gt;$rbp&lt;/code&gt; 地址;&lt;/li&gt;
&lt;li&gt;栈上数据的填充是&lt;strong&gt;从低地址向高地址&lt;/strong&gt;进行填充的&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;关键寄存器&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;RIP&lt;/strong&gt;: pc, 指向下一条执行指令;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RSP&lt;/strong&gt;: stack top pointer, 指向栈顶;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RBP&lt;/strong&gt;: stack base pointer, 标记当前栈帧起始;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;汇编指令&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mov&lt;/code&gt;: 数据移动;
&lt;ul&gt;
&lt;li&gt;mov 的功能实际上是复制, 不会影响源数据&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mov rax, rbx&lt;/code&gt; 将 rbx 的值复制到 rax&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mov rax, 0x1234ABCD&lt;/code&gt; 将立即数 0x1234ABCD 复制到 rax&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mov rax, [rbx]&lt;/code&gt; 将 rbx &lt;strong&gt;指向的内存地址的值&lt;/strong&gt;复制到 rax&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mov rax, [rbp-8]&lt;/code&gt; 将 rbp - (8 Byte) &lt;strong&gt;指向的内存地址的值&lt;/strong&gt;复制到 rax&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;jmp&lt;/code&gt;/&lt;code&gt;call&lt;/code&gt;: 控制流跳转;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;call&lt;/code&gt;会将返回地址压栈;
&lt;ul&gt;
&lt;li&gt;call = push(rip) + jmp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;jmp&lt;/code&gt;不会返回;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;push&lt;/code&gt;/&lt;code&gt;pop&lt;/code&gt;: 栈操作;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lea&lt;/code&gt;: (Load Effective Address) 加载有效地址,&lt;br&gt;
可以将计算有效地址加载到寄存器中, 而不访问/读取地址的数据;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;lea rax, [rbp-8]&lt;/code&gt; 将 rbp - (8 Byte) &lt;strong&gt;指向的内存地址&lt;/strong&gt;复制到 rax&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sub&lt;/code&gt; 减法, 常用来给数组预留空间&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;x64-函数调用汇编-pattern&#34;&gt;&lt;code&gt;x64&lt;/code&gt; 函数调用汇编 pattern&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Caller&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;函数参数调用:
&lt;ul&gt;
&lt;li&gt;前6个参数依次存入 RDI, RSI, RDX, RCX, R8, R9;&lt;/li&gt;
&lt;li&gt;其余参数通过栈传递;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;push(rip)&lt;/li&gt;
&lt;li&gt;jmp&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Callee&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;push(rbp) 存入 stack base 地址&lt;/li&gt;
&lt;li&gt;mov(rbp, rsp) 把当前栈顶地址存入 stack base&lt;/li&gt;
&lt;li&gt;&amp;hellip; 函数体&lt;/li&gt;
&lt;li&gt;leave: mov(rsp, rbp) + pop(rbp)&lt;/li&gt;
&lt;li&gt;ret: pop(rip)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;x86-isa-寄存器分类&#34;&gt;&lt;code&gt;x86&lt;/code&gt; isa 寄存器分类&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;4个数据寄存器(EAX, EBX, ECX和EDX)&lt;/li&gt;
&lt;li&gt;2个&lt;strong&gt;变址&lt;/strong&gt;寄存器 Index Register (ESI和EDI)
&lt;ul&gt;
&lt;li&gt;主要用于存放存储单元在段内的偏移量, 用它们可实现多种存储器操作数的寻址方式&lt;/li&gt;
&lt;li&gt;32位CPU有2个32位通用寄存器ESI和EDI;其低16位对应SI和DI, 对低16位数据的存取, 不影响高16位的数据;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;2个&lt;strong&gt;指针&lt;/strong&gt;寄存器(ESP和EBP)
&lt;ul&gt;
&lt;li&gt;32位CPU有2个32位通用寄存器EBP和ESP;其低16位对应BP和SP, 对低16位数据的存取, 不影响高16位的数据;&lt;/li&gt;
&lt;li&gt;主要用于存放堆栈内存储单元的偏移量&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;6个段寄存器(ES, CS, SS, DS, FS和GS)&lt;/li&gt;
&lt;li&gt;1个指令指针寄存器(EIP) 1个标志寄存器(EFlags)&lt;/li&gt;
&lt;li&gt;9个控制寄存器(C0, C1, C2, C3, C4, C5, C6, C7, C8)其中C5~C7架构保留;&lt;/li&gt;
&lt;li&gt;3保护模式寄存器(GDTR, LDTR, IDTR)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;esi-source-index&#34;&gt;ESI (Source Index)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;通常指向操作的源数据地址(如字符串, 数组的起始位置);&lt;/li&gt;
&lt;li&gt;在字符串指令(如 MOVSB, LODSB)中, 配合 DS 段寄存器使用;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;edi-destination-index&#34;&gt;EDI (Destination Index)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;通常指向操作的目标地址(如写入数据的内存位置);&lt;/li&gt;
&lt;li&gt;在字符串指令(如 MOVSB, STOSB)中, 配合 ES 段寄存器使用;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;缓冲区溢出buffer-overflow&#34;&gt;缓冲区溢出(Buffer Overflow)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;原理&lt;/strong&gt;: 输入数据超出缓冲区边界, 覆盖返回地址或关键数据;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;示例代码漏洞&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;foo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;char&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;kt&#34;&gt;char&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;buffer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nf&#34;&gt;strcpy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;buffer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// 无边界检查
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;数据执行保护-dep-防御&#34;&gt;数据执行保护 (DEP) 防御&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;内存分区的写与执行权限隔离(Write XOR Execute 原则)
&lt;ul&gt;
&lt;li&gt;一段内存要么只能写入读取要么只能执行而不能修改&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;可以有效防御 最基础的 buffer overflow 和 stack shellcode 攻击&lt;/li&gt;
&lt;li&gt;无法防御下面的 rop 攻击&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;return-oriented-programming-rop&#34;&gt;Return Oriented Programming (ROP)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;核心思想&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;利用现有代码片段(Gadgets)构建攻击链, 不会注入执行代码, 只会覆盖返回地址&lt;/li&gt;
&lt;li&gt;Gadget特征: 以&lt;code&gt;ret&lt;/code&gt;结尾的短指令序列&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ROP链构建&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;示例Gadgets: &lt;code&gt;mov rax, 0x10; ret&lt;/code&gt;, &lt;code&gt;add rax, rbp; ret&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;通过栈控制指令流(链式调用Gadgets)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;分类&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;ret2libc: 寻找合适的 ret 附近的汇编代码, 找到 reg&lt;br&gt;
填充数值合适的位置进行返回地址覆盖, 返回地址指向 libc 中的函数&lt;/li&gt;
&lt;li&gt;ret2syscall: 同理, 返回地址指向系统调用函数&lt;/li&gt;
&lt;li&gt;ret2shellcode: 返回地址指向 shellcode 的位置, 执行 shellcode&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;防御: Extraneous Function Removal&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;在编译/链接的时候删除没有额比引用的函数, 变量或者库代码来减少 &lt;strong&gt;(不是消除所有)&lt;/strong&gt; 攻击面&lt;/li&gt;
&lt;li&gt;由于仍然会剩下使用的函数, 还是会遭受 rop 攻击&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;x86的指令弱点&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;在 x86&lt;br&gt;
架构下指令长度是不确定的, 因此攻击者可以从意料之外的字节开始解码来构造额外的&lt;br&gt;
gadget , 即任意包含 &lt;code&gt;c3&lt;/code&gt; 的字节都可以被当做 &lt;code&gt;ret&lt;/code&gt; 指令来使用, 增大了攻击面&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ROP Chain&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;对于多输入函数如 &lt;code&gt;execve(&amp;quot;/bin/sh&amp;quot;,NULL,NULL)&lt;/code&gt; 需要同时填充 &lt;code&gt;rdi&lt;/code&gt;, &lt;code&gt;rsi&lt;/code&gt;, &lt;code&gt;rdx&lt;/code&gt; 3 个寄存器, 可以通过连续覆盖不同地址的返回地址来实现连续覆盖并且确保多个 reg 数值合理&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ASLR 防御&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;地址空间随机化 (Address Space Layout Randomization)&lt;br&gt;
指程序在运行时在运行的时候随机加入一个随机的偏移量, 使得攻击者无法预测函数的地址&lt;/li&gt;
&lt;li&gt;随机化代码段, 堆, 栈的基地址&lt;/li&gt;
&lt;li&gt;局限性:
&lt;ul&gt;
&lt;li&gt;部分代码段未完全随机化&lt;/li&gt;
&lt;li&gt;通过内存泄露 (如 Heartbleed 漏洞) 获取地址&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Fine-grained ASLR&lt;/code&gt; 细粒度随机化, 随机化函数内的指令地址&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stack Canaries 栈金丝雀&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;在函数返回地址的前面添加一个保护位&lt;/li&gt;
&lt;li&gt;每次返回之前对 canary xor initial_value 进行校验, 如果不一致 (xor = 1) 则说明栈被破坏&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;buffer-over-read&#34;&gt;Buffer Over-read&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;原理&lt;/strong&gt;: 读取超出缓冲区边界的数据, 可能导致敏感信息泄露;
&lt;ul&gt;
&lt;li&gt;攻击者可以首先读取 canary 然后合理覆盖&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Heartbleed 漏洞: 读取超长数据导致内存泄露;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;整数溢出与类型混淆&#34;&gt;整数溢出与类型混淆&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;数值范围: 对于 &lt;code&gt;unsigned int&lt;/code&gt; 类型的变量, 最大值为 &lt;code&gt;2^32-1&lt;/code&gt;, 那么如果要执行&lt;br&gt;
&lt;code&gt;(2^32 - 1) * 4&lt;/code&gt; 计算溢出得到 &lt;code&gt;0xFFFFFFFC&lt;/code&gt;, 这会导致分配的内存小于预期;
&lt;ul&gt;
&lt;li&gt;对于 &lt;code&gt;signed int&lt;/code&gt; 类型的变量, 最大值为 &lt;code&gt;2^31-1&lt;/code&gt;, 如果执行 &lt;code&gt;(2^31 - 1) * 4&lt;/code&gt; 计算溢出得到 &lt;code&gt;0xFFFFFFFC&lt;/code&gt; 为负数, 这会导致分配的内存小于预期;&lt;/li&gt;
&lt;li&gt;常见的场景是 &lt;code&gt;malloc(len * sizeof(int))&lt;/code&gt; 中 &lt;code&gt;len&lt;/code&gt; 过大 (不超过 uint 上限) 导致 len * 4 超过上限而被覆盖&lt;/li&gt;
&lt;li&gt;常用数值: &lt;code&gt;0x40000001&lt;/code&gt; 如果 * 4 就会得到 &lt;code&gt;0x00000004&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;符号类型混淆(有符号数误用为无符号数)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;防御: 使用安全类型(如&lt;code&gt;size_t&lt;/code&gt;)和边界检查&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;四-其他攻击技术&#34;&gt;四, 其他攻击技术&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;格式化字符串漏洞&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;利用&lt;code&gt;printf(user_input)&lt;/code&gt;泄露内存或篡改数据&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use-After-Free(UAF)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;释放后重用内存对象(常见于多线程环境)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;缓冲区越界读取(Buffer Over-read)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;示例: Heartbleed漏洞(读取超长数据泄露敏感信息)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;五-防御与自动化工具&#34;&gt;五, 防御与自动化工具&lt;/h2&gt;
&lt;h3 id=&#34;1-自动化漏洞检测&#34;&gt;1. 自动化漏洞检测&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;模糊测试(Fuzzing)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;生成随机/畸形输入触发程序崩溃&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;静态分析工具&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;检测不安全函数(如&lt;code&gt;strcpy&lt;/code&gt;), 类型混淆&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;动态分析工具&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;内存检查(如Valgrind)捕获越界访问, UAF&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;2-安全编码实践&#34;&gt;2. 安全编码实践&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;替换危险函数: &lt;code&gt;strncpy&lt;/code&gt;替代&lt;code&gt;strcpy&lt;/code&gt;, &lt;code&gt;snprintf&lt;/code&gt;替代&lt;code&gt;sprintf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;启用编译选项: &lt;code&gt;-fstack-protector&lt;/code&gt;(栈金丝雀), &lt;code&gt;-pie&lt;/code&gt;(ASLR支持)&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;六-攻击链与综合利用&#34;&gt;六, 攻击链与综合利用&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;多漏洞组合利用(Bug Chains)&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;示例:
&lt;ol&gt;
&lt;li&gt;缓冲区溢出泄露ASLR偏移&lt;/li&gt;
&lt;li&gt;ROP链禁用DEP&lt;/li&gt;
&lt;li&gt;注入并执行Shellcode&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;现实案例&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Heartbleed(OpenSSL漏洞): 越界读取服务器内存&lt;/li&gt;
&lt;li&gt;返回libc攻击: 调用&lt;code&gt;execv(&amp;quot;/bin/sh&amp;quot;)&lt;/code&gt;获取Shell&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;gdb-指令简介&#34;&gt;GDB 指令简介&lt;/h2&gt;
&lt;h3 id=&#34;break-point-断点设置&#34;&gt;break point 断点设置&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-gdb&#34; data-lang=&#34;gdb&#34;&gt;break *0xffffffff # 设置断点在指定地址, 没有执行该行
break vulnerable  # 设置断点在函数 vulnerable 处, 执行到该行
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;显示地址内存&#34;&gt;显示地址内存&lt;/h3&gt;
&lt;p&gt;以下指令需要在断点中才能显示&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. 内存空间抽象 Address Space</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/os/5.%20%E5%86%85%E5%AD%98%E7%A9%BA%E9%97%B4%E6%8A%BD%E8%B1%A1%20Address%20Space/</link>
      <pubDate>Tue, 11 Mar 2025 14:56:38 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/os/5.%20%E5%86%85%E5%AD%98%E7%A9%BA%E9%97%B4%E6%8A%BD%E8%B1%A1%20Address%20Space/</guid>
      <description>&lt;h2 id=&#34;地址空间与抽象-address-space-and-abstract&#34;&gt;地址空间与抽象 Address Space and Abstract&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;os视角&lt;/strong&gt;: 地址空间是在 process&lt;br&gt;
内部的用于不同进程之间对物理内存高效, 安全访问的一种抽象方式;
&lt;ul&gt;
&lt;li&gt;Process = one or more threads running in an address space;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;组成&lt;/strong&gt;: 包括 code, data, heap, stack&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phisical Machine Interface&lt;/strong&gt;: 多个任务共享同一个物理内存, 比如一个 config 文件&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Virtual Machine Interface&lt;/strong&gt;: 每个任务有独立的虚拟内存空间&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;地址空间抽象的三条准则&#34;&gt;地址空间抽象的三条准则&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Address Space Independence:&lt;/li&gt;
&lt;li&gt;Protection (controlled isolation):&lt;/li&gt;
&lt;li&gt;Large Address Space:&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;单进程执行缺陷&#34;&gt;单进程执行缺陷&lt;/h3&gt;
&lt;h3 id=&#34;多个进程执行&#34;&gt;多个进程执行&lt;/h3&gt;
&lt;h3 id=&#34;动态地址翻译-dynamic-address-translation&#34;&gt;动态地址翻译 Dynamic Address Translation&lt;/h3&gt;
&lt;h4 id=&#34;method-1-base--bound&#34;&gt;Method 1: Base + Bound&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;机制&lt;/li&gt;
&lt;li&gt;优点&lt;/li&gt;
&lt;li&gt;缺点&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;method-2-segmentation&#34;&gt;Method 2: Segmentation&lt;/h4&gt;
&lt;h4 id=&#34;method-3-paging&#34;&gt;Method 3: Paging&lt;/h4&gt;
&lt;h2 id=&#34;页地址转换方式&#34;&gt;页地址转换方式&lt;/h2&gt;
&lt;h2 id=&#34;页替换基础page-replacement-basics&#34;&gt;页替换基础(Page Replacement Basics)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;触发条件&lt;/strong&gt;: 当发生页错误(Page Fault)且物理页框(Page Frame)已满时, 需选择牺牲页(Victim Page)替换;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;目标&lt;/strong&gt;: 最小化页错误率(Page Fault Rate), 提升虚拟内存(Virtual Memory)性能;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;关键概念&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;局部性原理(Locality)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;时间局部性(Temporal Locality): 近期访问的页可能再次被访问;&lt;/li&gt;
&lt;li&gt;空间局部性(Spatial Locality): 邻近地址的页可能被连续访问;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;页替换算法page-replacement-algorithms&#34;&gt;页替换算法(Page Replacement Algorithms)&lt;/h3&gt;
&lt;h4 id=&#34;1-先进先出first-in-first-out-fifo&#34;&gt;1. 先进先出(First-In First-Out, FIFO)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;机制&lt;/strong&gt;: 淘汰最早进入内存的页;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;缺陷&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Belady异常(Belady&amp;rsquo;s Anomaly)&lt;/strong&gt;: (主要是fifo情况会导致)增加num of page in memory 可能增加 page fault;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;2-最优替换optimal-replacement-opt&#34;&gt;2. 最优替换(Optimal Replacement, OPT)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;机制&lt;/strong&gt;: 淘汰 &lt;strong&gt;未来&lt;/strong&gt; 最长时间不被访问的页(需预知未来访问序列);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;困难&lt;/strong&gt;: 很难预知未来访问模式, 仅作为理论基准;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;意义&lt;/strong&gt;: 作为理论 opt 基准(Yardstick)评估其他算法;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;3-最近最少使用least-recently-used-lru&#34;&gt;3. 最近最少使用(Least Recently Used, LRU)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;机制&lt;/strong&gt;: 淘汰最久未被访问的页, 基于最优 temporal locality, 对比 opt&lt;br&gt;
更加展现&lt;strong&gt;过去&lt;/strong&gt;的访问模式;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;最不利于 lru 算法的访问顺序&lt;/strong&gt;: 正序访问一个大于物理内存大小的page array,&lt;br&gt;
使得每次访问都需要替换一个页;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implement Problem&lt;/strong&gt;:
&lt;ol&gt;
&lt;li&gt;记录每次调用的时候的 cpu 时间, evict 的时候找到时间最老的 page: 占用内存更大, 且 Scanning 所有优先级的时间开销很大;&lt;/li&gt;
&lt;li&gt;使用一个 doubly-linked list, 每次访问将当前 node 放到尾部: 内存开销很大&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;4-时钟队列算法clock-queue-algorithm&#34;&gt;4. 时钟队列算法(Clock Queue Algorithm)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;MMU 存储每个 page 的访问位(Accessed/&lt;strong&gt;Referenced&lt;/strong&gt; Bit);&lt;/li&gt;
&lt;li&gt;evict 未被访问的页(ref=0), 访问过的页 ref = 0 并跳过(防止死循环);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;二次机会(Second-Chance)&lt;/strong&gt;: 别称&lt;/li&gt;
&lt;li&gt;evict 页处理
&lt;ul&gt;
&lt;li&gt;data 写回? 可能有 write-back 和 write-through 策略;
&lt;ul&gt;
&lt;li&gt;write-back: 仅dirty页且非swap数据页需写回, 需要额外记录 dirty-bit&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;页替换优化optimizations&#34;&gt;页替换优化(Optimizations)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;脏位管理(Dirty Bit Management)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;脏位(Dirty Bit)&lt;/strong&gt;: 标记页是否被修改, 或者说内存中的数据和磁盘中的数据是否一致;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;写回策略(Write-Back)&lt;/strong&gt;: 仅脏页需写回;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;硬件支持&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;访问位(Accessed Bit)&lt;/strong&gt;: 由内存管理单元(MMU)自动更新, 用于近似LRU;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;页表项(Page Table Entry, PTE)&lt;/strong&gt;: 包含物理页号, 有效位(Valid), 驻留位(Resident), 保护位(Protection), 脏位(Dirty), 访问位(Accessed);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;pte-优化策略&#34;&gt;pte 优化策略&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;valid&lt;/strong&gt;: mmu 可以不用保存 valid bit, 而由 os (Pager) 根据 r/w 权限来判断是否&lt;br&gt;
valid, 即将 invalid page 标记为 non-resident, 只需要判断是否 resident 就行;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;resident&lt;/strong&gt;: mmu 可以不用保存 resident bit, 而由 os (Pager) 根据 r/w 来判断是否 resident,&lt;br&gt;
即将 non-resident 标记为 r=0, w=0, 只需要判断是否 resident 就行;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dirty&lt;/strong&gt;: mmu 可以不用保存 dirty bit, 而由 os (Pager) 自行记录是否 dirty&lt;br&gt;
就可以, 即将每次写入的 page 标记为 dirty&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ref&lt;/strong&gt;: mmu 可以不用保存 ref bit, 而由 os (Pager) 自行记录是否 accessed&lt;br&gt;
就可以, 即将每次访问的 page 标记为 accessed&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;算法对比与选择&#34;&gt;算法对比与选择&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;算法&lt;/th&gt;
					&lt;th&gt;优点&lt;/th&gt;
					&lt;th&gt;缺点&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;FIFO&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;实现简单&lt;/td&gt;
					&lt;td&gt;Belady异常, 忽略访问模式&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;OPT&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;理论最优&lt;/td&gt;
					&lt;td&gt;不可实现(需预知未来)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;LRU&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;近似OPT, 利用时间局部性&lt;/td&gt;
					&lt;td&gt;实现开销大, 需硬件支持&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;时钟算法(Clock)&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;低开销, 近似LRU&lt;/td&gt;
					&lt;td&gt;可能淘汰频繁访问页(循环扫描)&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;</description>
    </item>
    <item>
      <title>5. 密码攻击 Password Attack</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/network/security/5.%20%E5%AF%86%E7%A0%81%E6%94%BB%E5%87%BB%20Password%20Attack/</link>
      <pubDate>Tue, 11 Mar 2025 14:01:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/network/security/5.%20%E5%AF%86%E7%A0%81%E6%94%BB%E5%87%BB%20Password%20Attack/</guid>
      <description>&lt;h2 id=&#34;认证基础authentication-basics&#34;&gt;认证基础(Authentication Basics)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义&lt;/strong&gt;: 确认实体声明的属性真实性, 常用于验证用户或设备的&lt;strong&gt;身份(Identity)&lt;/strong&gt;;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;目的&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;实施访问控制策略(Access Control Policies)&lt;/li&gt;
&lt;li&gt;防止冒充攻击(Impersonation Attacks)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;示例&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;网站通过密码认证用户&lt;/li&gt;
&lt;li&gt;手机通过指纹识别机主&lt;/li&gt;
&lt;li&gt;浏览器通过证书验证服务器&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;认证方式authentication-factors&#34;&gt;认证方式(Authentication Factors)&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;所知之物(Something You Know)&lt;/strong&gt;&lt;br&gt;
密码(Password), PIN码, 密钥&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;所有之物(Something You Have)&lt;/strong&gt;&lt;br&gt;
手机, 安全令牌(Security Token), 身份证&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;所是之物(Something You Are)&lt;/strong&gt;&lt;br&gt;
生物特征(Biometrics): 指纹, 面部识别(FaceID), 虹膜扫描&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h2 id=&#34;密码问题与防御password-problems--defenses&#34;&gt;密码问题与防御(Password Problems &amp;amp; Defenses)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;常见弱密码问题&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;用户倾向于选择简单密码(如&lt;code&gt;123456&lt;/code&gt;, &lt;code&gt;password&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;防御建议&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;用户&lt;/strong&gt;: 使用密码管理器(Password Manager), 启用双因素认证(2FA/MFA);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;开发者&lt;/strong&gt;: 避免强制密码复杂度规则, 支持第三方登录(OAuth);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;在线密码猜测攻击(Online Guessing)&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;攻击方法&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;单个网站多次测试登陆: 会被 Lock Account after n Guess&lt;br&gt;
方法防御, 但是这个方法会有一定的缺点: 攻击者可以暴力测试密码让原用户&lt;br&gt;
被拒绝服务&lt;/li&gt;
&lt;li&gt;多个网站测试同一密码&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;防御措施&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;账户锁定(Lock Account after n Guess): 缺点如上&lt;/li&gt;
&lt;li&gt;登录速率限制(Rate-Limit): 一定时间内限制登录次数, 可以有效解决上述问题&lt;/li&gt;
&lt;li&gt;异常检测 (Anomaly Detection): 检测异常登录行为, 如异地 (短时间内登录地点变化很大) 登录&lt;/li&gt;
&lt;li&gt;CAPTCHA验证(Completely Automated Public Turing Test): 防止机器人攻击,&lt;br&gt;
生成的密码让人类很容易解决但是很难被机器人解决&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>3. 网络层</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/network/3.%20%E7%BD%91%E7%BB%9C%E5%B1%82/</link>
      <pubDate>Tue, 11 Mar 2025 12:08:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/11/computer_system_basics/network/3.%20%E7%BD%91%E7%BB%9C%E5%B1%82/</guid>
      <description>&lt;h2 id=&#34;ip-基础与报文格式&#34;&gt;IP 基础与报文格式&lt;/h2&gt;
&lt;h3 id=&#34;网络层基础&#34;&gt;网络层基础&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;核心功能&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;寻址(Addressing)&lt;/li&gt;
&lt;li&gt;转发(Forwarding): 将数据包定向到正确接口(基于本地转发表);&lt;/li&gt;
&lt;li&gt;路由(Routing): 全局计算转发表(通过路由协议);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;架构分层&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;数据平面(Data Plane)&lt;/strong&gt;: 处理单个数据包的转发(快速, 本地决策);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;控制平面(Control Plane)&lt;/strong&gt;: 计算转发表的分布式算法(全局, 慢速);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;ip协议核心设计&#34;&gt;IP协议核心设计&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;IP数据包结构&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt;:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;字段名&lt;/th&gt;
					&lt;th&gt;位数&lt;/th&gt;
					&lt;th&gt;功能&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;版本号(Version)&lt;/td&gt;
					&lt;td&gt;4&lt;/td&gt;
					&lt;td&gt;标识IP版本(如IPv4=4);&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;头部长度(IHL)&lt;/td&gt;
					&lt;td&gt;4&lt;/td&gt;
					&lt;td&gt;以32位&lt;strong&gt;word&lt;/strong&gt;为单位的&lt;strong&gt;头部长度&lt;/strong&gt;(如无选项时为5, 对应20字节, 最长 60B 因为 IHL 最长 4bit 即 0xF word = 60B);&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;服务类型(ToS/DSCP)&lt;/td&gt;
					&lt;td&gt;8&lt;/td&gt;
					&lt;td&gt;定义优先级或拥塞通知(如ECN);&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;总长度(Total Length)&lt;/td&gt;
					&lt;td&gt;16&lt;/td&gt;
					&lt;td&gt;整个IP包的总字节数(最大65535字节);&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;生存时间(TTL)&lt;/td&gt;
					&lt;td&gt;8&lt;/td&gt;
					&lt;td&gt;防环路, 每经过一跳减1, 归零时丢弃包;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;协议(Protocol)&lt;/td&gt;
					&lt;td&gt;8&lt;/td&gt;
					&lt;td&gt;标识上层协议(如TCP=6, UDP=17);&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;头部校验和(Checksum)&lt;/td&gt;
					&lt;td&gt;16&lt;/td&gt;
					&lt;td&gt;仅校验头部完整性, 每跳重新计算;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;源/目的IP地址&lt;/td&gt;
					&lt;td&gt;32×2&lt;/td&gt;
					&lt;td&gt;端到端通信的基础;&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;分片相关字段&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;标识符(Identification)&lt;/strong&gt;: 唯一标记同一原始包的分片;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;标志位(Flags)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;DF(Don&amp;rsquo;t Fragment): 禁止分片(若MTU不足则丢弃并返回ICMP错误);&lt;/li&gt;
&lt;li&gt;MF(More Fragments): 标记是否为最后一个分片;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;偏移量(Fragment Offset)&lt;/strong&gt;: 以8字节为单位, 指示分片在原始包中的位置;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TTL (8b): 防止 loop&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;目的&lt;/strong&gt;: 防止数据包在网络中无限循环;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;实现&lt;/strong&gt;: 每经过一个路由器, TTL 值减1, 当 TTL 为0 时, 路由器丢弃该包并发送 &lt;strong&gt;Time exceeded&lt;/strong&gt; 错误消息给 src;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;校验和(Checksum)&lt;/strong&gt;: 仅校验头部, 每经过一个路由器需重新计算;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;由于 header 的 ttl 在每一个路由器都会发生变化, 所以每一个路由器都需要重新计算校验和&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type of Service (ToS)&lt;/strong&gt;: 支持 优先级和服务质量(QoS) 特殊处理&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;目的&lt;/strong&gt;: 可针对服务 priority, congestion notification 特殊处理一些包;&lt;/li&gt;
&lt;li&gt;现在称为 DSCP (Differentiated Service Code Point)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;: 可选字段, 用于调试或特殊需求;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;示例&lt;/strong&gt;: 记录路由(Record Router), 时间戳(Timestamp), Strict/Loose Source Route 等;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Protocol&lt;/strong&gt;: 指明上层协议类型;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;常见值&lt;/strong&gt;: TCP=6, UDP=17, ICMP=1;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;作用&lt;/strong&gt;: help with demultiplexing at the destination;
&lt;ul&gt;
&lt;li&gt;接收方 task: 1. 根据 transport layer header 来确定上层执行函数; 2. 发送&lt;br&gt;
response 到src&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>John the Ripper</title>
      <link>https://www.whoami-wesleyyou.top/2025/03/07/computer_system_basics/network/security/John-the-Ripper/</link>
      <pubDate>Fri, 07 Mar 2025 13:55:47 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/03/07/computer_system_basics/network/security/John-the-Ripper/</guid>
      <description>&lt;h2 id=&#34;简介和背景&#34;&gt;简介和背景&lt;/h2&gt;
&lt;p&gt;由于Linux是Internet最流行的服务器操作系统,因此它的安全性备受关注,这种安全主要靠口令实现&lt;/p&gt;
&lt;p&gt;Linux使用一个单向函数 &lt;code&gt;crypt()&lt;/code&gt; 来加密用户口令;单向函数 &lt;code&gt;crypt()&lt;/code&gt; 从数学原理上保证了从加密的密文得到加密前的明文是不可能的或是非常困难的; 当用户登录系统时,系统并不是去解密已加密的口令, 而是将输入的口令明文字符串传给加密函数, 将加密函数的输出与 &lt;code&gt;/etc/passwd&lt;/code&gt; 文件中该用户的PASSWORD域进行比较,若匹配成功,则允许用户登录系统;&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. Network 基础</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/19/computer_system_basics/network/security/4.%20Network%20%E5%9F%BA%E7%A1%80%20%28%E8%AF%A6%E8%A7%81489%29/</link>
      <pubDate>Wed, 19 Feb 2025 09:27:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/19/computer_system_basics/network/security/4.%20Network%20%E5%9F%BA%E7%A1%80%20%28%E8%AF%A6%E8%A7%81489%29/</guid>
      <description>&lt;h2 id=&#34;物理层攻击&#34;&gt;物理层攻击&lt;/h2&gt;
&lt;p&gt;&lt;img alt=&#34;physical_layer_concept.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/physical_layer_concept.png&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;数据链路层攻击&#34;&gt;数据链路层攻击&lt;/h2&gt;
&lt;h3 id=&#34;ethernet&#34;&gt;Ethernet&lt;/h3&gt;
&lt;p&gt;以太网(Ethernet) 是最常见的数据链路层协议, 用于在本地网络中传输数据:&lt;br&gt;
• 通过 MAC 地址寻址(而不是 IP 地址);&lt;br&gt;
• 传输单位是帧(Frame), 而不是 IP 包;&lt;br&gt;
• 可以在有线(RJ45)或无线(Wi-Fi)网络上运行;&lt;br&gt;
• 每个以太网帧大约 1500 字节&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. 死锁 Deadlock</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/18/computer_system_basics/os/4.%20%E6%AD%BB%E9%94%81%20Deadlock/</link>
      <pubDate>Tue, 18 Feb 2025 23:04:38 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/18/computer_system_basics/os/4.%20%E6%AD%BB%E9%94%81%20Deadlock/</guid>
      <description>&lt;h2 id=&#34;死锁简介-introduction-to-deadlock&#34;&gt;&lt;strong&gt;死锁简介 (Introduction to Deadlock)&lt;/strong&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义 (Definition)&lt;/strong&gt;: 线程因循环等待资源 (Cyclical Resource Waiting) 而无限期阻塞的状态.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;为了确保程序合理运行的必要条件&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;安全性 (Safety)&lt;/strong&gt;: 所有操作必须正确 (避免非法交错).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;活性 (Liveness)&lt;/strong&gt;: 操作必须持续进行; 死锁违反活性.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;Fix Attempts&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ol&gt;
&lt;li&gt;Ignore: 1. 0S会自己完成的; 2. 这个方法占用cpu时间为0;&lt;/li&gt;
&lt;li&gt;Detect and Fix:&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;&lt;ol&gt;
&lt;li&gt;Kill the deadlock threads:会导致一定!的 invariant条件破裂&lt;/li&gt;
&lt;li&gt;Rollback actions and then try again:某些指令如 output 并不能 roll back&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;Prevent: 得知道有哪些造成 deadlock 的必要条件&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;aside class=&#34;note-callout callout-concept&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;&lt;strong&gt;等待图 (Wait-for Graph)&lt;/strong&gt;:&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;顶点 (Vertices)&lt;/strong&gt;: 线程和资源.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;边 (Edges)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;线程 → 资源 (线程等待资源).&lt;/li&gt;
&lt;li&gt;资源 → 线程 (资源被线程持有).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;循环检测 (Cycle Detection)&lt;/strong&gt;: 图中存在循环即表明死锁.&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;hr&gt;
&lt;h2 id=&#34;死锁的构成要素-components-of-deadlock&#34;&gt;&lt;strong&gt;死锁的构成要素 (Components of Deadlock)&lt;/strong&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;有限资源 (Limited Resources)&lt;/strong&gt;: 线程所需的实体 (如锁 Locks, CPU, Memory).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;不可剥夺 (No Preemption)&lt;/strong&gt;: 不能强制线程放弃资源. &lt;strong&gt;Preemption&lt;/strong&gt;: no&lt;br&gt;
indefinite waiting, 系统不能强制从资源占有者处释放资源&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;获取且等待 (Hold and Wait)&lt;/strong&gt;: 线程持有资源同时等待其他资源.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;循环等待 (Circular Wait)&lt;/strong&gt;: 线程A等待线程B, 线程B等待线程C, 线程C等待线程A.&lt;/li&gt;
&lt;/ul&gt;
&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;Fix Attempts&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;ol&gt;
&lt;li&gt;Limited Resources: increase the number of resources&lt;/li&gt;
&lt;li&gt;No Preemption: Enable preemption,&lt;/li&gt;
&lt;li&gt;Hold and Wait: 1. Move the resources acquisition to the first step; 2.&lt;br&gt;
Acquire all the resources atomically, if not, release all its resources and retry&lt;/li&gt;
&lt;/ol&gt;
&lt;aside class=&#34;note-callout callout-note&#34;&gt;
    &lt;div class=&#34;callout-title&#34;&gt;仍然会导致问题:&lt;br&gt;&lt;/div&gt;
    &lt;div class=&#34;callout-body&#34;&gt;&lt;p&gt;如果对于中间用户左右资源被左右用户轮流占用,则中间用户本身也无法获取资源.&lt;br&gt;
解决方案: 定义一个 &lt;strong&gt;Global Ordering&lt;/strong&gt; 来规定资源的获取顺序.&lt;/p&gt;&lt;/div&gt;
  &lt;/aside&gt;&lt;/div&gt;
  &lt;/aside&gt;</description>
    </item>
    <item>
      <title>3. 信号量 Semaphore</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/18/computer_system_basics/os/3.%20%E4%BF%A1%E5%8F%B7%E9%87%8F%20Semaphore/</link>
      <pubDate>Tue, 18 Feb 2025 23:04:25 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/18/computer_system_basics/os/3.%20%E4%BF%A1%E5%8F%B7%E9%87%8F%20Semaphore/</guid>
      <description>&lt;h2 id=&#34;信号量基础-semaphore-basics&#34;&gt;&lt;strong&gt;信号量基础 (Semaphore Basics)&lt;/strong&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;定义 (Definition)&lt;/strong&gt;: 一种抽象的整数计数器 (Integer Counter), 用于控制多线程对共享资源的访问.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;核心操作 (Core Operations)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;down()&lt;/code&gt; &lt;strong&gt;(或 P()/wait())&lt;/strong&gt;: 原子性地减少计数器值; 若值为0则阻塞线程.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;up()&lt;/code&gt; &lt;strong&gt;(或 V()/signal())&lt;/strong&gt;: 原子性地增加计数器值; 唤醒等待的线程.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;类型 (Types)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;二进制信号量 (Binary Semaphore)&lt;/strong&gt;: 值仅0或1, 初始化为 1 的情况下等效于锁 (Lock).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;计数信号量 (Counting Semaphore)&lt;/strong&gt;: 值可为任意非负整数, 表示资源的可用数量.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;信号量的应用场景-applications-of-semaphores&#34;&gt;&lt;strong&gt;信号量的应用场景 (Applications of Semaphores)&lt;/strong&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;互斥 (Mutual Exclusion)&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;semaphore&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;down&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// 临界区 (Critical Section)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;up&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;顺序约束 (Ordering Constraints)&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;例如确保线程A先执行任务再启动线程B, 功能类似cv:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;semaphore&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// 线程A
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;taskA&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;up&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// 线程B
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;down&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;taskB&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>3. HTTP 攻击防御</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/security/3.%20HTTP%20%E6%94%BB%E5%87%BB%E9%98%B2%E5%BE%A1/</link>
      <pubDate>Thu, 13 Feb 2025 16:49:47 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/security/3.%20HTTP%20%E6%94%BB%E5%87%BB%E9%98%B2%E5%BE%A1/</guid>
      <description>&lt;h2 id=&#34;tls-transport-layer-security&#34;&gt;TLS Transport Layer Security&lt;/h2&gt;
&lt;p&gt;在传输层中 tcp 协议并不能保证信息的 confidentiality, integrity, authenticity 因此在 传输层和应用层之间加了一层专门用来保护安全的协议&lt;br&gt;
&lt;img alt=&#34;tls_concept.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/tls_concept.png&#34;&gt;&lt;br&gt;
tls 协议假设用户端和服务器端是安全的，而沟通信道 network 是危险的 (malicious) 并且在网络上有两种攻击模式:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;passive: only eavesdrops&lt;/li&gt;
&lt;li&gt;active: can see inject modify or block&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;tls-功能&#34;&gt;TLS 功能&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;confidentiality and integrity protection for app data&lt;/li&gt;
&lt;li&gt;client 可以确保服务器的身份 (authenticate)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;无法做到&#34;&gt;无法做到&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;用户端/服务器内病毒&lt;/li&gt;
&lt;li&gt;应用软件本身脆弱性&lt;/li&gt;
&lt;li&gt;社会工程学等信息泄漏&lt;/li&gt;
&lt;li&gt;浏览记录、网页元数据分析&lt;/li&gt;
&lt;li&gt;Denial of Service (DoS) 攻击&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;发展历史&#34;&gt;发展历史&lt;/h3&gt;
&lt;p&gt;现代 tls 拥有超过 30 年的研制历史&lt;br&gt;
&lt;img alt=&#34;ssl_history.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/ssl_history.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Web 攻击与防御</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/security/2.%20Web%20%E6%94%BB%E5%87%BB%E4%B8%8E%E9%98%B2%E5%BE%A1/</link>
      <pubDate>Thu, 13 Feb 2025 16:47:23 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/security/2.%20Web%20%E6%94%BB%E5%87%BB%E4%B8%8E%E9%98%B2%E5%BE%A1/</guid>
      <description>&lt;h1 id=&#34;web平台安全知识点大纲&#34;&gt;Web平台安全知识点大纲&lt;/h1&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1-web安全目标与攻击模型&#34;&gt;1. Web安全目标与攻击模型&lt;/h2&gt;
&lt;h3 id=&#34;11-核心目标&#34;&gt;1.1 核心目标&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;用户保护&lt;/strong&gt;: 防范恶意网站和网络攻击;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;站点隔离&lt;/strong&gt;: 确保不同站点间数据隔离;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;完整性&lt;/strong&gt;: 站点A无法篡改站点B的用户会话;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;机密性&lt;/strong&gt;: 站点A无法窃取站点B的用户数据;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;12-攻击模型&#34;&gt;1.2 攻击模型&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;恶意网站&lt;/strong&gt;: 通过钓鱼或注入攻击危害用户;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;恶意外部资源&lt;/strong&gt;: 第三方脚本/广告携带攻击载荷;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;网络攻击者&lt;/strong&gt;: 窃听或篡改HTTP流量;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;恶意软件攻击者&lt;/strong&gt;: 控制用户设备或浏览器;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-web基础技术&#34;&gt;2. Web基础技术&lt;/h2&gt;
&lt;h3 id=&#34;21-html与安全转义&#34;&gt;2.1 HTML与安全转义&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HTML结构&lt;/strong&gt;: 通过标签定义文档结构与内容;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;转义规则&lt;/strong&gt;: 特殊字符需转义为实体（如&lt;code&gt;&amp;lt;&lt;/code&gt;→&lt;code&gt;&amp;amp;lt;&lt;/code&gt;）;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;示例漏洞&lt;/strong&gt;: 未转义的用户输入可能导致XSS攻击;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;22-javascript与dom&#34;&gt;2.2 JavaScript与DOM&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;动态交互&lt;/strong&gt;: JavaScript可修改DOM内容;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;示例代码&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;kd&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;addTodo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;newitem&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;document&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;createElement&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;li&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nx&#34;&gt;newitem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;textContent&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nb&#34;&gt;document&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;getElementById&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;todo&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;appendChild&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;newitem&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;安全风险&lt;/strong&gt;: 恶意脚本可劫持用户操作或窃取数据;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    <item>
      <title>2. 传输层</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/2.%20%E4%BC%A0%E8%BE%93%E5%B1%82/</link>
      <pubDate>Thu, 13 Feb 2025 16:42:12 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/2.%20%E4%BC%A0%E8%BE%93%E5%B1%82/</guid>
      <description>&lt;p&gt;传输层的目的是将从 终端-终端通信的 ip 协议转变为 app-app 的通信&lt;br&gt;
IP 是一种弱连接服务模型, 数据包有可能损坏, 延迟, 丢包, 重复等, 以及物理线路流量问题(例如流量大的时候如何明智的选择时机发送包), 处理这些问题也可以让应用层避免考虑这些棘手的问题&lt;/p&gt;</description>
    </item>
    <item>
      <title>TCP 流量控制与拥塞控制</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/tcp-flow-congestion-control/</link>
      <pubDate>Thu, 13 Feb 2025 16:42:12 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/tcp-flow-congestion-control/</guid>
      <description>&lt;p&gt;本文从 &lt;a href=&#34;https://www.whoami-wesleyyou.top/2025/02/13/computer_system_basics/network/2.%20%E4%BC%A0%E8%BE%93%E5%B1%82/&#34;&gt;传输层笔记&lt;/a&gt; 拆出, 集中整理接收窗口 RWND, 拥塞窗口 CWND 与拥塞控制算法. 端口, UDP, 可靠传输模型和 TCP 连接管理见原篇.&lt;/p&gt;
&lt;h2 id=&#34;tcp-流控制-flow-control&#34;&gt;TCP 流控制 Flow Control&lt;/h2&gt;
&lt;p&gt;指传输过程不涉及流量拥塞的情况下对数据流量进行控制&lt;/p&gt;
&lt;h3 id=&#34;rwnd&#34;&gt;RWND&lt;/h3&gt;
&lt;p&gt;用来防止 sender 的窗口尺寸 &amp;gt; receiver 的窗口尺寸&lt;br&gt;
receiver 在 ack 中会指定对应的 rwnd 尺寸, 因此 sender 方要保证空中运输的数据尺寸大小不超过 rwnd, 即 rwnd 表示当前 buffer 剩余空间, 会收到新接受数据和应用层消耗数据的影响而改变, 由于发送端的发送速度以 byte/sec 为单位, 因此发送速度不能超过 rwnd/rtt (即在未来一个回路时间内发包不能超过 rwnd 的限制)&lt;br&gt;
指定的 rwnd 尺寸存在 tcp header 的 Advertised Window 部分&lt;br&gt;
&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. 线程调度的实现</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/09/computer_system_basics/os/2.%20%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6%E7%9A%84%E5%AE%9E%E7%8E%B0/</link>
      <pubDate>Sun, 09 Feb 2025 16:18:53 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/09/computer_system_basics/os/2.%20%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6%E7%9A%84%E5%AE%9E%E7%8E%B0/</guid>
      <description>&lt;h2 id=&#34;resource-acquisition-is-initialization-raii&#34;&gt;Resource Acquisition Is Initialization (RAII)&lt;/h2&gt;
&lt;h3 id=&#34;resource-资源&#34;&gt;Resource 资源&lt;/h3&gt;
&lt;p&gt;定义: 持有价值昂贵的，可以被获取和释放的对象为资源，常见的有 Memory, Mutex, File&lt;/p&gt;
&lt;h4 id=&#34;lifetime-生命周期&#34;&gt;Lifetime 生命周期&lt;/h4&gt;
&lt;p&gt;一个变量通过调用构造函数来实现 introduction 和 initialization&lt;br&gt;
在退出 {} 的时候，系统会按照与定义相反的方向进行析构函数&lt;/p&gt;
&lt;h3 id=&#34;raii&#34;&gt;RAII&lt;/h3&gt;
&lt;p&gt;定义: 利用变量的生命周期来实现资源的构造和析构管理&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 多线程同步机制</title>
      <link>https://www.whoami-wesleyyou.top/2025/02/01/computer_system_basics/os/1.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E6%9C%BA%E5%88%B6/</link>
      <pubDate>Sat, 01 Feb 2025 15:29:56 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/02/01/computer_system_basics/os/1.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E6%9C%BA%E5%88%B6/</guid>
      <description>&lt;h2 id=&#34;os-抽象机制&#34;&gt;OS 抽象机制&lt;/h2&gt;
&lt;p&gt;OS 是一种对硬件功能映射到软件层的抽象机制&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;cpu -&amp;gt; process/thread&lt;/li&gt;
&lt;li&gt;ram -&amp;gt; address space&lt;/li&gt;
&lt;li&gt;disk -&amp;gt; files&lt;br&gt;
&lt;img alt=&#34;os_abstraction.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/os_abstraction.png&#34;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;进程属性&#34;&gt;进程属性&lt;/h3&gt;
&lt;p&gt;进程 process 是一个在执行中的程序, program 是一个静态 static 的实体，有能执行的潜能&lt;br&gt;
每个线程拥有所有程序运行所需要的状态和属性&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;address space (memory)
&lt;ul&gt;
&lt;li&gt;code (text)&lt;/li&gt;
&lt;li&gt;data (global -&amp;gt; heap)&lt;/li&gt;
&lt;li&gt;stack (运行状态)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;PC 表示程序运行进度&lt;/li&gt;
&lt;li&gt;通用reg&lt;/li&gt;
&lt;li&gt;通用 OS 资源如网络连接等&lt;br&gt;
进程之间互相 isolate 即不可访问其他线程&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;线程属性&#34;&gt;线程属性&lt;/h3&gt;
&lt;p&gt;线程表示的是一系列执行流 execution stream&lt;br&gt;
定义了 PC, SP, register, 没有定义单独的 address space, general process attributes (PID, open files&amp;hellip;)&lt;br&gt;
每个线程只能归属于一个 process, 一个进程可以有多个线程&lt;/p&gt;</description>
    </item>
    <item>
      <title>网络 Socket 编程</title>
      <link>https://www.whoami-wesleyyou.top/2025/01/19/computer_system_basics/network/%E7%BD%91%E7%BB%9C%20Socket%20%E7%BC%96%E7%A8%8B/</link>
      <pubDate>Sun, 19 Jan 2025 12:14:16 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/01/19/computer_system_basics/network/%E7%BD%91%E7%BB%9C%20Socket%20%E7%BC%96%E7%A8%8B/</guid>
      <description>&lt;h2 id=&#34;socket-概念与调用流程&#34;&gt;Socket 概念与调用流程&lt;/h2&gt;
&lt;h3 id=&#34;socket-定义&#34;&gt;Socket 定义&lt;/h3&gt;
&lt;p&gt;socket 即套接字，是一个双向通信通道，两端为两个process或者两个机器&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;socket是对网络通信的一种抽象&lt;/li&gt;
&lt;li&gt;提供了数据交换的 api&lt;/li&gt;
&lt;li&gt;去处了一些网卡交互的细节&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;服务器工作流-server-flow&#34;&gt;服务器工作流 server flow&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&#34;server_socket_flow.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/server_socket_flow.png&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;用户工作流-client-flow&#34;&gt;用户工作流 client flow&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&#34;client_socket_flow.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/client_socket_flow.png&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;工作流解读&#34;&gt;工作流解读&lt;/h3&gt;
&lt;h4 id=&#34;sc-交互&#34;&gt;SC 交互&lt;/h4&gt;
&lt;p&gt;&lt;img alt=&#34;sc_interact.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/sc_interact.png&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;创建-绑定与连接&#34;&gt;创建, 绑定与连接&lt;/h2&gt;
&lt;h3 id=&#34;socket-构造&#34;&gt;&lt;code&gt;socket()&lt;/code&gt; 构造&lt;/h3&gt;
&lt;p&gt;参数为 &lt;code&gt;socket(int domain, int type, int protocol&lt;/code&gt;, 都使用宏定义进行输入的&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 密码学基础</title>
      <link>https://www.whoami-wesleyyou.top/2025/01/13/computer_system_basics/network/security/1.%20%E5%AF%86%E7%A0%81%E5%AD%A6%E5%9F%BA%E7%A1%80/</link>
      <pubDate>Mon, 13 Jan 2025 20:16:03 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/01/13/computer_system_basics/network/security/1.%20%E5%AF%86%E7%A0%81%E5%AD%A6%E5%9F%BA%E7%A1%80/</guid>
      <description>&lt;h2 id=&#34;message-integrity-信息完整性&#34;&gt;Message Integrity 信息完整性&lt;/h2&gt;
&lt;h3 id=&#34;定义&#34;&gt;定义&lt;/h3&gt;
&lt;p&gt;ensures that attackers cannot modify a message w/o being detected.&lt;/p&gt;
&lt;h3 id=&#34;mitm-模型&#34;&gt;MITM 模型&lt;/h3&gt;
&lt;h4 id=&#34;传输部分&#34;&gt;传输部分&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;并不完全相信网络的信息的真实性&lt;/li&gt;
&lt;li&gt;希望 Bob 接收到的完全就是 Alice 发出的信息&lt;br&gt;
&lt;img alt=&#34;mitm_model.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/mitm_model.png&#34;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;威胁模型-threat-model&#34;&gt;威胁模型 threat model&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Mallory 可以 see/modify/forge(伪造) message&lt;/li&gt;
&lt;li&gt;Mallory 的目的是让 Bob 相信一个不是由 Alice 发出的信息&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;防御威胁的方法论&#34;&gt;防御威胁的方法论&lt;/h3&gt;
&lt;h4 id=&#34;verifier-验证器&#34;&gt;verifier 验证器&lt;/h4&gt;
&lt;p&gt;如图所示，在发送的时候额外传送一个验证码，即要求验证码 $v = f(m)$&lt;br&gt;
&lt;img alt=&#34;message_verifier_model.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/message_verifier_model.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. OSI 概述与应用层</title>
      <link>https://www.whoami-wesleyyou.top/2025/01/13/computer_system_basics/network/1.%20OSI%20%E6%A6%82%E8%BF%B0%E4%B8%8E%E5%BA%94%E7%94%A8%E5%B1%82/</link>
      <pubDate>Mon, 13 Jan 2025 19:04:40 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2025/01/13/computer_system_basics/network/1.%20OSI%20%E6%A6%82%E8%BF%B0%E4%B8%8E%E5%BA%94%E7%94%A8%E5%B1%82/</guid>
      <description>&lt;h2 id=&#34;网络分层与设计原则&#34;&gt;网络分层与设计原则&lt;/h2&gt;
&lt;h3 id=&#34;概述&#34;&gt;概述&lt;/h3&gt;
&lt;p&gt;网络信息传播需要遵循 应用(Application) -&amp;gt; 封装送货信息+路由选择(Transport) -&amp;gt; 国际地址封装(Network) -&amp;gt; 地区地址封装(Data Link) -&amp;gt; 物理层发送(Physical) 的五层收发结构&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;低层级 (后面的不需要知道前面发生了什么)&lt;/li&gt;
&lt;li&gt;每一层只负责该层任务以及与相邻层的 api 交互&lt;/li&gt;
&lt;li&gt;同层之间遵循同样的协议，可以互相交流&lt;br&gt;
&lt;img alt=&#34;osi_protocol.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/osi_protocol.png&#34;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;分层的优缺点&#34;&gt;分层的优缺点&lt;/h4&gt;
&lt;h5 id=&#34;优点&#34;&gt;优点&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;reduce complexity&lt;/li&gt;
&lt;li&gt;improve flexibility&lt;/li&gt;
&lt;li&gt;better manageability&lt;/li&gt;
&lt;li&gt;increase redundancy (冗余多): 每一层都有自己的恢复措施，因此可靠性更强&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;缺点&#34;&gt;缺点&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;high overhead&lt;/li&gt;
&lt;li&gt;cross layer information is often useful&lt;/li&gt;
&lt;li&gt;speed decreased&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;封装形式&#34;&gt;封装形式&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Header: 每一层协议，除了物理层都会给数据包在前面 append 一个表头表示 instructions on how to process payload.&lt;/li&gt;
&lt;li&gt;Payload: 表示有效的数据部分 semantic message&lt;/li&gt;
&lt;li&gt;Protocol 表示的是不同端共用的交流途径&lt;br&gt;
&lt;img alt=&#34;header_like.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/header_like.png&#34;&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;传输模型&#34;&gt;传输模型&lt;/h4&gt;
&lt;p&gt;在网络数据传输模型中，只有两端的 end system (host) 可以拥有上面两层 application 和 transport 层，每一个 node 都会有下 3 层，其中链路交换机 (switch) 和路由器 (router) 有以下不同&lt;br&gt;
&lt;img alt=&#34;net_translate.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/net_translate.png&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>18. 基础图论</title>
      <link>https://www.whoami-wesleyyou.top/2024/11/07/computer_system_basics/structure_algorithm/18.%20%E5%9F%BA%E7%A1%80%E5%9B%BE%E8%AE%BA/</link>
      <pubDate>Thu, 07 Nov 2024 12:18:55 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/11/07/computer_system_basics/structure_algorithm/18.%20%E5%9F%BA%E7%A1%80%E5%9B%BE%E8%AE%BA/</guid>
      <description>&lt;h2 id=&#34;定义&#34;&gt;定义&lt;/h2&gt;
&lt;p&gt;一个图 $G = (V,E)$ 由点的集合 $V$ 和边的集合 $E$ 组成&lt;br&gt;
&lt;strong&gt;平行边&lt;/strong&gt; 两个节点之间存在多条边界&lt;br&gt;
&lt;strong&gt;self-loop&lt;/strong&gt; 自循环&lt;br&gt;
没有自循环的图称为 simple graph，两端不同的边称为 simple path&lt;br&gt;
connect path: 一个 simple path 存在于任意一对 vertices 之间 (节点间均间接/直接相连)&lt;br&gt;
cycle: 简单路径除了首尾 vertex 相同&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. Cook-Levin Theorem</title>
      <link>https://www.whoami-wesleyyou.top/2024/11/04/computer_system_basics/structure_algorithm/P=NP/4.%20Cook-Levin%20Theorem/</link>
      <pubDate>Mon, 04 Nov 2024 13:16:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/11/04/computer_system_basics/structure_algorithm/P=NP/4.%20Cook-Levin%20Theorem/</guid>
      <description>&lt;h2 id=&#34;定理内容&#34;&gt;定理内容&lt;/h2&gt;
&lt;p&gt;SAT 问题是 NP-complete 问题&lt;br&gt;
由于 SAT 问题在给定 certificate 的情况下只需要逐个检验是否符合, 复杂度是 polynomial -&amp;gt; NP, 因此这里只需要证明其是 NP-hard 即可&lt;/p&gt;
&lt;h2 id=&#34;证明-np-hard&#34;&gt;证明 NP-Hard&lt;/h2&gt;
&lt;p&gt;利用 NP-hard 的定义, 这里需要证明对所有的 language $L\in NP$ 都有 $L\le_p SAT$ (因为 SAT 问题往往会作为 NP-hard origin 来归纳其他的问题是否 NP-hard, 这里不能用其他 NP-hard 来归纳之)&lt;br&gt;
因此假设我们有一个任意 np 问题的 instance x 和一个输入语言 L $\in$ NP, 即存在 $Verify-L$ 可以在多项式时间内决定 L;&lt;br&gt;
&lt;strong&gt;证明目的&lt;/strong&gt;是是否存在一个 SAT instance $\phi$ satisfiable &lt;strong&gt;iff&lt;/strong&gt; 存在 c 使得 Verify-L(x,c) accept&lt;br&gt;
定义 VL 算法为一个 TM, 并将其编码为一个 $|x|^k\times |x|^k$ 的一个表格 tableau of Verify-L(x,c)&lt;br&gt;
表格的每一行表示图灵机执行了一步, 其中每个元素是 x 的值 alphabet 或者 c 的 alphabet 或者 TM 的状态 $q_i$ 以及 $\bot$&lt;br&gt;
&lt;img alt=&#34;cook_levin_table.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/cook_levin_table.png&#34;&gt;&lt;br&gt;
定义存在性函数 $t_{i,j,s} = \{T,F\}$ 表示在表格 i 行 j 列位置上是否数值为 s&lt;br&gt;
定义 clause $\phi$ 为部分 t 的表达式子的 and / or 逻辑结果, 那么可以将这个 TM 是否有解转变为满足几个条件&lt;br&gt;
那么利用这个定义可以将证明目的变成 construct instance $\phi$ satisfiable iff 存在 c 使得 tableau of VL contains $q_{accept}$&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. NP-Complete</title>
      <link>https://www.whoami-wesleyyou.top/2024/11/04/computer_system_basics/structure_algorithm/P=NP/3.%20NP-Complete/</link>
      <pubDate>Mon, 04 Nov 2024 13:15:44 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/11/04/computer_system_basics/structure_algorithm/P=NP/3.%20NP-Complete/</guid>
      <description>&lt;h2 id=&#34;定义&#34;&gt;定义&lt;/h2&gt;
&lt;p&gt;A language $L$ is NP-complete if&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$L\in$ NP&lt;/li&gt;
&lt;li&gt;$L$ is NP-hard&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;证明方法-polynomial-time-mapping-reduction&#34;&gt;证明方法: polynomial-time mapping reduction&lt;/h2&gt;
&lt;p&gt;定义归纳关系 $A\le_p B$ 表示 $\exists f \text{ s.t. } x \in A\Leftrightarrow f(x) \in B$&lt;/p&gt;
&lt;h3 id=&#34;引理-lemma&#34;&gt;引理 lemma&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;$B\in P \Rightarrow A \in P$&lt;/li&gt;
&lt;li&gt;$A$ NP-hard $\Rightarrow$ B NP-hard&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;用法&#34;&gt;用法&lt;/h3&gt;
&lt;ol start=&#34;0&#34;&gt;
&lt;li&gt;选取一个已知的 NP-hard 问题 A 来归纳关系 $A\le_p B$&lt;/li&gt;
&lt;li&gt;定义问题转变映射: 如何将问题集合 A 的某个确定 instance 转变为 B 的对应的 instance&lt;/li&gt;
&lt;li&gt;证明这个转变 f 的时间复杂度是 polynomial&lt;/li&gt;
&lt;li&gt;证明 correctness:
&lt;ol&gt;
&lt;li&gt;证明一个能解决 A 的 answer 同样在转变的问题中可以以同样的答案解决 B (&lt;strong&gt;suppose when given the solution&lt;/strong&gt; of $x\in A$, then this solution to $f(x)\in B$ is also correct)&lt;/li&gt;
&lt;li&gt;证明能解决 B 的 answer 能以同样答案解决 A&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;set-cover-问题&#34;&gt;Set Cover 问题&lt;/h2&gt;
&lt;p&gt;有 n 个工人，每人有各自的技术集合, 目标是在定义的全技术集合中雇佣的工人能覆盖所有的技术 (假设每个技术不会被三个人及以上的拥有)&lt;/p&gt;</description>
    </item>
    <item>
      <title>17. 二叉树和自平衡二叉搜索树</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/31/computer_system_basics/structure_algorithm/17.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E5%92%8C%E8%87%AA%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91/</link>
      <pubDate>Thu, 31 Oct 2024 14:15:45 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/31/computer_system_basics/structure_algorithm/17.%20%E4%BA%8C%E5%8F%89%E6%A0%91%E5%92%8C%E8%87%AA%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91/</guid>
      <description>&lt;h2 id=&#34;树的定义&#34;&gt;树的定义&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;没有 cycle 的无向图&lt;/li&gt;
&lt;li&gt;rooted tree
&lt;ol&gt;
&lt;li&gt;存在某个 node 作为根节点&lt;/li&gt;
&lt;li&gt;每个节点事实上都可以作为 root&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;二叉树的操作复杂度&#34;&gt;二叉树的操作复杂度&lt;/h2&gt;
&lt;p&gt;二叉树的方法时间复杂度看的主要是二叉树自身的结构形状，如果是 complete 树是最好情况; 如果是 每个节点都只有一个子枝，其复杂度最大，是 worst case&lt;/p&gt;
&lt;h3 id=&#34;数组法&#34;&gt;数组法&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;insert
&lt;ol&gt;
&lt;li&gt;最好 O(1)&lt;/li&gt;
&lt;li&gt;最差 O(n)&lt;/li&gt;
&lt;li&gt;和树的排布方式有关，如果树的根节点的某个字节点为空那么直接插入，复杂度 O(1); 如果全部排满我们需要遍历找到空节点位置那么时间复杂度 O(n)&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;remove
&lt;ol&gt;
&lt;li&gt;最差 O(n)&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;parent O(1)&lt;/li&gt;
&lt;li&gt;child O(1)&lt;/li&gt;
&lt;li&gt;space
&lt;ol&gt;
&lt;li&gt;最好 O(n)&lt;/li&gt;
&lt;li&gt;最差 O(2^n)&lt;/li&gt;
&lt;li&gt;这里取决于数据的排布方式, 如果是完全二叉树，那只需要 O(n) 空间; 如果是完全一叉树 (每个node最多只有一个节点) 就需要 O(2^n) 空间&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;指针法&#34;&gt;指针法&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;insert 好 O(1) 坏 O(n)&lt;/li&gt;
&lt;li&gt;remove 坏 O(n)&lt;/li&gt;
&lt;li&gt;parent O(n) 因为没有爹指针&lt;/li&gt;
&lt;li&gt;child O(1)&lt;/li&gt;
&lt;li&gt;space 好 O(n) 坏 O(n)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;遍历方向-ordering&#34;&gt;遍历方向 ordering&lt;/h2&gt;
&lt;h3 id=&#34;preorder&#34;&gt;preorder&lt;/h3&gt;
&lt;p&gt;满足 &lt;strong&gt;中左右&lt;/strong&gt; 的顺序&lt;/p&gt;</description>
    </item>
    <item>
      <title>8. 缓存 cache</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/computer_composition/8.%20%E7%BC%93%E5%AD%98%20cache/</link>
      <pubDate>Tue, 29 Oct 2024 21:45:09 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/computer_composition/8.%20%E7%BC%93%E5%AD%98%20cache/</guid>
      <description>&lt;h2 id=&#34;sram-dram-ssd&#34;&gt;SRAM, DRAM, SSD&lt;/h2&gt;
&lt;h3 id=&#34;sram-静态随机访问内存&#34;&gt;SRAM 静态随机访问内存&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;由六个三极管组成&lt;/li&gt;
&lt;li&gt;脆弱&lt;strong&gt;volatile&lt;/strong&gt;：需要常量的电压来保存数据&lt;/li&gt;
&lt;li&gt;快速: 1ns 左右的数据访问时间&lt;/li&gt;
&lt;li&gt;空间占用率低: 只能在芯片上存储 MB 大小的数据&lt;br&gt;
&lt;img alt=&#34;sram.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/sram.png&#34;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;dram-动态随机访问内存&#34;&gt;DRAM 动态随机访问内存&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;每一个 bit 用一个 三极管和一个电容组成&lt;/li&gt;
&lt;li&gt;需要常量的电压来保存数据&lt;/li&gt;
&lt;li&gt;缓慢: 大约 50 ns 的访问时间&lt;/li&gt;
&lt;li&gt;便宜，可以提供 GB 单位的内存空间&lt;br&gt;
&lt;img alt=&#34;dram.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/dram.png&#34;&gt;&lt;br&gt;
现代硬件结构中这个往往被用作是主要内存硬盘&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;disk-光盘&#34;&gt;Disk 光盘&lt;/h3&gt;
&lt;p&gt;硬件将数据存储在 磁电,通过光盘的旋转来进行数据获取&lt;br&gt;
数据获取非常缓慢，约 3ms 的访问时间&lt;br&gt;
不脆弱：即使没有电压也可以保存数据&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. NP-Hardness</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/structure_algorithm/P=NP/2.%20NP-Hardness/</link>
      <pubDate>Tue, 29 Oct 2024 21:23:34 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/structure_algorithm/P=NP/2.%20NP-Hardness/</guid>
      <description>&lt;h2 id=&#34;np-hard-定义&#34;&gt;NP-hard 定义&lt;/h2&gt;
&lt;p&gt;一个语言 $L$ 是 NP-hard 若对任意 NP 中的语言 X 存在关系 $X\le_p L$&lt;br&gt;
定义这个关系为：at least as hard as&lt;br&gt;
并不要求 NP-hard 问题属于 NP&lt;/p&gt;
&lt;h3 id=&#34;np-complete&#34;&gt;NP-complete&lt;/h3&gt;
&lt;p&gt;定义语言 $L$ 是 NP-complete 的如果 1. $L\in$ NP 且 2. $L\in$ NP-hard&lt;br&gt;
从简单上来认识这个 class，可以理解为这是最难解决的 NP 问题&lt;/p&gt;
&lt;h3 id=&#34;np-hard-的复杂度性质&#34;&gt;NP-hard 的复杂度性质&lt;/h3&gt;
&lt;p&gt;如果对于任何一个 NP-hard 的问题，存在一个 多项式复杂度的解 那么任何 NP 问题都可以在 P 时间内解决&lt;br&gt;
因此有两种可能性:&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 计算的复杂性 complexity</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/structure_algorithm/P=NP/1.%20%E8%AE%A1%E7%AE%97%E7%9A%84%E5%A4%8D%E6%9D%82%E6%80%A7%20complexity/</link>
      <pubDate>Tue, 29 Oct 2024 21:23:14 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/29/computer_system_basics/structure_algorithm/P=NP/1.%20%E8%AE%A1%E7%AE%97%E7%9A%84%E5%A4%8D%E6%9D%82%E6%80%A7%20complexity/</guid>
      <description>&lt;h2 id=&#34;p-类-多项式可解类&#34;&gt;P 类 多项式可解类&lt;/h2&gt;
&lt;p&gt;定义 P class:= 所有的 decidable 的 problem 中可以在多项式中决定的集合&lt;br&gt;
即若有 $L\in P$, 那么就会存在图灵机 $M$ decides $L$, 且 $M$ 的时间复杂度是 $O(n^k)$&lt;/p&gt;
&lt;h3 id=&#34;难以解决的问题-例-traveling-salesperson-problem--tsp-旅行商问题&#34;&gt;难以解决的问题-例: traveling salesperson problem  (TSP) 旅行商问题&lt;/h3&gt;
&lt;p&gt;在一个图中，是否存在一条路径经过每个点一次且路径权值和小于常数 b ?&lt;br&gt;
这个问题的求解步骤或许非常麻烦，但是当我们提出一种解之后，我们很容易就可以根据定义来进行验证其真伪，我们称这类容易验证的问题为 efficiently verifiable&lt;/p&gt;</description>
    </item>
    <item>
      <title>7. 流水线指令 pipeline</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/23/computer_system_basics/computer_composition/7.%20%E6%B5%81%E6%B0%B4%E7%BA%BF%E6%8C%87%E4%BB%A4%20pipeline/</link>
      <pubDate>Wed, 23 Oct 2024 22:58:11 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/23/computer_system_basics/computer_composition/7.%20%E6%B5%81%E6%B0%B4%E7%BA%BF%E6%8C%87%E4%BB%A4%20pipeline/</guid>
      <description>&lt;h2 id=&#34;目的&#34;&gt;目的&lt;/h2&gt;
&lt;p&gt;可以压缩执行时间，从单循环的长周期短cpi和多循环的短周期长cpi结合得到&lt;br&gt;
短周期 + 短 cpi (等于 多循环的cpi)&lt;/p&gt;
&lt;h2 id=&#34;特点&#34;&gt;特点&lt;/h2&gt;
&lt;p&gt;在 multi-cycle 的电路基础上，添加一个 对应每个 stage 的寄存器, 一共四个&lt;br&gt;
最大同时执行指令的次数: 5 (即 if, id, ex, mem, wb 各一个同时进行)&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. 组合逻辑与串行逻辑 combinational logic and sequential logic</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/23/computer_system_basics/computer_composition/6.%20%E7%BB%84%E5%90%88%E9%80%BB%E8%BE%91%E4%B8%8E%E4%B8%B2%E8%A1%8C%E9%80%BB%E8%BE%91%20combinational%20logic%20and%20sequential%20logic/</link>
      <pubDate>Wed, 23 Oct 2024 22:58:02 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/23/computer_system_basics/computer_composition/6.%20%E7%BB%84%E5%90%88%E9%80%BB%E8%BE%91%E4%B8%8E%E4%B8%B2%E8%A1%8C%E9%80%BB%E8%BE%91%20combinational%20logic%20and%20sequential%20logic/</guid>
      <description>&lt;h2 id=&#34;选择器-mux&#34;&gt;选择器 mux&lt;/h2&gt;
&lt;p&gt;在逻辑电路中，我们经常会需要选择使用哪个数据源(这里其实是比较 compare 逻辑)，所以我们会用到 mux 来完成, 其符号如下:&lt;br&gt;
&lt;img alt=&#34;mux_concept.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/mux_concept.png&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;原理&#34;&gt;原理&lt;/h3&gt;
&lt;p&gt;这个逻辑可以用 与门 来完成&lt;br&gt;
&lt;img alt=&#34;mux_principle.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/mux_principle.png&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;加法器-adder&#34;&gt;加法器 adder&lt;/h2&gt;
&lt;p&gt;已经在基本逻辑电路中解释过了，大致原理就是接收 进位位 Carrier, 输入位 a,b 通过逻辑演算得到 本位值以及进位位值&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. 从不可定到不可认知 From Undecidable to Unrecognizable Problem</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/computation_theory/3.%20%E4%BB%8E%E4%B8%8D%E5%8F%AF%E5%AE%9A%E5%88%B0%E4%B8%8D%E5%8F%AF%E8%AE%A4%E7%9F%A5%20From%20Undecidable%20to%20Unrecognizable%20Problem/</link>
      <pubDate>Tue, 15 Oct 2024 18:38:14 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/computation_theory/3.%20%E4%BB%8E%E4%B8%8D%E5%8F%AF%E5%AE%9A%E5%88%B0%E4%B8%8D%E5%8F%AF%E8%AE%A4%E7%9F%A5%20From%20Undecidable%20to%20Unrecognizable%20Problem/</guid>
      <description>&lt;h2 id=&#34;常用的不可定中间语言&#34;&gt;常用的不可定中间语言&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;BARBER $L_{BARBER} = \{ \langle M \rangle : M \text{does not accept } \langle M \rangle \}$&lt;/li&gt;
&lt;li&gt;HALT $L_{HALT} = \{ (\langle M\rangle, x) : M \text{ halts on } w \}$&lt;/li&gt;
&lt;li&gt;ACC $L_{ACC} = \{ \langle M \rangle : M \text{ accepts } L(M) \}$&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;单string停机问题&#34;&gt;单string停机问题&lt;/h2&gt;
&lt;p&gt;虽然不能解决通用停机问题，但是我们是否可以解决单string停机问题？即对于给定的一个string，判断一个特定的图灵机是否能停机。从简单的角度考虑，我们来看语言 $L_{\epsilon-HALT}$ 是否可决定&lt;br&gt;
如果我们要用到图灵归纳的方法，用不可定推导不可定的推导方向应该是 $L_{HALT}\le_T L_{\epsilon-HALT}$&lt;br&gt;
那么我们就需要假设一个预言机(oracle) $D_{\epsilon-HALT}$ 能解决 $L_{\epsilon-HALT}$ ，那么我们就可以构造一个图灵机 $D_{HALT}$ 来解决 $L_{HALT}$&lt;br&gt;
并且我们的老演员 $L_{HALT}$ 是 $D_{HALT}$ 的预言机&lt;br&gt;
我们需要利用oracle 来构建 $L_{HALT}$ 即判断 $M(x)$ 是否停机&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. 从罗素悖论到不可解决的问题 Undecidable Problem</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/computation_theory/2.%20%E4%BB%8E%E7%BD%97%E7%B4%A0%E6%82%96%E8%AE%BA%E5%88%B0%E4%B8%8D%E5%8F%AF%E8%A7%A3%E5%86%B3%E7%9A%84%E9%97%AE%E9%A2%98%20Undecidable%20Problem/</link>
      <pubDate>Tue, 15 Oct 2024 18:38:00 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/computation_theory/2.%20%E4%BB%8E%E7%BD%97%E7%B4%A0%E6%82%96%E8%AE%BA%E5%88%B0%E4%B8%8D%E5%8F%AF%E8%A7%A3%E5%86%B3%E7%9A%84%E9%97%AE%E9%A2%98%20Undecidable%20Problem/</guid>
      <description>&lt;h2 id=&#34;罗素悖论---理发师悖论-barber-paradox&#34;&gt;罗素悖论 - 理发师悖论 Barber Paradox&lt;/h2&gt;
&lt;p&gt;一个小镇上的理发师，只给那些不给自己理头发的人理发&lt;br&gt;
那么就会出现一个问题，如果这个理发师给自己理发（假设物理上做得到）那么他就违反了他的 slogan，因为他自己是理头发的人，他不能给理头发的人理头发&lt;br&gt;
如果这个理发师不给自己理头发，那么他也违反了自己的slogan，他不给自己理头发但是他理应给自己理头发&lt;/p&gt;</description>
    </item>
    <item>
      <title>15. 排序算法</title>
      <link>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/15.%20%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/</link>
      <pubDate>Tue, 15 Oct 2024 17:33:50 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/10/15/computer_system_basics/structure_algorithm/15.%20%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/</guid>
      <description>&lt;h2 id=&#34;排序的分类&#34;&gt;排序的分类&lt;/h2&gt;
&lt;p&gt;一般我们将排序能不能根据输入数组后能否优化处理的特性将排序算法分为两类&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Non-Adaptive Sort: 不会根据输入数据的特性进行优化处理&lt;/li&gt;
&lt;li&gt;Adaptive Sort: 会根据输入数据的特性进行优化处理&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;冒泡排序-bubble-sort&#34;&gt;冒泡排序 bubble sort&lt;/h2&gt;
&lt;p&gt;用两个指针，逐个将相邻的两个节点大小进行比较，每次把最极端的值放到数组的某一边，然后下一层循环减小空间&lt;/p&gt;</description>
    </item>
    <item>
      <title>11. 查找与并集</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/structure_algorithm/11.%20%E6%9F%A5%E6%89%BE%E4%B8%8E%E5%B9%B6%E9%9B%86/</link>
      <pubDate>Thu, 26 Sep 2024 21:55:52 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/structure_algorithm/11.%20%E6%9F%A5%E6%89%BE%E4%B8%8E%E5%B9%B6%E9%9B%86/</guid>
      <description>&lt;h2 id=&#34;对分查找-binary-search&#34;&gt;对分查找 binary search&lt;/h2&gt;
&lt;p&gt;这个查找的前提是建立在数组有序的基础上，我们可以通过对分的位置判断分区，从而快速找到目标节点&lt;br&gt;
一般只能返回是否找到目标节点，而不能返回其位置，我们应该使用 标准迭代器&lt;br&gt;
&lt;code&gt;lower_bound()&lt;/code&gt;, &lt;code&gt;upper_bound()&lt;/code&gt; 进行坐标确定，其中 &lt;code&gt;lower_bouund&lt;/code&gt; 能从右侧逼近最靠近目标元素的位置； &lt;code&gt;upper_bound&lt;/code&gt; 能从最左侧逼近最靠近目标元素的位置&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. 浮点数算法</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/computer_composition/lab_coding/3.%20%E6%B5%AE%E7%82%B9%E6%95%B0%E7%AE%97%E6%B3%95/</link>
      <pubDate>Thu, 26 Sep 2024 02:00:08 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/computer_composition/lab_coding/3.%20%E6%B5%AE%E7%82%B9%E6%95%B0%E7%AE%97%E6%B3%95/</guid>
      <description>&lt;h2 id=&#34;单精度浮点数-float&#34;&gt;单精度浮点数 float&lt;/h2&gt;
&lt;p&gt;浮点数在内存中的存储格式是 127 基偏差 方式 (base biased 127 encoding) 即将 -127 = 0x00000000 那么:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1 = 0x10000000&lt;/li&gt;
&lt;li&gt;128 = 0x11111111&lt;/li&gt;
&lt;li&gt;0 = 0x01111111&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;小数点的前后&#34;&gt;小数点的前后&lt;/h3&gt;
&lt;p&gt;对于十进制小数 10.625, 我们可以将整数部分分解为二进制: 1010&lt;br&gt;
但是小数部分如何用二进制表示？&lt;br&gt;
类比十进制，小数点后一位是 $10^{-1}$, 二进制小数点后一位是 $2^{-1}$, 二进制小数点后二位是 $2^{-2}$, 以此类推。&lt;br&gt;
那么 .625 就可以理解为 $0.5 + 0.125 = 2^{-1} + 2^{-3} = 0b0.101$&lt;br&gt;
因此整个小数就是 $0b1010.101$ = 10.625&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. 链接步骤 linking</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/computer_composition/5.%20%E9%93%BE%E6%8E%A5%E6%AD%A5%E9%AA%A4%20linking/</link>
      <pubDate>Thu, 26 Sep 2024 01:57:50 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/computer_composition/5.%20%E9%93%BE%E6%8E%A5%E6%AD%A5%E9%AA%A4%20linking/</guid>
      <description>&lt;h2 id=&#34;背景&#34;&gt;背景&lt;/h2&gt;
&lt;p&gt;在编译 C 或者 C++ 文件的时候，我们都会用到链接这一步骤，即 预处理 - 编译 - 汇编 - 链接 四个步骤&lt;br&gt;
我们已经学过了汇编了，那么接下来就该了解一下什么是 linking 了&lt;/p&gt;
&lt;h2 id=&#34;什么是链接&#34;&gt;什么是链接&lt;/h2&gt;
&lt;p&gt;在汇编中，我们一般是每一个 c/cpp 文件生成一个 汇编代码文件 (obj file, 扩展名 &lt;code&gt;.o&lt;/code&gt;)，那么，如果存在跨文件的变量，汇编怎么知道这个变量是来自哪里的呢？&lt;br&gt;
首先我们联想在编译的时候 (compile time) 我们会在项目编译的内存空间中创建一个格式为 text - data - heap - stack 的空间结构(这里说的不恰当，应该说 compile time 分配的 text - data 空间)，那么类似的，对于每个源文件生成的汇编码，我们都要用一个表来记录&lt;strong&gt;全局变量&lt;/strong&gt;的引用 $cross-ref$ 以及&lt;strong&gt;外来方法&lt;/strong&gt;  (即函数) 的对应引用&lt;/p&gt;</description>
    </item>
    <item>
      <title>7. 贪心算法 Greedy</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/structure_algorithm/7.%20%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95%20Greedy/</link>
      <pubDate>Thu, 26 Sep 2024 01:57:09 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/26/computer_system_basics/structure_algorithm/7.%20%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95%20Greedy/</guid>
      <description>&lt;h2 id=&#34;排课问题&#34;&gt;排课问题&lt;/h2&gt;
&lt;p&gt;假设开学季的某一个下午多个社团都想要占用霍体开设招新活动，每个活动的时间长度各不相同且开始和结束的时间都各不相同，那么，学校方希望能尽可能多的开设活动，而并不考虑总活动时长的影响因素&lt;/p&gt;
&lt;h3 id=&#34;最早结束时间算法-earliest-ending-time-eet&#34;&gt;最早结束时间算法 Earliest Ending Time EET&lt;/h3&gt;
&lt;p&gt;将这些活动按照时间结束的早晚进行排序，然后选中最前面那个，然后去除所有重叠的活动，然后递归选取下一个&lt;/p&gt;</description>
    </item>
    <item>
      <title>10. 堆，优先队列与堆排序</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/24/computer_system_basics/structure_algorithm/10.%20%E5%A0%86%EF%BC%8C%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%E4%B8%8E%E5%A0%86%E6%8E%92%E5%BA%8F/</link>
      <pubDate>Tue, 24 Sep 2024 13:42:44 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/24/computer_system_basics/structure_algorithm/10.%20%E5%A0%86%EF%BC%8C%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97%E4%B8%8E%E5%A0%86%E6%8E%92%E5%BA%8F/</guid>
      <description>&lt;h2 id=&#34;堆&#34;&gt;堆&lt;/h2&gt;
&lt;p&gt;我们将一棵树变得更加特别，即限制其必须为完整的，即每一个树的层级都是满的，除了最后一层。&lt;br&gt;
然后，我们联想生活中的常见的堆型结构：稻草堆，其特征是上小下大，那么，我们就可以定义数据结构中堆的特性：具有一定的偏序关系(优先级)，且根节点的值总是该偏序关系的一端。&lt;/p&gt;</description>
    </item>
    <item>
      <title>8. STL 的使用</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/19/computer_system_basics/structure_algorithm/8.%20STL%20%E7%9A%84%E4%BD%BF%E7%94%A8/</link>
      <pubDate>Thu, 19 Sep 2024 22:57:01 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/19/computer_system_basics/structure_algorithm/8.%20STL%20%E7%9A%84%E4%BD%BF%E7%94%A8/</guid>
      <description>&lt;h2 id=&#34;stdmove&#34;&gt;&lt;code&gt;std::move()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;将参数转换为右值引用，在调用移动构造函数或移动赋值操作符时可以进行资源的转移而非拷贝，从而提高效率&lt;/p&gt;
&lt;h2 id=&#34;stdswap&#34;&gt;&lt;code&gt;std::swap()&lt;/code&gt;&lt;/h2&gt;
&lt;h3 id=&#34;实现&#34;&gt;实现&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;template&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;typename&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;swap&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;temp&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;std&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;move&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;std&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;move&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;std&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;move&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;temp&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;功能&#34;&gt;功能&lt;/h3&gt;
&lt;p&gt;可以交换两个动态数组，但是实际上是交换两个数组的指针，操作量非常小，效率非常高&lt;br&gt;
也常常用于所谓需要 &amp;ldquo;copy&amp;rdquo; 的地方，特别是需要硬拷贝的类的赋值&lt;br&gt;
一般类的赋值涉及指针的时候，需要额外 new 一个新的指针进行等于，且在判断是否 new 的时候&lt;strong&gt;需要判断输入对象和执行对象不相同&lt;/strong&gt;（相同的话在析构的时候会将当前的数组指针释放且会重复申请同一个数值的多个指针）&lt;br&gt;
使用这个 swap 函数进行 就不需要担心这个问题&lt;/p&gt;</description>
    </item>
    <item>
      <title>9. 图的最短路径</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/19/computer_system_basics/structure_algorithm/9.%20%E5%9B%BE%E7%9A%84%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84/</link>
      <pubDate>Thu, 19 Sep 2024 22:56:49 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/19/computer_system_basics/structure_algorithm/9.%20%E5%9B%BE%E7%9A%84%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84/</guid>
      <description>&lt;h2 id=&#34;问题背景阐述以及分类&#34;&gt;问题背景阐述以及分类&lt;/h2&gt;
&lt;p&gt;在一个有权有向图(weighted directed graph)中，我们想知道从一个节点到其他某一个节点的路径的权和，注意权重可能是负数，我们这里假设图本身没有形成环&lt;br&gt;
那么问题会被分成两类&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Single-Source Shortest Paths (SSSP): 单个源出发到达某一节点的最短路径&lt;/li&gt;
&lt;li&gt;All-pairs Shortest Paths (ASAP): 任意一对节点之间的最短路径&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;两则引理&#34;&gt;两则引理&lt;/h3&gt;
&lt;h4 id=&#34;引理1&#34;&gt;引理1&lt;/h4&gt;
&lt;p&gt;如果从 $s$ 到 $t$ 的最短路径经过 $v$ 节点，那么 $s$ 到 $v$  和 $v$ 到 $t$ 均为最短路径&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. Multiplier</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/15/computer_system_basics/computer_composition/lab_coding/2.%20Multiplier/</link>
      <pubDate>Sun, 15 Sep 2024 01:28:54 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/15/computer_system_basics/computer_composition/lab_coding/2.%20Multiplier/</guid>
      <description>&lt;p&gt;如果使用 lc-2k 指令集完成一个乘法操作，要求复杂度是 $O(\log n)$ 要怎么做？&lt;/p&gt;
&lt;h2 id=&#34;问题分析&#34;&gt;问题分析&lt;/h2&gt;
&lt;p&gt;lc-2k 指令集中涉及计算的部分只有 &lt;code&gt;add&lt;/code&gt; 和 &lt;code&gt;nor&lt;/code&gt; 两个指令&lt;br&gt;
对于一个十进制的乘法操作，我们一般的做法是 列竖式，即将两个数的每一位相乘，然后将结果相加&lt;br&gt;
但是在二进制中，我们应该想到的是将被乘数（较小的）写成二进制，看每一位是否为1,如果是1,那么即乘数的 &lt;code&gt;cand*2^i&lt;/code&gt; ，然后将所有的结果相加&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. 从 C 语言到 汇编指令</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/14/computer_system_basics/computer_composition/4.%20%E4%BB%8E%20C%20%E8%AF%AD%E8%A8%80%E5%88%B0%20%E6%B1%87%E7%BC%96%E6%8C%87%E4%BB%A4/</link>
      <pubDate>Sat, 14 Sep 2024 14:34:55 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/14/computer_system_basics/computer_composition/4.%20%E4%BB%8E%20C%20%E8%AF%AD%E8%A8%80%E5%88%B0%20%E6%B1%87%E7%BC%96%E6%8C%87%E4%BB%A4/</guid>
      <description>&lt;h2 id=&#34;位数扩展&#34;&gt;位数扩展&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;有符号数的符号位(most significant number)为 1 时，扩展时高位补 1&lt;/li&gt;
&lt;li&gt;有符号数的符号位(most significant number) 为 0 时，扩展时高位补 0&lt;/li&gt;
&lt;li&gt;无符号数的扩展时高位补 0&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;寄存器知道存储数值是有符号还是无符号的吗&#34;&gt;寄存器知道存储数值是有符号还是无符号的吗&lt;/h3&gt;
&lt;p&gt;答案是不知道，寄存器只会存储数值，不会存储数值的符号，符号是由汇编码的不同操作指令来决定的，比如 &lt;code&gt;LDURSW&lt;/code&gt; 就是有符号数，&lt;code&gt;LDUR&lt;/code&gt; 就是无符号数&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. lc-2k 指令集架构</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/12/computer_system_basics/computer_composition/2.%20lc-2k%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84/</link>
      <pubDate>Thu, 12 Sep 2024 14:46:07 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/12/computer_system_basics/computer_composition/2.%20lc-2k%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84/</guid>
      <description>&lt;h2 id=&#34;硬件结构&#34;&gt;硬件结构&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;32 位 处理器: 指令长度是 32 位 , 寄存器大小是 32 位&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;32 位处理器&lt;/strong&gt;的关键特征是其寄存器、数据总线和地址总线的宽度为 32 位。这意味着它可以处理 32 位的整数，并且通常可以寻址的最大内存空间为 4 GB。&lt;/li&gt;
&lt;li&gt;在 32 位处理器中，寄存器和数据路径通常也是 32 位的，所以处理器可以在一次操作中处理 32 位的数据&lt;/li&gt;
&lt;li&gt;其指令长度也是 32 位（这里的32 没有特指王楚钦）&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;8 个寄存器，其中 reg 0 一般只会被赋值 0&lt;/li&gt;
&lt;li&gt;内存寻址范围 4GB 即 65536 words&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;指令形式&#34;&gt;指令形式&lt;/h2&gt;
&lt;h3 id=&#34;寄存器型指令结构&#34;&gt;寄存器型指令结构&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;31 - 25&lt;/th&gt;
					&lt;th&gt;24 - 22&lt;/th&gt;
					&lt;th&gt;21 - 19&lt;/th&gt;
					&lt;th&gt;18 - 16&lt;/th&gt;
					&lt;th&gt;15 - 3&lt;/th&gt;
					&lt;th&gt;2 - 0&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;unused&lt;/td&gt;
					&lt;td&gt;opcode&lt;/td&gt;
					&lt;td&gt;regA&lt;/td&gt;
					&lt;td&gt;regB&lt;/td&gt;
					&lt;td&gt;unused&lt;/td&gt;
					&lt;td&gt;destR&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;立即数型指令结构&#34;&gt;立即数型指令结构&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;31 - 25&lt;/th&gt;
					&lt;th&gt;24 - 22&lt;/th&gt;
					&lt;th&gt;21 - 19&lt;/th&gt;
					&lt;th&gt;18 - 16&lt;/th&gt;
					&lt;th&gt;15 - 0&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;unused&lt;/td&gt;
					&lt;td&gt;opcode&lt;/td&gt;
					&lt;td&gt;regA&lt;/td&gt;
					&lt;td&gt;regB&lt;/td&gt;
					&lt;td&gt;offset&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;j-类型指令-jalr&#34;&gt;J 类型指令 (jalr)&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;31 - 25&lt;/th&gt;
					&lt;th&gt;24 - 22&lt;/th&gt;
					&lt;th&gt;21 - 19&lt;/th&gt;
					&lt;th&gt;18 - 16&lt;/th&gt;
					&lt;th&gt;15 - 0&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;unused&lt;/td&gt;
					&lt;td&gt;opcode&lt;/td&gt;
					&lt;td&gt;regA&lt;/td&gt;
					&lt;td&gt;regB&lt;/td&gt;
					&lt;td&gt;unused&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;o-类型指令-halt-noop&#34;&gt;O 类型指令 halt, noop&lt;/h3&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;31 - 25&lt;/th&gt;
					&lt;th&gt;24 - 22&lt;/th&gt;
					&lt;th&gt;21 - 0&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;unused&lt;/td&gt;
					&lt;td&gt;opcode&lt;/td&gt;
					&lt;td&gt;unused&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;指令分析&#34;&gt;指令分析&lt;/h2&gt;
&lt;h3 id=&#34;算术类&#34;&gt;算术类&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;add&lt;/code&gt;: &lt;code&gt;add 1 2 3&lt;/code&gt; 表示将 1 + 2 的结果存入 3&lt;br&gt;
&lt;code&gt;nor&lt;/code&gt;: &lt;code&gt;nor 1 2 3&lt;/code&gt; 表示将 ~(r1|r2) 的结果存入 3&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. ARM 指令集架构</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/12/computer_system_basics/computer_composition/3.%20ARM%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84/</link>
      <pubDate>Thu, 12 Sep 2024 14:45:57 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/12/computer_system_basics/computer_composition/3.%20ARM%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84/</guid>
      <description>&lt;p&gt;相比于前一节课讲的 lc2k isa, arm 架构的效果会好很多&lt;/p&gt;
&lt;h2 id=&#34;isa-的分类&#34;&gt;ISA 的分类&lt;/h2&gt;
&lt;h3 id=&#34;risc-架构reduced-instruction-set-computing&#34;&gt;RISC 架构，Reduced Instruction Set Computing&lt;/h3&gt;
&lt;p&gt;指令数量更少，编码的指令长度是一致的，硬件设备相对更加简单，程序更大，手写会更加困难，但是当前非常常用&lt;br&gt;
应用: lc2k, risc-v, arm (包括其子集 LEG)&lt;/p&gt;
&lt;h3 id=&#34;cisc-架构complex-instruction-set-computing&#34;&gt;CISC 架构，Complex Instruction Set Computing&lt;/h3&gt;
&lt;p&gt;用更多、更复杂的指令集，编码的指令的长度是不一定的，所以硬件更复杂，程序的长度更短，手写更方便，现在比较少用了&lt;br&gt;
应用: x86&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. 递归算法</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/11/computer_system_basics/structure_algorithm/5.%20%E9%80%92%E5%BD%92%E7%AE%97%E6%B3%95/</link>
      <pubDate>Wed, 11 Sep 2024 21:18:41 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/11/computer_system_basics/structure_algorithm/5.%20%E9%80%92%E5%BD%92%E7%AE%97%E6%B3%95/</guid>
      <description>&lt;h2 id=&#34;尾递归-tail-recursion&#34;&gt;尾递归 Tail Recursion&lt;/h2&gt;
&lt;p&gt;我们称递归调用在函数最后一步的递归方式为 &lt;strong&gt;尾递归&lt;/strong&gt;&lt;br&gt;
例如我们在计算阶乘的时候，如果我们这样写：&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;factorial&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acc&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;factorial&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;那么调用自身的步骤在最后，就是尾递归，这种递归形式由于和 正向递推没有很大的区别，有一些编译器会将其变成 iteration 的形式进行执行，从而避免 stack-overflow 的问题，其占用的时间和空间都会比一般的递归小很多&lt;/p&gt;</description>
    </item>
    <item>
      <title>4. 程序性能的分析</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/11/computer_system_basics/structure_algorithm/4.%20%E7%A8%8B%E5%BA%8F%E6%80%A7%E8%83%BD%E7%9A%84%E5%88%86%E6%9E%90/</link>
      <pubDate>Wed, 11 Sep 2024 20:49:38 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/11/computer_system_basics/structure_algorithm/4.%20%E7%A8%8B%E5%BA%8F%E6%80%A7%E8%83%BD%E7%9A%84%E5%88%86%E6%9E%90/</guid>
      <description>&lt;h2 id=&#34;时间的测量&#34;&gt;时间的测量&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;cp&#34;&gt;#include&lt;/span&gt; &lt;span class=&#34;cpf&#34;&gt;&amp;lt;chrono&amp;gt;&lt;/span&gt;&lt;span class=&#34;cp&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kt&#34;&gt;int&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;Timer&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;start&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;stop&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;cout&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;seconds&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;endl&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;reset&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;start&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;stop&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;但是多次&lt;strong&gt;查看&lt;/strong&gt;系统时间会导致程序明显变慢&lt;/p&gt;
&lt;h3 id=&#34;常用的工具-profiling-tools&#34;&gt;常用的工具 profiling tools&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;perf&lt;/code&gt; 指令会显示某些节点花费的时间、cpu占用等性能&lt;br&gt;
或者在linux 下，可以考虑使用 &lt;code&gt;time prog&lt;/code&gt; 指令，该指令会在命令行输出一行 后面的prog 内容加上 各个部分占用的时间以及cpu占用量&lt;/p&gt;</description>
    </item>
    <item>
      <title>6. 动态规划 Dynamic Programming</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/09/computer_system_basics/structure_algorithm/7.%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%20Dynamic%20Programming/</link>
      <pubDate>Mon, 09 Sep 2024 22:50:32 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/09/computer_system_basics/structure_algorithm/7.%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%20Dynamic%20Programming/</guid>
      <description>&lt;p&gt;在分治算法中，我们已经知道要将一个问题分裂成不同的子问题来解决，但是，如果有些时候子问题之间存在覆盖问题，那么再利用 分治算法得到的时间复杂度就会非常大，所以，我们往往使用制表法来解决这个问题，中文名“动态规划”。&lt;br&gt;
动态规划的解 （ OP, optimal）往往有很多个, 但是我们会用 value 进行标注这个 解，即我们可以通过比较 value 来找到最优解 (OTV, optimal value)。&lt;/p&gt;</description>
    </item>
    <item>
      <title>5. 分治算法 Divide and Conquer</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/09/computer_system_basics/structure_algorithm/6.%20%E5%88%86%E6%B2%BB%E7%AE%97%E6%B3%95%20Divide%20and%20Conquer/</link>
      <pubDate>Mon, 09 Sep 2024 22:42:54 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/09/computer_system_basics/structure_algorithm/6.%20%E5%88%86%E6%B2%BB%E7%AE%97%E6%B3%95%20Divide%20and%20Conquer/</guid>
      <description>&lt;h2 id=&#34;分治思想&#34;&gt;分治思想&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;将一个输入变成多个 sub-inputs&lt;/li&gt;
&lt;li&gt;将一个 subinput 通过递归找到子解决方法&lt;/li&gt;
&lt;li&gt;结合 (combine, or conquer) 子解决方法得到最终解决方法&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;归并排序&#34;&gt;归并排序&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;将一个线性数组分割成两个等长的数组，长度 n/2&lt;/li&gt;
&lt;li&gt;对左右子数组分别执行归并排序（递归）复杂度&lt;/li&gt;
&lt;li&gt;将左右数组进行合并， 复杂度 $O(n)$&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;递归部分复杂度分析&#34;&gt;递归部分复杂度分析&lt;/h3&gt;
&lt;p&gt;首先我们明确这是一个类似二叉树的结构，所以，从层数上来讲，一共有 $\log_2 n$ 层，每一层的复杂度是 $O(n)$ (每一层都有合并)，所以递归部分的复杂度是 $O(n \log n)$&lt;/p&gt;</description>
    </item>
    <item>
      <title>基本门电路图标识</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/01/computer_system_basics/computer_composition/0.%20%E5%9F%BA%E6%9C%AC%E9%97%A8%E7%94%B5%E8%B7%AF%E5%9B%BE%E6%A0%87%E8%AF%86/</link>
      <pubDate>Sun, 01 Sep 2024 11:01:07 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/01/computer_system_basics/computer_composition/0.%20%E5%9F%BA%E6%9C%AC%E9%97%A8%E7%94%B5%E8%B7%AF%E5%9B%BE%E6%A0%87%E8%AF%86/</guid>
      <description>&lt;p&gt;&lt;img alt=&#34;gate_circuit1.png&#34; loading=&#34;lazy&#34; src=&#34;https://www.whoami-wesleyyou.top/images/gate_circuit1.png&#34;&gt;&lt;br&gt;
gate_circuit.png&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. Bit Manipulation</title>
      <link>https://www.whoami-wesleyyou.top/2024/09/01/computer_system_basics/computer_composition/lab_coding/1.%20Bit%20Manipulation/</link>
      <pubDate>Sun, 01 Sep 2024 10:39:31 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/09/01/computer_system_basics/computer_composition/lab_coding/1.%20Bit%20Manipulation/</guid>
      <description>&lt;h2 id=&#34;位操作-bit-manipulation&#34;&gt;位操作 Bit Manipulation&lt;/h2&gt;
&lt;p&gt;如果我们要将一个十六进制数 &lt;code&gt;0x2020&lt;/code&gt; 取出从低到高第二位的值，我们最直接的方法就是使用 &lt;strong&gt;mask&lt;/strong&gt;, 即&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mh&#34;&gt;0x2020&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;mh&#34;&gt;0x00F0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;如果要将这几位输出，我们就要 &lt;code&gt;a = a &amp;gt;&amp;gt; 4;&lt;/code&gt; 就可以将数据向右 bit shift 4 位，然后我们就可以得到 &lt;code&gt;0x0002&lt;/code&gt; 的值&lt;/p&gt;
&lt;h3 id=&#34;为什么不能用-a--8--12&#34;&gt;为什么不能用 (a &amp;laquo; 8) &amp;raquo; 12?&lt;/h3&gt;
&lt;p&gt;对于向右位移，我们可能会将超过长度的内容赋值 0, 但是向左位移则不是这样，向左的位移会被认为是 直接扩大数字&lt;br&gt;
如果是 &lt;code&gt;int&lt;/code&gt; 数据类型向左位移 100 位，这个等价于 &lt;code&gt;&amp;lt;&amp;lt; 100 % 32&lt;/code&gt; 因为 &lt;code&gt;int&lt;/code&gt; 长 4 字节 32 位，编译器会将这一步截断到 4 位从而不为 0&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. 基础容器的实现</title>
      <link>https://www.whoami-wesleyyou.top/2024/08/31/computer_system_basics/structure_algorithm/3.%20%E5%9F%BA%E7%A1%80%E5%AE%B9%E5%99%A8%E7%9A%84%E5%AE%9E%E7%8E%B0/</link>
      <pubDate>Sat, 31 Aug 2024 13:03:55 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/08/31/computer_system_basics/structure_algorithm/3.%20%E5%9F%BA%E7%A1%80%E5%AE%B9%E5%99%A8%E7%9A%84%E5%AE%9E%E7%8E%B0/</guid>
      <description>&lt;p&gt;在使用抽象数据类型的时候，我们往往会需要考虑数据结构的存取api的使用逻辑，这我就需要考虑&lt;strong&gt;栈&lt;/strong&gt;和&lt;strong&gt;队列&lt;/strong&gt;了&lt;br&gt;
数据的存储有两种形式: 连续的 array 型存储 和 离散的 linked list 型存储，我们接下来也会对比二者的效果&lt;/p&gt;
&lt;h2 id=&#34;栈-stack&#34;&gt;栈 Stack&lt;/h2&gt;
&lt;p&gt;栈的存储顺序是 &lt;code&gt;LIFO&lt;/code&gt;, 即 last in - first out&lt;br&gt;
需要两个指针: 指向栈底的 &lt;code&gt;base_ptr&lt;/code&gt; 与 指向栈顶的 &lt;code&gt;top_ptr&lt;/code&gt; , 其中 &lt;code&gt;top_ptr&lt;/code&gt; 指向的是栈顶的&lt;strong&gt;下一个位置&lt;/strong&gt;(悬空)&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 指令集架构 Instruction Set Architecture, ISA</title>
      <link>https://www.whoami-wesleyyou.top/2024/08/31/computer_system_basics/computer_composition/1.%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84%20Instruction%20Set%20Architecture,%20ISA/</link>
      <pubDate>Sat, 31 Aug 2024 13:03:24 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/08/31/computer_system_basics/computer_composition/1.%20%E6%8C%87%E4%BB%A4%E9%9B%86%E6%9E%B6%E6%9E%84%20Instruction%20Set%20Architecture,%20ISA/</guid>
      <description>&lt;p&gt;ISA 可以看作是连接汇编层代码和硬件的操控指令集合, 例如 汇编会有 &lt;code&gt;ADD r1, r2, r3&lt;/code&gt; 的指令，我们利用 ISA 就会将指令转换为 &lt;code&gt;r2 + r3 -&amp;gt; r1&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;常见分类-classification&#34;&gt;常见分类 Classification&lt;/h2&gt;
&lt;h3 id=&#34;x86-架构&#34;&gt;x86 架构&lt;/h3&gt;
&lt;p&gt;由 intel 公司开发，为 32 位处理器，一般在上世纪末的电脑中比较常见&lt;br&gt;
由于 $2^{32}\approx 2^2 \times 2^{30} = 4\times 1000^3 = 4GB$ 即地址循迹的范围小于等于 4GB, 也就是内存大小不超过 4G&lt;/p&gt;</description>
    </item>
    <item>
      <title>3. 寄存器 与 计数器 register and counter</title>
      <link>https://www.whoami-wesleyyou.top/2024/08/05/computer_system_basics/computer_composition/basic_circuits/3.%20%E5%AF%84%E5%AD%98%E5%99%A8%20%E4%B8%8E%20%E8%AE%A1%E6%95%B0%E5%99%A8%20register%20and%20counter/</link>
      <pubDate>Mon, 05 Aug 2024 20:03:22 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/08/05/computer_system_basics/computer_composition/basic_circuits/3.%20%E5%AF%84%E5%AD%98%E5%99%A8%20%E4%B8%8E%20%E8%AE%A1%E6%95%B0%E5%99%A8%20register%20and%20counter/</guid>
      <description>&lt;p&gt;对于计算机而言，我们常常会讨论到“磁盘”的概念，磁盘就是存储数据信息的重要电子元件，那么，这里就让我们从头开始，看看怎么存储 1 位的数据，再到怎么存储 1 字节的数据，以后再以此类推，我们就可以做出更大的“寄存器”了&lt;/p&gt;
&lt;h2 id=&#34;1-位寄存器&#34;&gt;1 位寄存器&lt;/h2&gt;
&lt;p&gt;首先，我们要明确这个寄存器的必备功能: &lt;strong&gt;写入&lt;/strong&gt;以及&lt;strong&gt;输出&lt;/strong&gt;&lt;br&gt;
写入应该需要有一个信号，不能随便来一个数据就能写入; 输出也要有一个信号，需要的时候输出&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 继电器，电子管和晶体管</title>
      <link>https://www.whoami-wesleyyou.top/2024/08/05/computer_system_basics/computer_composition/basic_circuits/1.%20%E7%BB%A7%E7%94%B5%E5%99%A8%EF%BC%8C%E7%94%B5%E5%AD%90%E7%AE%A1%E5%92%8C%E6%99%B6%E4%BD%93%E7%AE%A1/</link>
      <pubDate>Mon, 05 Aug 2024 20:03:05 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/08/05/computer_system_basics/computer_composition/basic_circuits/1.%20%E7%BB%A7%E7%94%B5%E5%99%A8%EF%BC%8C%E7%94%B5%E5%AD%90%E7%AE%A1%E5%92%8C%E6%99%B6%E4%BD%93%E7%AE%A1/</guid>
      <description>&lt;h2 id=&#34;继电器-relay&#34;&gt;继电器 relay&lt;/h2&gt;
&lt;p&gt;输入小电流，输出大电流，起到中继的作用&lt;/p&gt;
&lt;h3 id=&#34;为什么bug和虫子是一个意思&#34;&gt;为什么bug和虫子是一个意思？&lt;/h3&gt;
&lt;p&gt;在早期ibm制造的继电器计算机中，经常会在故障的继电器中找到死掉的虫子，于是我们称计算机的问题为 bug&lt;/p&gt;
&lt;h2 id=&#34;真空管&#34;&gt;真空管&lt;/h2&gt;
&lt;p&gt;热电子发射是真空条件下加热金属的时候电子从材料表面逸出的现象&lt;br&gt;
每一秒可以开闭数千次&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. 加法器，减法器和乘法器</title>
      <link>https://www.whoami-wesleyyou.top/2024/07/05/computer_system_basics/computer_composition/basic_circuits/2.%20%E5%8A%A0%E6%B3%95%E5%99%A8%EF%BC%8C%E5%87%8F%E6%B3%95%E5%99%A8%E5%92%8C%E4%B9%98%E6%B3%95%E5%99%A8/</link>
      <pubDate>Fri, 05 Jul 2024 01:47:35 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/07/05/computer_system_basics/computer_composition/basic_circuits/2.%20%E5%8A%A0%E6%B3%95%E5%99%A8%EF%BC%8C%E5%87%8F%E6%B3%95%E5%99%A8%E5%92%8C%E4%B9%98%E6%B3%95%E5%99%A8/</guid>
      <description>&lt;h2 id=&#34;全加器&#34;&gt;全加器&lt;/h2&gt;
&lt;p&gt;考虑进位的加法称为全加，能够完成全加运算的电路称为全加器，一个基本全加器能够完成两个一位二进制数的全加运算，因此它具有三个输入端和两个输出端，其中 $X_i, Y_i$ 为加数，$C_{i - 1}$ 相邻低位进来的进位数， $S_i$ 为输出和，$C_i$ 为向高位邻位进位数&lt;/p&gt;</description>
    </item>
    <item>
      <title>2. 空间复杂度</title>
      <link>https://www.whoami-wesleyyou.top/2024/06/16/computer_system_basics/structure_algorithm/2.%20%E7%A9%BA%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6/</link>
      <pubDate>Sun, 16 Jun 2024 15:50:24 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/06/16/computer_system_basics/structure_algorithm/2.%20%E7%A9%BA%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6/</guid>
      <description>&lt;h2 id=&#34;o1--常量空间复杂度&#34;&gt;O(1) — 常量空间复杂度&lt;/h2&gt;
&lt;p&gt;不管输入数据的规模如何，算法所需的内存空间大小是固定的。&lt;br&gt;
数组中查找最大元素。这个操作只需要一个变量来保存当前找到的最大值，因此空间复杂度是O(1)。&lt;/p&gt;
&lt;h2 id=&#34;olog-n--对数空间复杂度&#34;&gt;O(log n) — 对数空间复杂度&lt;/h2&gt;
&lt;p&gt;需要的空间随输入数据的规模的对数增长。&lt;br&gt;
递归实现的二分查找。在每次递归调用中，问题的规模都&lt;strong&gt;减半&lt;/strong&gt;，因此最大的调用深度是log n，相应地，栈的空间也是O(log n)。&lt;/p&gt;</description>
    </item>
    <item>
      <title>1. 时间复杂度</title>
      <link>https://www.whoami-wesleyyou.top/2024/06/14/computer_system_basics/structure_algorithm/1.%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6/</link>
      <pubDate>Fri, 14 Jun 2024 20:54:28 +0800</pubDate>
      <guid>https://www.whoami-wesleyyou.top/2024/06/14/computer_system_basics/structure_algorithm/1.%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6/</guid>
      <description>&lt;h2 id=&#34;o1&#34;&gt;O(1)&lt;/h2&gt;
&lt;p&gt;常见的就是直接访问一个数组中某个元素的内容&lt;br&gt;
这种算法一般不会受到输入数据大小的影响&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-cpp&#34; data-lang=&#34;cpp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;on&#34;&gt;O(n)&lt;/h2&gt;
&lt;p&gt;线性时间复杂度，一般是&lt;strong&gt;遍历&lt;/strong&gt;一阶数组中的所有元素&lt;br&gt;
这会随着输入数据量的大小线性增大&lt;/p&gt;
&lt;h2 id=&#34;olog-n&#34;&gt;O(log n)&lt;/h2&gt;
&lt;p&gt;对数时间复杂度，一般自常见的是用在对分查找。&lt;br&gt;
或者常见的 m 叉树结构我们有 $O(log_m n)$ 的时间复杂度&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
