LogSeq/pages/hls__ostep_1680491762166_0.md
2023-04-07 00:11:22 +08:00

19 KiB
Raw Blame History

file-path:: ../assets/ostep_1680491762166_0.pdf

  • virtualization, concurrency, and persistence ls-type:: annotation hl-page:: 1 hl-color:: yellow id:: 642a452b-2dc9-4566-b8a8-95f0caa7b8e3
  • didactic 道德说教的;教诲的; hl-page:: 2 ls-type:: annotation id:: 642a7c33-ca04-447a-a357-88236d0b9360 hl-color:: green
  • Cramming 填塞;填鸭式用功;考试前临时硬记 hl-page:: 3 ls-type:: annotation id:: 642a80b7-43a1-40ba-ad01-815cb171572f hl-color:: green
  • fond 喜爱(尤指认识已久的人);喜爱(尤指长期喜爱的事物) hl-page:: 4 ls-type:: annotation id:: 642a80ef-5f31-422a-8227-3842faa4eb8d hl-color:: green
  • the operating system as a virtual machine, standard library and resource manager hl-page:: 25 ls-type:: annotation id:: 642bb88b-f481-4af6-afb6-7375d37654ce hl-color:: yellow
  • illusion 错觉,幻象 hl-page:: 27 ls-type:: annotation id:: 642bb978-1efe-418e-8894-8493bfd4f6bb hl-color:: green
  • virtualizing the CPU: run many programs at the same time hl-page:: 27 ls-type:: annotation id:: 642bb9c2-efb8-4960-a7bd-36afe1cc0b1d hl-color:: yellow
  • virtualizing memory: each process accesses its own private virtual address space hl-page:: 29 ls-type:: annotation id:: 642bbaae-582b-4b1c-bc60-e709931085e7 hl-color:: yellow
  • intricate 错综复杂的 ls-type:: annotation hl-page:: 33 hl-color:: green id:: 642bbca9-67e2-45d3-a131-968df46c0cef
  • heyday 全盛时期 ls-type:: annotation hl-page:: 39 hl-color:: green id:: 642bc0e8-ee33-46a6-bf83-407cc1e64737
  • incredulous 不肯相信的;不能相信的;表示怀疑的 hl-page:: 45 ls-type:: annotation id:: 642bc1b3-459e-4e76-b36c-406daba96726 hl-color:: green
  • The definition of a process, informally, is quite simple: it is a running program ls-type:: annotation hl-page:: 47 hl-color:: yellow id:: 642bc39c-f56a-488f-a751-1532e413d474
  • To implement virtualization of the CPU, low-level machinery and some high-level intelligence. hl-page:: 47 ls-type:: annotation id:: 642bc417-a3af-4132-b4b9-9fec9749fc9b hl-color:: yellow
    • mechanisms are low-level methods or protocols that implement a needed piece of functionality hl-page:: 47 ls-type:: annotation id:: 642bc41d-8b68-46d9-908e-ab14b53a859b hl-color:: yellow
    • Policies are algorithms for making some kind of decision within the OS ls-type:: annotation hl-page:: 48 hl-color:: yellow id:: 642bc579-a1cc-4b67-a8c5-5a33f274c634
  • inventory 库存;财产清单; hl-page:: 48 ls-type:: annotation id:: 642bc8a9-1a7d-4236-86ce-65b0498e9e01 hl-color:: green
  • three states of a process: Running Ready Blocked hl-page:: 51 ls-type:: annotation id:: 642bd104-6b57-44f2-9f10-e5107a926079 hl-color:: yellow
  • nitty-gritty 本质;事实真相;实质问题 hl-page:: 55 ls-type:: annotation id:: 642c279e-0187-4175-abfb-5fcf4e534ae8 hl-color:: green
  • KEY PROCESS TERMS ls-type:: annotation hl-page:: 56 hl-color:: yellow id:: 642c27e3-d7d6-41d8-9832-73674615a246
  • Interlude: Process API hl-page:: 60 ls-type:: annotation id:: 642cc7d2-cd33-4dd6-879f-72f1070ed96d hl-color:: yellow Syscall-fork, wait, exec
  • Get it right. Neither abstraction nor simplicity is a substitute for getting it right ls-type:: annotation hl-page:: 65 hl-color:: yellow id:: 642cc975-cf26-431c-8c38-617da01d89ee
  • the separation of fork() and exec() is essential in shell, because it lets the shell run code after the call to fork() but before the call to exec(); this code can alter the environment of the about-to-be-run program hl-page:: 65 ls-type:: annotation id:: 642ccc92-baa5-4b54-8525-9a664698c669 hl-color:: yellow
  • imperative 必要的,命令的;必要的事 hl-page:: 67 ls-type:: annotation id:: 642ccf62-0b5a-41db-899e-3e99a69c2eac hl-color:: green
  • control processes through signal subsystem hl-page:: 67 ls-type:: annotation id:: 642cd11a-eea5-48f8-b4d1-b225f37ccdb4 hl-color:: yellow
  • Limited Direct Execution: Direct execution is to simply run the program directly on the CPU. hl-page:: 74 ls-type:: annotation id:: 642cd1eb-c058-484a-ac25-782e37082bc6 hl-color:: yellow
  • aspiring 有追求的,有抱负的 hl-page:: 75 ls-type:: annotation id:: 642cd2f2-c565-4309-951a-1f809da9beff hl-color:: green
  • user mode and kernel mode hl-page:: 76 ls-type:: annotation id:: 642cd3e3-3fa6-43a6-a37a-cae62c634654 hl-color:: yellow
    • In user mode, code is restricted in what it can do, otherwise the processor will raise an exception
    • User code perform system call to do privileged operation.
    • To execute a system call, use trap and return-from-trap instruction: jump to/from kernel and change the privilege level.
  • Limited Direct Execution Protocol-interesting figure illustrating how system call is done hl-page:: 78 ls-type:: annotation id:: 642cd6be-083b-4ecd-b220-aafef97a8b65 hl-color:: yellow
  • wary 谨慎的;考虑周到的 hl-page:: 79 ls-type:: annotation id:: 642cd6e9-21fc-49c7-b0bb-0c9ba3b7a524 hl-color:: green
  • Switching Between Processes: how OS regain control of the CPU hl-page:: 80 ls-type:: annotation id:: 642cd90e-ab6b-4d4d-8312-cd8c69efdac8 hl-color:: yellow
    • Cooperative Approach: wait for a system call. 1. The processes are expected to give up the CPU periodically through system call yield(which does nothing except to transfer control to the OS). 2. The process does something that causes a trap
    • Non-Cooperative Approach: timer interrupt.
    • Context switch: save a few register values for the currently-executing process. Two types of register saves/restores: TI, hardware save state to kernel stack; context switch, OS save kernel registers and restore everything to return from trap
  • malfeasance 渎职;不正当行为 hl-page:: 81 ls-type:: annotation id:: 642cdc2e-329c-423e-a65a-0a53fb6eaa76 hl-color:: green
  • scoff 嘲笑;愚弄;笑柄 hl-page:: 83 ls-type:: annotation id:: 642ce319-8087-4252-b51d-42f749f7c283 hl-color:: green
  • enact 制定(法律);通过(法案) ls-type:: annotation hl-page:: 83 hl-color:: green id:: 642ce357-9914-417b-8036-35ae44ac7283
  • whet 引起,刺激(食欲、欲望、兴趣等) hl-page:: 84 ls-type:: annotation id:: 642cef47-0c2f-482f-8b61-9a715e5438e5 hl-color:: green
  • analogous 相似的,可比拟的 ls-type:: annotation hl-page:: 86 hl-color:: green id:: 642cf0c1-59a2-410e-8f45-517f66ef47f9
  • workload assumptions: Each job, runs for the same amount of time, arrives at the same time, runs to completion, uses only CPU, and run-time is known hl-page:: 90 ls-type:: annotation id:: 642cf292-4464-4c8f-8639-3a194484d4c0 hl-color:: yellow
    • Quite unrealistic, but modern preemptive scheduling somewhat mimics part of these assumptions
  • scheduling metric: turnaround time, aka completion - arrival hl-page:: 91 ls-type:: annotation id:: 642cf48d-b312-4af1-a2ff-d55cf9f32e48 hl-color:: yellow
  • conundrum 谜,猜不透的难题,难答的问题 ls-type:: annotation hl-page:: 91 hl-color:: green id:: 642cf4c4-d246-48f2-a6ef-f14c77684ad9
  • First In, First Out (FIFO/FCFS) algorithm hl-page:: 91 ls-type:: annotation id:: 642cf4f9-4afd-4240-ac76-5522285fa1eb hl-color:: yellow
    • Bad average turnaround when long job runs first(The jobs run for different amount of time)
    • Convoy effect: a number of relatively-short potential consumers of a resource get queued behind a heavyweight resource consumer
  • Shortest Job First(SJF) hl-page:: 93 ls-type:: annotation id:: 642cf705-4a47-4daa-a542-43c4ae6f239e hl-color:: yellow
    • assuming that jobs all arriving at the same time, it could be proven that SJF is indeed an optimal scheduling algorithm
    • Downgrade to the same problem of Convey Effect when jobs don't arrive at the same time. For example, short jobs arrive shortly after the long job.
  • Shortest Time-to-Completion First (STCF) ls-type:: annotation hl-page:: 94 hl-color:: yellow id:: 642cfce4-67f5-4315-bf81-445922b8ae54
    • Basically, it is SJF(by our definition is a non-preemptive scheduler) with preemption. When a new job enters the system, STCF schedules to the job with the least time left among all present jobs(including the new guy).
  • Metric: Response Time. Defined as resp = firstrun - arrival. Compare to ((642cf48d-b312-4af1-a2ff-d55cf9f32e48)) hl-page:: 95 ls-type:: annotation id:: 642e41ac-3b8f-4fe3-a9ef-e2adeeadfe9d hl-color:: yellow
    • For this metric, STCF is not that good.
  • Round-Robin (RR) ls-type:: annotation hl-page:: 96 hl-color:: yellow id:: 642e435d-7116-4d2c-9ec3-889558ba2dca
    • Not run jobs to completion But run a job for a time slice and then Switch to the next job in the run queue. Repeat until the jobs are done
    • Good for Response Time, bad for Turnaround Time.
    • Length of time slice is critical, in theory the shorter the better performance under response time metric. However, cost of context switching will dominate overall performance. The cost of context switching comes not only from save/restore registers, but also from caches or something alike.
  • amortization 分期偿还;折旧;(均摊) hl-page:: 97 ls-type:: annotation id:: 642e4473-4162-4320-91af-fba22e79be25 hl-color:: green
  • pessimal 最差的;最坏的 ls-type:: annotation hl-page:: 97 hl-color:: green id:: 642e4a5d-37c1-4484-b2ac-913e40d8a2dc
  • Incorporating I/O: Overlap. Basic idea is to treat each CPU burst(rather than the whole job) as a job, so that the job is divided into parts. This enables the scheduler to choose another job to run when the job is doing IO hl-page:: 98 ls-type:: annotation id:: 642e4ed2-7674-4a5f-bb65-67541b97db95 hl-color:: yellow
  • Multi-level Feedback Queue (MLFQ) ls-type:: annotation hl-page:: 103 hl-color:: yellow id:: 642e5117-90c3-41db-9f15-45f3ba9edf91
    • Workload: a mix of interactive jobs that are short-running, and some longer-running “CPU-bound” jobs
    • Basic rules: each job assigned to a priority level and MLFQ decides which job to run by priority. In this scheme, a job with higher priority runs first, and jobs with the same priority RR. ((642ecc9e-b28b-4951-aaf6-1191e867b34f))
    • Change priority: set priority based on its observed behavior, for example, keep high priority for interactive jobs which frequently relinquish CPU. collapsed:: true
      • one of the major goals of the algorithm: It doesnt know whether a job will be short or job, it first assumes it might be short, thus giving high priority. If it actually is short, it will run quickly and complete; if it is not, it will slowly move down the queues, and thus soon prove itself to be a long-running more batch-like process. hl-page:: 107 ls-type:: annotation id:: 642ece05-2fa8-4a24-88e2-f2550cfdd2ed hl-color:: yellow
      • Approximates SJF
    • Basic rules for MLFQ: hl-page:: 104 ls-type:: annotation id:: 642ecc9e-b28b-4951-aaf6-1191e867b34f hl-color:: yellow collapsed:: true
      • Rule 1: If Priority(A) > Priority(B), A runs (B doesnt).
      • Rule 2: If Priority(A) = Priority(B), A & B run in RR.
    • Problematic priority adjustment algorithm hl-page:: 105 ls-type:: annotation id:: 642ecd09-c81b-4127-8bfa-e1fbb78ba583 hl-color:: yellow collapsed:: true
      • Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue).
      • Rule 4a: If a job uses up an entire time slice while running, its priority is reduced. id:: 642ecd25-c824-4dcd-9a6a-43a717dd5b1e Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the same priority level.
        • Problem 1: starvation. id:: 642ecd3f-c076-42f1-ba24-7f363eba9e14 If there are too many interactive jobs occupying the CPU in combination, then the long jobs will never get to run
        • Problem 2: game the scheduler. For example, a CPU-bound job intentionally issue a trivial IO request just before its time slice is over, so that it will not be moved to lower queue although it should be.
        • Problem 3: program behavior change. id:: 642ed383-c27c-401c-b77f-66e7ec60ba5e
    • The Priority Boost ls-type:: annotation hl-page:: 109 hl-color:: yellow id:: 642ed47c-9ba8-4451-b6b3-6ca6ee1dbdda collapsed:: true
      • Rule 5: After some time period S, move all the jobs in the system to the topmost queue.
      • This solves the problem of ((642ecd3f-c076-42f1-ba24-7f363eba9e14)) and ((642ed383-c27c-401c-b77f-66e7ec60ba5e)). Since the priorities will get recalculated periodically, the scheduler re-learns the jobs' traits which may have changed.
      • However, how to choose such S is a problem.
        • voo-doo constants ls-type:: annotation hl-page:: 109 hl-color:: yellow id:: 642ed799-d933-441a-a043-06e47877c0d9
    • Better Accounting ls-type:: annotation hl-page:: 110 hl-color:: yellow id:: 642ed5f6-2a74-4a24-9f69-a472cf644fc9 collapsed:: true
      • Rule 4: Once a job uses up its time allotment at a given level (regardless of how many times it has given up the CPU), its priority is reduced.
      • This substitutes ((642ecd25-c824-4dcd-9a6a-43a717dd5b1e))
    • parameterized scheduler hl-page:: 110 ls-type:: annotation id:: 642ed6a2-c04b-4f03-a86f-1d70933c0d42 hl-color:: yellow
  • relinquish 交出,让给;放弃 hl-page:: 105 ls-type:: annotation id:: 642ec9be-dd64-4a66-ab7a-3f0ee376e055 hl-color:: green
  • culprit 犯人,罪犯;被控犯罪的人 ls-type:: annotation hl-page:: 110 hl-color:: green id:: 642ed5fe-3314-4020-a4fc-b1b75ea987b9
  • Proportional-share(fair-share) scheduler hl-page:: 115 ls-type:: annotation id:: 642eda22-bd34-42e4-b7e4-1107636d1fbc hl-color:: yellow
    • Instead of optimizing for turnaround or response time, the scheduler tries to guarantee that each job obtain a certain percentage of CPU time.
    • tickets: represent the share of a resource that a process should receive hl-page:: 115 ls-type:: annotation id:: 642edaa2-78d2-4fde-8b14-584b7d39fa24 hl-color:: yellow
      • ticket currency: kind of user interface. Users allocate tickets freely to their own processes, and the system converts user tickets to global tickets according to some kind of exchange rate, in order to achieve fairness between users. hl-page:: 117 ls-type:: annotation id:: 642edc09-1329-4eca-95ad-7f62b48875e2 hl-color:: yellow
      • ticket transfer: kind of cooperation between processes. A process temporarily hands off its tickets to another process. hl-page:: 117 ls-type:: annotation id:: 642edc0f-464d-4616-9313-92b640cecec5 hl-color:: yellow
      • ticket inflation: another kind of cooperation. A process can temporarily raise or lower the number of tickets it owns, to indicate that it needs CPU. hl-page:: 117 ls-type:: annotation id:: 642edc14-74d6-4758-a21f-d615d2ee51c9 hl-color:: yellow
    • Lottery scheduling hl-page:: 115 ls-type:: annotation id:: 642edb1d-7740-4459-bb42-0c6a84156475 hl-color:: yellow
      • Scheduler randomly pick a winning ticket(i.e. number the tickets 1-N, and do a range random), the job which holdes this ticket runs. The more tickets a job holds, the higher chance it is chosen to run. Thus the CPU is shared by proportion, probabilistically.
      • Lottery Fairness Study: When the job length is not very long, unfairness can be quite severe. Only as the jobs run for a significant number of time slices does the lottery scheduler approach the desired outcome. ls-type:: annotation hl-page:: 119 hl-color:: yellow id:: 642eded0-39d0-40aa-8b28-c273d39f90c2
    • Stride scheduling: a deterministic fair-share scheduler. hl-page:: 120 ls-type:: annotation id:: 642edf4f-7c7f-477f-acae-0969da13731e hl-color:: yellow
      • Each job has a stride, which is inverse in proportion to the tickets it has (conceptually like reciprocal). Every time a process runs, increase its counter(called its pass value) by 1 stride. The scheduler picks the process with lowest pass value to run
      • Why still lottery scheduling? No global states! Thus much easier to implement.
    • Problem: How to determine how many tickets to assign to your processes with different purposes and traits? MLFQ does this automatically, but here nobody does this.
  • Completely Fair Scheduler (CFS) ls-type:: annotation hl-page:: 121 hl-color:: yellow id:: 642ee1b9-281d-4589-ab90-e776507dd04f
    • Goal: to fairly divide a CPU evenly among all competing processes. hl-page:: 122 ls-type:: annotation id:: 642ee242-d382-4685-86b4-b3169fcc4fcf hl-color:: yellow
    • virtual runtime: As each process runs, it accumulates vruntime. And the scheduler picks the lowest one to run. hl-page:: 122 ls-type:: annotation id:: 642ee25b-1f3a-4b7c-a721-fa60f5fa5d2f hl-color:: yellow
      • For blocked processes: need to alter vruntime of a job when it wakes up. Otherwise, its vruntime would be too small thus breaking fairness. CFS chooses the minimum vruntime in the running process table. hl-page:: 125 ls-type:: annotation id:: 642ee7e4-20d2-44d5-8407-288a8a2e1769 hl-color:: yellow
    • Parameters
      • sched_latency: when running, scheduler divides this value by the number of running processes n. The result is used as the time slice for each process. This simple approach is adaptive to dynamic change of running processes. hl-page:: 122 ls-type:: annotation id:: 642ee303-c289-4e55-a0c5-bc4f534fa882 hl-color:: yellow
      • min_granularity: minimum of time slice, to avoid reducing performance too much hl-page:: 122 ls-type:: annotation id:: 642ee3d6-827b-4d80-b6c3-9cb8253a16d6 hl-color:: yellow
    • Weighting (Niceness): every process is assigned to a nice value ranging from -20 to 19. The smaller nice value, the higher priority. A nice value is mapped to some weight through a carefully built table. hl-page:: 123 ls-type:: annotation id:: 642ee44f-5fca-4d7d-b688-ff4ac22be23a hl-color:: yellow
      • Given the weight, the time slice can be calculated, and the calculation for vruntime needs adaptation to guarantee the time slice.
         time\_slice_k = \frac{weight_k}{\sum weight_i}\cdot sched\_latency \\ vruntime_i = vruntime_i + \frac{weight_0}{weight_i} \cdot runtime_i
  • hallmark 特征;特点: ls-type:: annotation hl-page:: 126 hl-color:: green id:: 642ee5dd-9183-4122-9dee-06ff7fb9be46
  • panacea 万能药 hl-page:: 126 ls-type:: annotation id:: 642ee8c2-89fe-4e7b-bf6d-bb0e379f8fe2 hl-color:: green
  • remedy 补救方法 ls-type:: annotation hl-page:: 129 hl-color:: green id:: 642eeb3a-8803-4c73-84a7-cc48c903f10f
  • proliferation 涌现;增殖 ls-type:: annotation hl-page:: 129 hl-color:: green id:: 642eeb44-cf62-4cf6-81cb-f1f6423cb66d
  • cache coherence ls-type:: annotation hl-page:: 132 hl-color:: yellow id:: 642eecc1-d07d-4e48-bcd5-b84db831b241