# NCTU OSDI Dicussion - Memory Management III
###### tags: `OSDI`
* 在影片中有提到 process 的 data segament 會被 linux mm_struct 記錄為 file-backed 。想確認的是當我們把數值給到 global variable 時,一開始會寫到 memory,最後當 write back 時是會被寫到 disk file 嗎?有點不太能理解 data segament 要使用 file-backed 。
* The first question is why memory mapped file.
* you don’t have to load entire file to memory (reduce memory pressure when load a program)
* shared lib/data (different/same VM mapping to the same file, or different VM mapping to the same page)
* speed up the file access (4K page)
* easy to swap to disk (VM swap)
* The second question is why two types of mmap. filed-backed and anonymous. mapping to file and mapping to page. filed-backed, because you have file to be mapped. why if you don’t have file to be mapped, you need mmap. because you want to map to page and maybe one day you need to map to file (swap)
* mmap has two flags about how to update file-backed mapping when writing. `MAP_SHARED` (write into file) and `MAP_PRIVATE` (copy on write).
* 
* m map主要要解決的問題?
* 使用者開了一個超大的檔案的時候,會怎麼做?
* alloc memory 然後東西搬到memory中。超級慢慢慢。要慢慢搬。
* 記憶體會瞬間少很多。這是個大問題,怎麼解決?
* 只load必要的東西?實作?
* 宣告一個page,把code segment load進來。PC指過去。
* 做完了,繼續往下走,產生page fault,然後?
* page fault handler繼續往下load下一塊。
* 不小心同時解決share library的問題。
* https://manybutfinite.com/post/how-the-kernel-manages-your-memory/
* 如果上面是對的話,那不會造成每次寫,elf object file 的 .data 區段都會改變?還是他不會寫到原來的 elf object file。
* Read only or Read/Write. There is no problem for read only .data. For read/write .data,
* “A file-backed section can also be mapped as copy-on-write. In that case, the view's data is read from the file, but any data written to the view is not written to the file; instead it is discarded after the final view is unmapped and the last handle to the section is closed.”
* https://docs.microsoft.com/zh-tw/windows-hardware/drivers/kernel/file-backed-and-page-file-backed-sections
* 到底是宣告成memory private還是memory share?不一定都是寫回file。
* DMA 也是利用 file-backed 的方式來讓 device 送資料嗎?
* DMA is a hardware mechanism which can transfer data from devices to memory without CPU.
* Memory mapped file is a OS mechanism which can have VM mapped to files.
* DMA 跟 memory map file 好像很像?DMA是硬體的做的事情,硬體資料搬到MEM上。memor map file是OS的東東,是一個把virtual memory 對上memory的方法。
* `malloc()`後都要`free()`以防止memory leak,但如果長時間一直`malloc()`和`free()`是不是有可能因為internal fragmentaion而造成heap有太多沒有滿的frame而被kill?
* heap fragmentation
* 
* `malloc()`誰做的?user?lib?kernel?
* lib做的啦。誰都可以做啦。
* 的確可能會有fragmentation,heap fragmentation。
* fragmentation誰的責任?user?lib?
* 管理的權利是`malloc`,他要負責啦,是他去跟kernel要一大堆空間來分配給user的,所以要他來負責。
* 那到底fragmentation怎麼辦?
* 不要管啊
* `malloc()`就回傳`0`啊。
* 解決方法?也會有新的問題。好煩。老師說要留下一個伏筆。
* How to solve the problem? alloca? What is the problem for alloca?
* 兩個vm_area_struct可以共用一個frame,例如shared library,那是不是要有另外的結構紀載共用的frame被多少process用到,才不會其中一個程式結束就被收回了?
* 找到有struct mmap_info的實作,裡面有個reference紀錄。
* kernel因為有disk driver之類的重要程式,不能被swap進disk,那能不能夠把kernel 分成可以swap跟不能swap的部分?
* https://stackoverflow.com/questions/45112292/allocate-swappable-memory-in-linux-kernel
* ㄚ那你到底這麼做到底是要幹嘛。
* kernel需要這麼大,到底是為甚麼,哪有kernel要這麼慢。
* 在memory mapping 時 , shared mapping 或 private mapping 是在 mmap 時給予 MAP_SHARED 或 MAP_PRIVATE 的 flag 來決定的嗎?
* yes
* 在設計 program 時 , 可以指定哪些 segments (text, data, bss, memory mapping, stack, heap, etc) 要被放在同一個 page 中嗎? (為了Locality)
* Why? For performance?
* Why not? Think about the scenario, sharing .text and .data in the same page. What will happen?
* How we can do that?
* 怎麼可能一個page就可以run?對啦,linux有min page的需求。只是一個說法。
* 在linux底下有沒有可能,一個程式只有4K,全部的東西都放在一個page裡?
* 老師說他也不確定答案。就是個概念的問題。
* inline assembly?能不能在kenel中寫inline assembly。把所有的code跟data放在同一個page底下。
* 老師說在kernel space可以這樣做。但是user space應該是不行。
* 助教說:Your linker can put text, data, bss to one segment.
* 助教說:memory mapping把stack和heap的分配那些是以page為單位在分配。這些東西是lib提供的,但假如你自己來處裡,也可以自己把他們對在一起。
* 在沒有 secondary storage 的情況下 , 是不是每次 process allocate 新的 page 時 , 就要檢查 physical memory 的空間是否小於所有 process 的 virtual memory space 加總?
* (我的想法是在worst case下, 所有的 process 可能都會使用其全部的 virtual memory 空間 , 此時 physical memory 有可能裝不下)
* 
* [solved] dynamic linking 的 library 是怎麼被找到的
* [solved] mmio 的 interrupt 是不會給使用者感受到的嗎?
* [solved] 有人去摸不該摸的記憶體的時候是什麼地方檢查的?
* 在做了 virtual memory 後,每個 process 都會有一個 page table,那這些 table 是在各個 process 的 kernel stack 上嗎?
* (Solved: 是)
* 如果是存在 kernel stack 上,那要怎麼知道 page table 的位置?
* (Solved: page table 的位置也會紀錄在 mm_struct 上)
* 對於被 swap out 的 page,他會把 swap 到硬碟的位置資訊存在哪裡?
* https://www.kernel.org/doc/gorman/html/understand/understand014.html
* swapping的實作細節。
* 請問process擁有1G kernel image是為了讓process進入kernel mode使用的記憶體空間嗎? 像是kernel stack, 或是kernel mode時使用動態記憶體分配的空間。
* yes
* 想請問shared library在各個process中都是被對應到相同的phy memory嗎?
* (已解, shared lib被以memory-mapping file被載入到process, OS會將其對應到相同的phy memory)
* 還是不清楚mm_struct與vm_area_struct的關係
* [ref](https://my.oschina.net/zhuzihasablog/blog/129443) mm_struct->mmap 指向vm_area_struct記錄各個區段的virtual mem, mmap_rb再紀錄RB Tree, 可以把vm_area_struct看成RB Tree的node連結 [ref](https://darktea.github.io/notes/2013/05/27/memory-manager.html)
* 影片中有提到Text的file-backed,在file有buffer cache,怎麼知道接著要執行的code是哪段,如果有判斷式而大幅度跳動導致接著要執行的程式不是依序的話,會產生要去硬碟取該text段的狀況嗎,這樣不是會導致程式執行變慢嗎?
* page fault
* 紅黑樹紀錄vm_end怎麼判斷,假設現在有用是100~150、200~350,那紀錄是150跟350嗎?怎麼知道150~200是空的
* Please study: https://lwn.net/Articles/184495/
* there is still a linked list, so after you find the node, you can look up the previous one or the next one.
* shared library的memory mapping是share還是private是由誰決定的?
* user decide the parameters
* virtual memory怎麼轉到physical memory? (已解)
* kernel space跟 user space大小怎麼分配的? (已解)
* program的記憶體是怎麼分配的?(已解)
* 若kernel memory超過1G(不夠用)的時候該怎麼辦呢?
* Unmapped some mapped highmem, and map new page on highmem
* 影片中提到,kernel thread不需要mm structure因為都是一對一個關係,但是kernel space應該也是會切成好幾段分給不同的kernel thread吧,那這些分配的資料會記在哪裡?
* all kernel memory can be easily mapped to physical memory.
* https://docs.huihoo.com/doxygen/linux/kernel/3.7/structvmap__area.html
* physical memory 和logical memory一對一個關係(kmalloc)。offset的對應。
* 在kernel中也可用vamlloc就會用page table對應。
* for vmalloc, vmap in kernel space. May not be a one-one mapping.
* but for most oif the case, it's a one-one mapping!
* 課程不斷提到會分User space 3G,kernel space 1G。為甚麼會有這樣的規劃?如果user space超過了3G又會發生甚麼事?如果再加上HD的swapping space,理論上不就可以一直往上加嗎?
* why swaping space?
* why virtual memory?
* why 3G/1G partition?
* 題目代表你有誤解。
* swapping space 和 virtual memory要解決不同的問題。swapping space就是實體空間不夠了,要搬過去。3G 1G是virtual memory的問題,所以這兩個東西不應該混再一起談。
* virtual memory要不要切partition,是你的事情。要全部4G切給user space,也可以,這樣要做system call都要做memory space switch,這樣超級無敵爆炸慢。
* 在沒有swapping space的情況下,virtual memory有沒有解決memory不夠的問題?沒有啦!!
* 要做到swapping space(看到的位置,實際放在HD上)是否需要做到virtual memory?要RRRR。
* 影片中不斷提到,如果要了一塊空間,只會在VMA上有紀錄,要真正使用該空間而引發page fault才會去真的對上physical空間。但是現在memory越做越大,是不是能夠要了就直接對上,這樣執行效率也能較好?
* page fault probability: p
* page fault extra latency: l_pagefault
* load latency for 1MB: l_mem
* program size: S
* Method 1: load entire program to memory
* Method 2: demand paging
* Please calculate user-experinced delay under method 1 and method 2.
* 全部搬進來,一開始執行的時間就超慢。可以算一下
* 以目前來看,也是有人這樣做,但是by default,不會這樣做。
* mmap has a flag (MAP_POPULATE) that can preload data into a page from a file.
* (solved)1. invalid memory access 是拿到kernel正在使用的那段才會發生,還是用到留給kernel的整個1GB就會發生?
* (solved)2. vm_area_struct串連方式是如何?(投影片看起來是linked list)如果太長會不會造成存取變慢?
* (solved)3. kernel thread的stack, heap就自己放在kernel空間內嗎?
* 原來 stack 用不夠會再去拉新的空間,但是可以拉到多大呢?[已解]
* 解答:可以用指令 prlimit 查看目前系統設定的最大 stack size 預設是 8 MB,而一般程式在 linker 做鏈結的時候可以設定 stack segment 要多大的空間,預設會是 2 MB。因此在程式一開始只有 2 MB 的狀態時,若有更大的需求不會直接導致 segmentation fault 而是先有 page fault,因為在 kernel 內的 vma 記錄中行程的可擁有大小會是 8 MB,直到需求超過 8 MB 時才會導致 segmentation fault。
* Ref:
* https://unix.stackexchange.com/questions/521960/how-does-the-elf-loader-determine-the-initial-stack-size
* https://linux.die.net/man/1/ld
* http://man7.org/linux/man-pages/man2/getrlimit.2.html
* 考慮 thread 的情況下,不同 thread 應該是使用不同的 task struct,但 mm struct 裡面的 vma 應該會指到一些相同的地方。那如果 vma 因為其中一個 thread 執行而有所更動的話,另外一個 thread 的 vma 內容是不是也要跟著修改?那我們需要去掃所有的 task struct 去檢查所有 task 的 vma 內容嗎?
* yeah, that's what I mentioned. My question is that should we check each vma address of mm struct belongs to every task struct on vma modification?
* threads in the same process point to the same mm_struct pointer
* mm struct 也是一個pointer,你改一個,全部也都會一起改。
* 個別thread會有自己的task struct裡面的mm structur會指到同一個。
* Each thread stack is placed into the same VM addressing space but they are different memory addresses.
* https://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux
* how to test:
```bash
$ cat /proc/{pid}/maps
# if pid = 3 and pid = 4 have thread relationship.
$ diff /proc/3/maps /proc/4/maps
# pid = 3
# pid = 4
```
* 他還是有一個offset mapping不一樣的關係,但是他的內容會長一樣。
```bash
sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"
```
* No need to disable randomize_va_space, I made wrong experiments.
* 講到 mmap 的時候提到,user 準備 user space 的記憶體,然後 trap 到 kernel 去,kernel 需要 allocate 一段記憶體然後讓硬碟的 dma 寫到 kernel 的位置記憶體,kernel 再 copy 回 user 的位置,那為什麼 dma 不能直接寫到 user space 的記憶體位置?
* why not?
* I mean why does the kernel need to allocate a space and copy again, security issue?
* open(O_DIRECT)
* mmap 的概念是將 virtual memory 直接 map 到 file 的位置,所以做完這個 syscall 之後,那些位置是不是其實還沒有 file 的資料,實際上是等到 user 存取那些位置時,產生 page fault,這時 exception 會直接把資料讀到 user space 記憶體上?那這之間應該是沒有 syscall 的吧?
* yes.
* Stack overflow 發生的時候是一蓋到 heap 的部分,VMA 就會發出錯誤嗎 還是要到 code segment 的時候才會因為 code 不可寫而有錯誤。
* as soon as you grow stack up, VMA created. If VMA creates fails, stack cannot grow anymore.
* Stack overflow 應該是蓋到不該蓋的記憶體 系統有個機制較 canary 去避免這種狀況
* 想要做`add sp, sp 4`,這件事是VMA在管,所以VMA尖叫,放不過去了。
* 但實際上,stack和heap中間是有一塊buffer的,是有一個page,但不是真的有那一塊空間。他就是一個mapping,不會被分配到。去碰到了,他就會引發page fault,然後他就會繼續尖叫stack overflow。
* 沒有硬體支援虛擬化的機器要跑 VM 是不會經歷 guest 的 OS 再經過 host 的 OS 的兩層轉址。
* [已解] Ref: https://en.wikipedia.org/wiki/X86_virtualization
* 投影片 OSDI-008-4-MemoryManagement-Part3 .pdf P. 19 提到如果 page cache reclaim 拿到的記憶體不夠多會再去縮減 kernel 的記憶體,例如 special caches 跟 kernel vm allocator。這一段我看不太懂是甚麼意思
* 以影片中的例子為例,為什麼會想要Mappping User process到3GB的空間,而不是讓他Mapping到整個4GB,而Kernel也是4GB ?
* [已解決] https://www.quora.com/Why-do-32-bit-Linux-kernels-only-recognize-3GB-of-RAM
* ARMv8-A的Addresible region採48 bit,如果對應到virtual address space後,他中間會有Memory hole(Lab5),這樣有什麼好處?跟用意?
* [已解決] https://zhuanlan.zhihu.com/p/66794639 這篇文章的最下面有寫到
* mmap 會將檔案映射到記憶體上,他在建構vm_area_struct相關流程是如何做的?
* [已解決] https://www.cnblogs.com/huxiao-tee/p/4660352.html 有解釋mmap處理的流程
* 我們希望不同 processes 共用的程式碼,只存在一份資料在 physical memory。但系統要如何能知到哪些是共用的?
* User process 的 memory leak 可以透過 library injection,或是 virtual machine 來監控。
* [mmleak_detect](https://stackoverflow.com/questions/28446850/memory-leak-detectors-working-principle), [mmleak_detect](https://hackmd.io/@sysprog/c-dynamic-linkage?type=view)
* 那 kernel 開發怎麼偵測 memory leak?只能依靠其他的virtual machine嗎?還是會寫出bug的 programer 沒有資格開發 OS
* https://hackmd.io/@sysprog/c-dynamic-linkage?type=view
* https://www.kernel.org/doc/html/latest/dev-tools/kmemleak.html
* 教授有說程式可以用一個 page 就能執行,假如不在 page 就從硬碟抓,但假如現在有個程式要去抓資料,而資料不在當前 page,就會把 page 換成資料的內容,但這樣指令就不見了而產生 pagefault 竟而產生無盡循環?
* windows 有mmap的機制嗎?(已解)
* 有對應的方法,但是使用上比mmap複雜
* https://docs.microsoft.com/en-us/windows/win32/memory/file-mapping
* 如果我fork一個process,就需要把VMA所有visual address對應到的physical address複製一份,並轉成指到新的physical address這樣嗎?
* 如過我要寫一個跨平台的程式,user space就只能使用2gb,不然拿去windows編譯就會掛掉了?(已解)
* windows提供了一個將user space變成3gb的方法
* https://docs.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/virtual-address-spaces
* 如果 process 的 region (Ex. heap, BSS...) 超過一個 page 的大小,那個幾個 pages 需要同時被搬離 memory?或同時被搬回 memory 嗎?還是就誰 page fault 再搬就好?(已解)
* 為什麼使用 VMA 可以減少 internal fragmentation 的產生?是因為 VMA 對應到的結構是 page 嗎?
* VM is for reducing external fragementation.
* 在沒有 memory I/O 的情況下,一個 I/O operation 去 Disk 搬資料,要先複製一份到 kernel space,再從 kernel space 複製到 user space,搬完之後會把 kernel space 用到的那塊 free 掉嗎?
* yes. you can check how Linux implements sys_read()
* 為什麼使用 read 讀檔的話,kernel 需要自己開一個 buf 來放 DMA 的資料,而不要直接讓 DMA 寫入 user space 存入的 buffer 對應的 frame 呢?
* 這題已解。我的理解是檔案內容需要被寫入 page cache,所以不能直接拿 user space 對應的 page frame 來用。
* 
* 
* 
* 如果採用 private mapping,使用者對該 page 的寫入是否就不會被寫回 back-store file?
* 
* 
* 假設我 `malloc` 一個 array `i`,我去 access `i[x]` (`x`是任意數),只要 `x` 都還在這個合法的 page 裡面,就算我沒有 `malloc` `x` 這麼大的空間,都算是合法的存取嗎?
* yes, but not a good behavior
* 承上,假設這樣算合法的存取,這樣存 `i[x]` 的值的地方可能是存別的變數的地方,所以要避免髒掉是 user 的責任囉?
* yes
* 上完課後還是不太確定 vm_area_struct 的作用,主要是用來記錄 process 的 data、bss、stack 等的區段目前所能用的 logical address space 的大小嗎?
* yes, keep the segment information
* memory mapping region 的功能,為什麼 dynamic linking library 要放在這 而不是放在 text region?
* 以後面老師的講解來說,我的理解是因為有多個程式會用到同一個 library ,所以這個 library 只要在 memory keep 一份就好,每個 process 用 memory map 的方式把該 library map 到 virtual memory 裡。可是 dynamic linking library 不是希望說用到時才 load 進 memory,
* dynamic linking library 是希望說用到時才 load 進 memory,所以是該 library 會先被 load 到 os 的 kernel space 內,然後再用 memory map 的方式 map 到該 process 的 user space 內?然後下個也要用到該 library 的 process 知道已經被 load 到 kernel 了,所以直接 map 就好?
* yes
* data region 和 text region 的 struct file 是指原始的執行檔裡面會有一塊區域是存 memory struct 的資訊嗎?
* elf keep part of the segments information
* 為甚麼virtual address的設計,windows default使用的是和linux不同的2G kernel : 2G user呢?雖然老師有提到可能和應用上有很大的關係,那麼這兩個作業系統是基於甚麼應用上的差異導致這樣的設計呢?
* (有看到說跟windows可能targeted machines是64M memory所以1:1比較好的說法,但沒找到比較可靠的證據)
* page fault的機制雖然可以避免allocate不必要的記憶體空間,但處理太多的page fault有沒有可能造成很大的overhead呢?
* 
* https://scoutapm.com/blog/understanding-page-faults-and-memory-swap-in-outs-when-should-you-worry
* 不同OS、硬體的時間panlty
* minor page fault,logical和physical沒有對上,要去對上的一個時間。
* major page fault,被丟到HD上要swap回來的時間。 *
* 呈上題,以linux來說,有沒有可能因為可以預期這個問題,提供system call可以讓user直接要一塊map到physical memory的空間,而不是只是合法的定址?
* [solved] Linux 支援的 binary 格式? [追 binary memory mapping 的 code 時看到 Linux 提供讓使用者註冊的方式 可以把 非預設的執行黨格式 ex: win exe 用指定的 function 或程式跑起來 藉此支援各種不同的執行檔]
* 在linux當中,用gdb trace process的時候常常都會看到vmmap有不同的擺放方式,請問也是VMA負責的嗎,那他的order主要是根據什麼來配置?
* page fault 算是種 exception,那麼在preemption kernel 裡面是否會有 preemption point,還是其實沒必要?
* ???
* 在 linux 中 stdin/stdout 也是 shared mapping file的概念嗎,但是兩個 process 卻可以同時寫入相同的 stdout,卻不會互相影響,那麼這是因為在寫入的當下就產生copy,還是說本來兩個 process 對到的 stdout 就已經都是 copy 了?
* stdin/stdout are files and not mapped, they’re read/write by read/write system call
* 問個基本問題,為何memory有時候要align有時候不用呢?
* Usually hardware dependent.
* 如果程式malloc一塊記憶體,又free掉,之後再access那塊記憶體會發生什麼事?
* Usually okay because libc won’t unmapped the region.
* But it’s not recommended.
* C當中的struct在memory中如何擺放?
* Compiler decides the layout. Please refer to C spec.
* 影片中, Memory 像是 BSS, Memory Mapping, Stack 這幾種都是要使用才分配?
* 理解上會是 Virtual Page Table 有這個 record, 但還不會mapping到physical memory, 而真的access時 才發page fault 去allocate physical memory填回Page Table.
* Page Fault Handler : 情境上 如果是不屬於這個Process的 Memory Access, 但又同在User Mode, 假定4G Addressing, 影片中是說會access到不存在的空間. 但有沒有可能剛好存取到一個當前Process有allocate的記憶體 所以不會 illegal access (影片 54:13 上下)
* MMIO的部分 是利用 Physical Page Frame 跟 inode block 連結, 而 struct file又可以跟 page Frame 有關連 所以可以直接Mapping 的意思嗎?
* MMIO is CPU use a memory address to access peripherals or you mean memory mapped file?
* 如果有在page table的page fault(合法的)卻沒在硬碟找到怎麼辦? (應該是直接掛掉)
* linux會定期檢查不用的就swap掉避免physical memory滿了不夠用,那還會有Thrashing的問題嗎? (應該還是會)
* Yes, garbage collection always has performance overhead
* linux裡面有Shared Memory讓兩個process互相溝通,這種memory也只是physical memory相同但virtual memory不相同嗎?
* yes, but virtual memory may still be the same
* kernel 中如 Filesystem, driver 不能被 swap out 但如 microkernel 內本身不會有 filesystem 而是放在 userspace,這樣要如何保證不會被 swap out
* If you want the swap mechanism in microkernel, you need a swap subsystem or filesystem subsystem should support swap( in user mode). And the subsystem registers the page fault handler for certain regions in the address space to the kernel. And the kernel will inform the subsystem on page fault.(It’s just one possible solution came to my mind, you can have your own design)
* vm_area struct可以保存多段的記憶體區塊減少完整記錄memory address的浪費,這樣子在使用sharelibrary的時候會是直接共用對應的vm_area structure嗎?(ex glibc)
* Won’t share vm_area_struct between process, and it’s not related to glibc
* pthread是怎麼做 ?
* Ans: 產生出來的 task_struct 共用別人的 mm_struct
* kernel thread need mm_struct ? (solved)
* GPU 的 address space 是否獨立?
* GPU access usually by memory mapped IO
* 
* 64 bits system 的 virtual memory address 還是 4G 嗎?
* (Solved, it is 2^48)
* fork() 會有新的 address space 嗎?pthread 呢?
* (Solved, fork 有; pthread 沒有)
* MMU 是 share 的, 還是每個 core 有一個?
* (Solved, 每個 core 都有)
* [sloved]Stack 成長的時候會超越原本實際有 mapping 的區域時觸發 page fault,然後 allocate 新的 page(dynamic stack 時),想請問這樣是否代表 stack 的 vma_struct 的 end 應該是綁死的?
* Stack 的 start end 一開始就是訂好的。heap 也是,所以理論上沒有 libc 的封裝操作,heap 在區間內的的表現應該會跟 stack 一樣。除非 user allocate 大量的記憶體,可能會導致 libc 需要額外讓 kernel 新增 vma
* 關於 vma 的 file mapping 上課時一直提到"buffer"跟"cache",這個 buffer 單純的是指 kernel 在從硬碟讀取資料並且放到 user 指定的 memory 上的時候中間暫時使用的空間,還是指他有一塊獨立的空間去應付 page fault 發生的時候才把剩下的資料補上以防止硬碟等待或浪費空間? 另外像是 shared libs 應該也是有 backed file 的吧(在 vma_struct 底下的 i_node 實際有指向 libs files)
* [sloved]為甚麼需要使用 RBT 去處理 VMAs? VMAs 整體的數量會龐大到需要使用這樣的管理機制嗎? 怎樣的情況會頻繁的插入/拔出/搜尋 VMAs ?

以這張圖來說,一個 task 擁有的 VMAs 應該是十分有限的,使用 RBT 能從中獲得很大的收益嗎? 還是說 kernel 會對所有 task 的所有 VMAs 做一些操作?
* 大型的資料處理 server 可能會頻繁地把資料 map 進出 logical memory ,這時 RBT 結構可以快速的在 logical memory 中找到可以使用的連續空間