# Operation system ## Virtual memory ### Background #### 好處: 1. 讓process可以使用比實體記憶體大的空間(動態分配) 2. 加速(Pre-read,一次load 4Kbit) 3. 增加電腦資源使用率(讓沒被使用的資源被使用,trim) 4. 簡化Program負擔(不用管實際怎麼寫,) #### Implement 1. Demand paging 2. Demand Segmentation #### Concept 1. SWAP 不常用的DATA從到Mamory 到DISK 2. 所以SWAP的選擇很重要,選錯會一直搬 ##### Demand paging 1. Less I/O : 一次LOAD 4K 2. Less memmory needed :要使用才搬 graph load code from memory --> 如果memory 上的flag 為Invalid --> interrupt (SW trap)去Disk 找code load 到Memory load --> Program counter 回到上一步(還找不到Code時的位置) --> 此時已經找到Code,可以直接執行指令 --> falg = valid #### Copy-on-Write