免費詳解 / 台大 / 硬體 / 102

102 台大資工所考古題解答|硬體逐題詳解

102 台大資工所硬體考古題的逐題詳解,共 19 題,免費公開。

逐題詳解

12%

I. Architecture [50%] 第一部分:回答這部分的問題之前,請先閱讀以下這摘錄自科技網站上的文章片段(第 1–4 題都依這篇文章作答):

Intel pitches ARM alternative to data centers—including Facebook's by Jon Brodkin – Dec 12 2012, posted on http://arstechnica.com

Intel today (2012.12.12) launched an Atom system-on-chip (SoC) line that combines extremely low power usage with server-class features, including virtualization technology and Error-Correcting Code (ECC) for higher reliability. The Intel Atom S1200 chips are for microservers as well as storage and networking systems that need energy efficiency and enterprise features that—Intel says—you just can't get in ARM chips. Intel called the S1200 "the world's first 6-watt server-class processor," and said microservers using the chip will be able to fit 1,000 nodes into a single rack.

ARM may dominate smartphones and tablets, but Intel hopes to lead the way in bringing smartphone CPUs to data centers. "Right now there are no ARM-based enterprise-class servers," Intel VP Diane Bryant said at a press conference for today's announcement. In addition to the hardware-assisted virtualization and ECC features already mentioned, Bryant noted that the Intel S1200 chips are 64-bit and support the x86 software prevalent in today's data centers.

The prospects of ARM servers from AMD (and some other companies) are intriguing, but ARM isn't a major player in the data center yet. With Atom S1200, Intel hopes to pre-empt ARM's entry into the server market. To prove the Atom chips' usefulness, Intel trotted out partners HP and Microsoft to talk about servers that will use the S1200 SoC and Windows Server's support for the new product line.

Today, Facebook VP of hardware design and supply chain Frank Frankovsky said, "Xeon-class processors have helped us scale Facebook very effectively so far." But not every workload needs what Frankovsky called "brawny cores." Now that "smartphone-class CPUs" for servers are 64-bit and include ECC, they're ready for certain parts of the Facebook infrastructure, he said.

"We've applied what I'll call brawny cores unilaterally across our environment," Frankovsky said. "What's interesting about these smartphone-class CPUs is we can right-size them to the needs of maybe the photo storage tier, for example. Maybe that's a great place to start, where we don't need a brawny core, what we need is maybe a smartphone-class CPU that also includes 64-bit and also includes ECC." Frankovsky noted that you might need two or three times as many Atom (or "wimpy") cores to do the same work Xeon-class processors handle, but ultimately come out ahead when measuring "how much useful work you can get done per watt and per dollar."

Those advantages only exist for certain types of workloads—the key is different CPUs for different applications. According to HP, compute-intensive applications still require Xeons, but the Atoms will be appropriate for "light scale-out applications" such as static Web serving and in-memory caching.

1. [2%] The ARM processor family is already widely used in the data center as enterprise-class servers, and Intel wants to compete in the same market by selling this new Atom S1200 chip. TRUE or FALSE?

文章 Bryant 說「Right now there are no ARM-based enterprise-class servers」,ARM 在 data center 還不是主要玩家 → F

F

22%

2. [2%] Having a 64-bit ISA is critical to data center applications because a 64-bit ISA is much faster than a 32-bit ISA in terms of the computational speed. TRUE or FALSE?

64-bit 的好處是 address space 大(記憶體超過 4 GB)、能直接做 64-bit 整數運算;不是「計算速度快很多」

F

32%

3. [2%] According to the article, Facebook is interested in replacing some brawny cores (e.g. XEON) with ARM or Atom cores for the photo storage tier. TRUE or FALSE?

Frankovsky:photo storage tier 不需要 brawny core,smartphone-class CPU(64-bit+ECC)就夠

T

42%

4. [2%] Hardware-assisted virtualization is important to the server market, because a modern virtual machine monitor can take advantage of the virtualization support to speed up virtual machines. TRUE or FALSE?

VT-x 這類硬體支援讓 VMM 不用靠 binary translation/trap 處理 sensitive instruction,VM 跑得快 → T

T

52%

Now, to further understand this article, we found the original presentation on the Web, which includes the charts shown below. According to the data on the charts, Facebook has built two systems to perform a specific type of work: one was built with Wimpy cores (Wimpy-Core System, or WCS for short), and the other was built with Brawny cores (Brawny-Core System, or BCS for short).(第 5–8 題都依這三張圖作答;柱高為讀圖的近似值)

Computing Powerwork – normalized00.20.40.60.81.01.2Wimpy CoreBrawny CoreCores Requiredcores / work00.20.40.60.81.01.21.41.6Wimpy CoreBrawny CoreWatts Requiredwatts / work01234567Wimpy CoreBrawny Core

5. [2%] In this case, the computing power refers to: (CHOOSE ONE)

(A) Latency, measured by the execution time required to get the work done

(B) Throughput, measured by the amount of work that can be done in a given time period

(C) Power consumption, measured by the cost of power dissipation for the system

(D) The power of ISA, measured by the average cycles per instruction (CPI)

縱軸是 work(normalized):同一段時間內做完多少工作 → throughput

(A)latency 是做完一件事要多久;(C)是第三張圖的 watts;(D)CPI 與 work 無關

(B)

62%

6. [2%] Based on the left-most chart, the two systems perform equally well. According to the article and the data on the other charts, which of the following is false? (CHOOSE ONE)

(A) A Brawny Core completes a task much sooner than a Wimpy Core does.

(B) The power efficiency of the BCS is about half of the WCS.

(C) The WCS has ~3 times more processor cores than the BCS has.

(D) Overall, the WCS consumes more power than the BCS.

兩系統做的 work 一樣(1.0)。cores/work:WCS 約 1.2、BCS 約 0.45;watts/work:WCS 約 2.7、BCS 約 5.3

(A) 同樣的 work BCS 只要 0.45 個 core → 一個 Brawny core 的產出約 2.7 個 Wimpy core,做得比較快 → T

(B) work/watt:WCS \(1/2.7\)、BCS \(1/5.3\),BCS 約為 WCS 的 \(\tfrac12\) → T

(C) \(1.2/0.45\approx2.7\approx3\) → T

(D) WCS 2.7 W/work 小於 BCS 5.3 W/work,WCS 耗電比較少 → F

(D)

72%

7. [2%] Let us compare the amount of work that the system can get done per watt and per dollar. Suppose that one Wimpy Core costs one dollar and one Brawny Core costs 3 dollars, which of the following is the ratio of work done per watt and per dollar between WCS and BCS? (CHOOSE ONE)

(A) The ratio is about 0.9. Facebook should choose BCS.

(B) The ratio is about 0.9. Facebook should choose WCS.

(C) The ratio is 0.2. The Facebook should choose BCS.

(D) The ratio is 0.2. The Facebook should choose WCS.

每單位 work 的成本:WCS \(1.2\times\$1=\$1.2\);BCS \(0.45\times\$3=\$1.35\)

WCS 對 BCS 的成本比 \(=1.2/1.35\approx0.9\) → 每塊錢 WCS 做的 work 略多(約 \(1/0.9\) 倍)

每瓦:WCS 2.7 W/work、BCS 5.3 W/work → WCS 約 2 倍好

每瓦、每塊錢兩項都是 WCS 比較划算 → 選 WCS

每單位 work 的成本兩邊只差約一成,對得上的是 0.9,0.2 與讀圖的數字對不上

(B)

82%

8. [2%] Which of the following applications may NOT be suitable for the new Intel S1200 chips? (CHOOSE ONE)

(A) Web serving applications

(B) Big-data simple search systems

(C) Weather simulation and forecast engine

(D) Low-power network storage system

文章:compute-intensive 的應用還是要 Xeon;Atom 適合 light scale-out(static Web serving、in-memory caching)、storage、networking

天氣模擬是 compute-intensive

(C)

93%

Now, let us try to design a system using the knowledge in the computer architecture course and what we just learned from the article.

As illustrated in the article, availability and speed are well-known metrics for servers, but power consumption is becoming increasingly important. Let us consider a big-data analysis system which runs the Apache Hadoop open-source software. The system is divided into two parts to handle different types of workload: (1) The data are distributed on the disks on the Filesystem Serving nodes. (2) The MapReduce Computing nodes acquire data from the Filesystem nodes and perform a MapReduce program in parallel.

The Hadoop runtime system handles the I/O details for the program, so the programmer can focus on the computation. The transactions between the Filesystem nodes and the Computing nodes are of 64MB size on average. Suppose the workloads running on the two types of nodes have the following parameters:

WorkloadUser-Space Instructions
per Transaction
OS Instructions per Transaction
for Disk Operation
OS Instructions per Transaction
for Network Operation
Hadoop MapReduce Computing200,000,0000100,000
Hadoop Filesystem Serving100,00030,000,00030,000,000

9. [3%] Suppose we build the system with Brawny cores. A Brawny Core can perform 6 billion instructions per second. Assume the disk and network operations are NOT the bottleneck. How fast can a Brawny Core perform the transactions for each type of workload? (CHOOSE ONE)

(A) 30 transactions/s for MapReduce Computing, 100 transactions/s for Filesystem Serving

(B) 30 transactions/s for MapReduce Computing, 600,000 transactions/s for Filesystem Serving

(C) 30,000 transactions/s for MapReduce Computing, 100,000 transactions/s for Filesystem Serving

(D) 5,000 transactions/s for MapReduce Computing, 10,000 transactions/s for Filesystem Serving

每筆 transaction 的指令數 \(=\) user + disk OS + network OS

MapReduce Computing:\(200{,}000{,}000+0+100{,}000=200{,}100{,}000\)

\(\dfrac{6\times10^9}{2.001\times10^8}\approx29.98\approx30\) transactions/s

Filesystem Serving:\(100{,}000+30{,}000{,}000+30{,}000{,}000=60{,}100{,}000\)

\(\dfrac{6\times10^9}{6.01\times10^7}\approx99.8\approx100\) transactions/s

(A)

103%

10. [3%] Suppose both the disk subsystem and the network interface are connected to the PCI Express x16 ports on each server. Each lane of a PCIe is 500 MB/sec. Assume the disk subsystem and network interface are NOT the bottleneck. What is the maximum transaction rate for the MapReduce Computing node and the Filesystem Serving node, each with 4 of the Brawny cores mentioned in 3(a)? (CHOOSE ONE)

(A) 120,000 transactions/s for MapReduce Computing, 400,000 transactions/s for Filesystem Serving

(B) 120 transactions/s for MapReduce Computing, 400 transactions/s for Filesystem Serving

(C) 120 transactions/s for MapReduce Computing, 125 transactions/s for Filesystem Serving

(D) ~8 transactions/s for MapReduce Computing, ~8 transactions/s for Filesystem Serving

題目的「3(a)」指第 9 題的 Brawny core(6 billion instructions/s)

CPU 上限(4 個 core):MapReduce \(4\times30=120\);Filesystem \(4\times100=400\) transactions/s

PCIe x16:\(16\times500\ \text{MB/s}=8000\ \text{MB/s}\),每筆 64 MB → \(8000/64=125\) transactions/s

瓶頸取小的:MapReduce \(\min(120,125)=120\);Filesystem \(\min(400,125)=125\)

(C)

113%

11. [3%] Assume the Wimpy Core is capable of 2 billion instructions per second, and it does twice as much performance per watt as the Brawny Core for Filesystem Serving, but only half the performance-per-watt of the Brawny Core for MapReduce Computing. Each Wimpy chip contains 2 Wimpy cores, and each Brawny chip contains 4 Brawny cores. Consider only the power consumption of the processors, which of the following design should be the most energy-efficient and cost-effective? (CHOOSE ONE)

(A) 2 Brawny chips for a MapReduce Computing node, 2 Wimpy chip for a Filesystem Serving node

(B) 1 Brawny chip for a MapReduce Computing node, 1 Brawny chip for a Filesystem Serving node

(C) 1 Wimpy chip for a MapReduce Computing node, 1 Brawny chip for a Filesystem Serving node

(D) 1 Brawny chip for a MapReduce Computing node, 1 Wimpy chip for a Filesystem Serving node

Filesystem Serving:Wimpy 的 performance per watt 是 Brawny 的 2 倍 → 用 Wimpy

MapReduce Computing:Wimpy 只有 Brawny 的一半 → 用 Brawny

(D) 兩種 node 都用到效率較高的 core

(A) 的 core 種類也對,但 chip 數是 (D) 的兩倍,成本與待機耗電都多,不是 cost-effective

(B) 的 Filesystem node 用 Brawny、(C) 的 MapReduce node 用 Wimpy,都放在 performance per watt 較差的 core 上

(D)

1210%

第二部分:

12. [10%] Answer the following questions considering a streaming application with the following address stream (byte address): 0, 4, 8, 12, 16, 20, 24, … (i.e., 4*n, where n= 0, 1, 2, 3…)

a. [4%] What are the miss rates of a 32K direct-mapped cache and a two-way associate cache with a 32-byte line?

b. [2%] What types of cache misses is this streaming application experiencing in the 3C model?

c. [4%] Considering two mechanisms to improve cache performance, Victim Cache and Stream Buffer:

Victim Cache: adopting a small fully-associative cache to store cache blocks that have been replaced from the main cache. On a cache miss, both the main cache and the victim cache are searched. A hit in the victim cache is considered as a hit and the data are moved into the main cache.

Stream Buffer: prefetching sequentially adjacent cache lines into a separate buffer, when a particular cache line is brought in. If the data is found in the prefetch buffer, this is considered as a hit and moved into the cache and the next cache line is prefetched. Assume a two-entry stream buffer and assume that the cache latency is such that a cache line can be loaded before the computation on the previous cache line can be completed.

What are the cache miss rates for the Victim Cache mechanism with a 4-entry victim cache and the Stream Buffer mechanism with a two-entry stream buffer assuming a 32K direct-mapped main cache?

a. 一條 line 32 B,每次存取 4 B → 一條 line 內 \(32/4=8\) 次存取

第一次存取新 line 才 miss,其餘 7 次 hit;每條 line 只走過一次,沒有 reuse,所以 associativity 無差別

direct-mapped:\(1/8=12.5\%\);2-way:\(1/8=12.5\%\)

b. 每個 block 都是第一次被碰到,沒有重複使用,不會因為被擠掉而再 miss

全部是 compulsory(cold)miss;沒有 capacity、conflict miss

c. Victim cache:被換出的 line 之後不會再被存取,victim cache 永遠 hit 不到,cold miss 還是 miss

Victim cache(4-entry):\(1/8=12.5\%\)

Stream buffer:第一條 line miss 時把下一條 prefetch 進 buffer;下一條 line 在被用到之前就載好了 → 在 buffer 中 hit,搬進 cache,再 prefetch 後面一條。只有最開頭那一次 miss

Stream buffer(2-entry):steady state \(0\%\)(只剩開頭 1 次 compulsory miss,長串流下趨近 0)

1312%

13. [12%] Assume a pipelined data path of a MIPS processor as shown in Figure 1.

Figure 1: Pipeline Datapath(原題附圖:標準五級 MIPS pipelined datapath,IF/ID、ID/EX、EX/MEM、MEM/WB 四組 pipeline register;branch target 的 Add 放在 EX stage)

Answer this problem set assuming the following instruction mix and access latency of each pipeline stage and pipeline registers:

Addbeqlwsw
45%30%15%10%

Table 1: instruction mix

IFIDEXMEMWBPipeline registers
110ps120ps90ps140ps60ps10ps

Table 2: Pipeline latency

a. [3%] Assuming there is no stall and that 40% of all the conditional branches are taken, in what percentage of clock cycles does the branch adder in the EX stage generate a value that is actually used?

b. [3%] Assuming there is no stall, what is the speed-up achieved by pipelining compared to a single-cycle datapath?

c. [2%] Assuming there is no stall, what percentages of all cycles do we use the data memory?

d. [4%] Assume that the latency of the EX stage becomes 150 ps after adding the forwarding logics. If 20% of the instructions stall for one cycle before adopting forwarding, what percentage of stall cycles need to be eliminated by forwarding in order to get 10% speedup from adding the forward logics compared to the pipeline design without forwarding?

a. no stall → 每個 cycle 退休 1 道指令;branch adder 的結果只有 taken 的 beq 才會用到

\(0.30\times0.40=0.12\)

\(12\%\)

b. single-cycle 的 clock 由最長的指令決定:

指令經過的 stage延遲
addIF+ID+EX+WB380 ps
beqIF+ID+EX320 ps
swIF+ID+EX+MEM460 ps
lwIF+ID+EX+MEM+WB520 ps

single-cycle:每道指令 520 ps(CPI 1)

pipeline:clock \(=\max(110,120,90,140,60)+10=150\) ps,no stall → CPI 1,每道指令 150 ps

speedup \(=520/150\)

\(\approx3.47\)

c. 只有 lw、sw 用 data memory:\(15\%+10\%\) (no stall,每道指令在 MEM 停一個 cycle)

\(25\%\)

d. 沒有 forwarding:clock \(=140+10=150\) ps;20% 的指令 stall 1 cycle → CPI \(=1.2\)

每道指令 \(1.2\times150=180\) ps

有 forwarding:EX 變 150 ps → clock \(=150+10=160\) ps;剩下的 stall 比例設 \(s\),CPI \(=1+s\)

要快 10%:\(\dfrac{180}{160(1+s)}=1.10\) → \(1+s=\dfrac{180}{176}\) → \(s=\dfrac1{44}\approx0.0227\)

要消除的 stall 比例:\(\dfrac{0.20-0.0227}{0.20}=1-\dfrac{5}{44}=\dfrac{39}{44}\)

\(\approx88.6\%\)

143%

14. [3%] Which of the following statements are correct? (全對才給分)

(A) The RISC instruction set can lead to more efficient processor implementation than the CISC instruction set.

(B) A data access that incurs a TLB miss cannot result in a page fault.

(C) Increasing the cache associativity can reduce conflict misses

(D) In a virtually-indexed and physically-tagged cache, the tag bits are taken from virtual addresses.

(A) RISC 指令格式規則、load/store 架構,decode 與 pipeline 容易做 → T

(B) TLB miss 後去查 page table,page 不在記憶體就是 page fault → F

(C) 同一個 set 放得下更多 block,conflict miss 減少 → T

(D) virtually-indexed physically-tagged:index 用 virtual address,tag 用 physical address → F

(A)、(C)

1515%

II. Operating System [50%]

A bicycle sharing system (BSS) is a service in which bicycles are made available for shared use to individuals who do not own them. The central concept of these systems is to provide free or affordable access to bicycles for short-distance trips in an urban area as an alternative to motorized public transport or private vehicles, thereby reducing traffic congestion, noise, and air pollution. As of May 2011 there were around 136 BSSes in 165 cities around the world, made of an estimated fleet of 237,000 bicycles. U-Bike, Taipei BSS of 11 stations and 500 bikes since 2008, will have 162 stations with 5359 bikes by 2018. The number of parking slots in each station is fixed and might range from 10s to 90s. So far, there are over 10000 accesses each day in average. The Taipei U-Bikers can rent a bike from any station and return to any from an unmanned distributed system. They need to wait if there is no available bike or parking slot. We can get the availability in real time from Internet servers. There are some trucks shipping bikes from stations to stations for better utilization. The rental fee, now, is free for the first 30 minutes and 10 NTD for the following each 30 minutes.

Please answer the following questions:

15. [15%] To support the service on all the stations, the server needs to collect all the data including user's transaction, bike availability, etc. and process users' requests. Alice is the system architect for U-Bike service. To support concurrent requests from all the bike stations, she proposes to use a multiple process model to design the server application. On the server, a background process is started to listen to the requests from all the stations. When a request arrives, a new process is created to process the request.

a. [3%] Please discuss if Alice should use either fork() or vfork() for the background daemon process to create new process so as to provide better concurrence in this application? Please compare the pros and cons of these two functions and select the better one.

b. [3%] Copy-on-write is the technique used to in fork() and vfork() to copy memory regions. Please (1) define technique Copy-on-write and (2) answer which memory segments in a process will be benefit from copy-on-write?

c. [2%] How can Alice know the maximum of concurrent processes being supported in the operating systems?

d. [2%] Suppose each request requires 100ms to process and there is no volunteer yielding during the execution. Moreover, there are 10,000 requests in the ready queue and there are no new requests. The operating system employs Round Robin Scheduling algorithm to schedule all the processes and the time quantum for each process is 50ms. Suppose that there is no other user processes and the CPU time used by kernel processes are negligible. What's the average response time of all the requests?

e. [2%] After a detail investigation, Alice found that the execution time of processing requests evenly distributed in interval [5ms, 200ms] and the exact execution times are not known when requests arrive. Which of the following scheduling algorithm should be selected to achieve maximum throughput? Candidate scheduling algorithms include Round-Robin Scheduling, First-Come-First-Serve, Shortest-Job First, Multi-level Feedback Queue algorithm.

f. [3%] Suppose the system is required to support at least 1,000 transactions per second and each process can create 100 concurrent threads. The context switch overhead for each process is 1ms and that for each thread is 0.1ms. Note that the execution time ranges from 5ms to 200ms. How should Alice revise her design? You should take into account that the execution time of all requests are not equal, the scheduling algorithm used in the operating systems, and the overhead of managing processes and threads.

a. daemon 要一直回去 listen,所以 parent 不能被 child 卡住

vfork:child 借用 parent 的 address space、不複製 page table,建立很快;但 parent 會被 suspend 到 child 呼叫 exec 或 exit,child 改到的資料 parent 看得到(危險)→ parent 在 child 處理請求時無法 accept 新 request,沒有 concurrency

fork:複製 page table、以 copy-on-write 共享 page,建立成本比 vfork 高一些;但 parent 與 child 各有自己的 address space,parent 立刻回去 listen,child 安全地處理自己的 request

用 fork()

b. (1) fork 之後 parent 與 child 先共用同一批 physical page,標成 read-only;任何一方第一次寫入某個 page 時發生 fault,kernel 才複製那一個 page 給寫的人,不寫就不複製

(2) 可寫的 segment 受益:data(initialized data、bss)、heap、stack。text 本來就是 read-only 共享,不需要複製;child 若馬上 exec,這些 page 根本不會被複製

(1) 先共享、第一次寫入才複製該 page (2) data、heap、stack

c. 查 OS 的限制:Linux 用 ulimit -u/getrlimit(RLIMIT_NPROC)/sysconf(_SC_CHILD_MAX) 看每個 user 的 process 上限,再看 /proc/sys/kernel/pid_max、threads-max;實際還受記憶體限制,再用壓力測試確認

查 OS 的 process 上限參數(ulimit -u、RLIMIT_NPROC、pid_max),並用壓力測試確認

d. response time 取 Silberschatz 的定義:request 提交後到第一次得到 CPU 的時間。10,000 個同時在 ready queue,每個 request 需要 100 ms \(\gt50\) ms,每輪都用滿 quantum

第 \(i\) 個 request(\(i=0,\ldots,9999\))第一次執行在 \(50i\) ms

平均 \(=\dfrac{50\,(0+1+\cdots+9999)}{10000}=\dfrac{50\times9999}{2}=249{,}975\) ms

若把 response time 算成做完(turnaround):每個 request 要兩輪,第 \(i\) 個在 \(500{,}000+50(i+1)\) ms 完成,平均 \(500{,}000+50\cdot\tfrac{10001}{2}=750{,}025\) ms

\(249{,}975\) ms \(\approx249.975\) s

e. 最大 throughput = 單位時間內完成最多個 request → 短的先做最好,SJF 最佳;但 burst time 事先不知道(每個 request 是新 process,沒有歷史可估),SJF 做不出來

FCFS:長的擋在前面(convoy effect);RR:quantum 小 context switch 多,quantum 大就退化成 FCFS

MLFQ:新 request 先進高 priority、quantum 短,短的 request(5 ms 附近)在上層就做完;用完 quantum 的往下層降,不必知道 burst time 就近似 SJF

Multi-level Feedback Queue

f. 平均執行時間 \((5+200)/2=102.5\) ms;1000 transactions/s → 同時在處理的 request 約 \(1000\times0.1025\approx103\)(Little's law)

不要一個 request 開一個 process:每個 process 的 context switch 1 ms(加上建立、address space 的記憶體),thread 只要 0.1 ms,且共用 address space

一個 process 最多 100 個 thread → 只靠 1 個 process:\(100/0.1026\approx975\lt1000\),不夠;2 個 process 共 200 個 thread 才夠

設計:預先建好 2 個 worker process(process pool),每個內有 100 個 thread 的 thread pool;daemon 把 request 放進 queue 派給空閒 thread,不為每個 request fork

request 長短差 40 倍:OS 用 MLFQ(或 priority),短 request 不被長 request 擋住;thread 的 context switch 0.1 ms 相對於 5 ms 以上的執行時間可忽略,再依壓力測試調整 thread 數

process pool(至少 2 個 process)+每個 process 100 個 thread 的 thread pool,不再為每個 request 建 process;OS 排程用 MLFQ

1610%

16. [10%] After Alice implemented the system and started to test, she found that the performance is pretty poor. She was asked to identify the causes and resolve the issue.

a. [2%] She found that there are large numbers of context switch among threads and processes and no much real works are done. Please name and define such scenario.

b. [2%] When she checked the logs in the operating system on server, she found that many recently and frequently used memory pages are swapped in and out due to high demanding on U-Bike. Hence, she checked the textbook and decided to take page-fault frequency (PFF) approach to solve the problem. Please describe this technique.

c. [3%] Unfortunately, PFF approach does not help. She also observed that the execution time of processing a request is not long and can be finished within few context switches when the system load is not high. Moreover, when a process/thread is scheduled, it needs to certain page frames for a certain amount time until it completes. What approach should Alice use to avoid thrashing when the system load is high?

d. [3%] Alice also founds that the system is short of memory due to large number of processes to process U-bike requests. How can Alice lower the memory usage if she is not allowed to change the number of processes?

a. thrashing:process 分到的 frame 不夠放它正在用的 page,一直 page fault、換進換出;大部分時間花在 paging 與 context switch,CPU 利用率掉下來,真正執行 request 的工作很少

thrashing(花在換頁、切換的時間多過真正執行的時間)

b. 替每個 process 量 page-fault rate,訂上限與下限:

rate \(\gt\) 上限 → 這個 process frame 不夠,多給它 frame(沒有空 frame 就 suspend 一個 process,把它的 frame 拿來用)

rate \(\lt\) 下限 → frame 太多,收回一些給別人

用 page-fault rate 直接控制每個 process 的 frame 數;上限以上加 frame、下限以下收 frame

c. request 很短,被排到時需要一整組 frame 跑完 → 用 working-set model 做 admission control:只讓 working set 放得進記憶體的 process/thread 執行,其餘的 swap out(medium-term scheduling)

等有 frame 時再 swap in;負載高時降低 multiprogramming degree,而不是讓全部一起搶 frame

working-set model+限制同時執行的 process 數(admission control/swap out 多出來的)

d. process 數不變,改減少每個 process 佔的記憶體:

① 共用 code:shared library、同一份 text 只放一份

② fork 之後用 copy-on-write,沒改到的 page 不複製

③ 共用的資料放 shared memory/memory-mapped file

④ demand paging,不用的 page 不載入;縮小每個 process 的 stack、heap

共用(shared library/shared memory)+copy-on-write+demand paging,不為每個 process 複製一份

1710%

17. [10%] How can you schedule the trucks with minimum cost to reduce the average waiting time of renting a bike [5%], and returning a bike [5%]? Hint: during rush hours or not.

等租車=站上沒車;等還車=站上沒空位(滿站)。卡車目標:讓每個站不空也不滿,且路程最短

租車 [5%]

非尖峰:用歷史資料預測每站每個時段的淨流出,把各站補到目標庫存(預期下個時段的需求量);從「預期會滿」的站拉車去「預期會空」的站;用一趟路線串好幾站(路線最短)

尖峰:先在尖峰前預先配置(通勤熱點:住宅區的站在早上先補滿車);尖峰中依即時庫存與需求率,找最快要空的站,用 \(\tfrac{\text{減少的預期等待}}{\text{路程成本}}\) 排優先順序,高的先去

依預測在尖峰前補車到將空的站,尖峰中先補最快要空且成本效益最高的站

還車 [5%]

同樣的做法反過來看空位:辦公區、捷運站的站在早上尖峰會被還滿,要先把車載走、留出空位;下班尖峰反向

即時監控空位剩幾個,快滿的站排優先,從滿站載車到鄰近有空位的站(同一趟路線順便補空站,載車量不浪費)

尖峰時卡車少跑長距離,只在鄰近站之間調度;非尖峰把庫存拉回平衡,成本低

尖峰前先騰出將滿站的空位、尖峰中就近調度最快要滿的站;路線串連相鄰站,載車量與路程一起考慮

1810%

18. [10%] How to function the system even when the network is down temporarily, where stations cannot communicate with servers but still work with their own parking slots? Hint: stateful or stateless, timing, synchronization, rollback, what information to keep?

stateful:station 要在本機保存自己的狀態,不能每次動作都問 server

要留的資訊:① 每個 parking slot 有沒有車、哪一台車;② 已授權的使用者(悠遊卡/會員的快取名單與黑名單);③ 每一筆租、還的紀錄:unique transaction ID、card ID、bike ID、slot、本機時間 timestamp、遞增的 sequence number

斷線中:依本機狀態直接處理租、還;紀錄寫進非揮發的 log(先寫 log 再開鎖),斷電重開也不遺失;可加限制(單一使用者離線期間可借的台數、黑名單檢查)

timing:租金以時間計(前 30 分鐘免費),所以 timestamp 要準;station 時鐘定期與 server 同步(NTP),離線時用本機 clock,重連後依 timestamp 計費

synchronization:連線恢復後把 log 依 sequence number 補送 server;每筆有 ID,server 重複收到也只算一次(idempotent);server 把各站狀態合併,更新全域的可用車數

rollback:衝突時(例:同一張卡在斷線期間於兩個站各借一台、黑名單卡被借走)server 不覆蓋歷史紀錄,用補償交易處理(補扣款、通知、標記異常);station 與 server 狀態對不上時,以 server 已確認的版本為準,station log 重放補上差異

station 本機維持狀態(slot 與車、使用者名單、帶 timestamp 與 ID 的交易 log)離線照常租還;連線後依序補送,server 以 ID 去重、衝突用補償處理

195%

19. [5%] How do you design a booking or reserving service to improve user satisfaction? Hint: for bike and for parking slot.

預約租車(bike):使用者選站、時段,server 把該站可用車數減 1、已預約加 1,保留一台車,保留期限 TTL(例如 15 分鐘),逾時自動釋放

預約還車(parking slot):目的站空位數減 1、保留一個 slot,一樣有 TTL;保證到站有位子還,不用再繞去別站

可用數與已預約數的更新要 atomic(transaction/lock),避免同一台車或同一個位子被預約給兩個人(oversubscription)

保留期間 station 的鎖定:預約的車只有該使用者的卡能開、預約的位子不讓別人停

防濫用:每人同時預約的筆數有上限;no-show 多次就縮短 TTL 或暫停預約;取消與逾時釋放後立即更新即時資訊

即時顯示各站可借/可還與預約數,並推薦鄰近仍有車(或有位)的站,預約失敗時給替代方案

bike、slot 各自預約、帶 TTL;可用數與預約數 atomic 更新;防 no-show;即時顯示並推薦替代站

109–115 的詳解也是這樣寫的。

國立臺灣大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 367 頁,逐題推導。

購買 · NT$ 850 看台大其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com