# 2024q1 Homework1 (lab0) contributed by < `vacantron` > ### Reviewed by `Vincent550102` ### Reviewed by `w96086123` ### Reviewed by `vax-r` * 未完成任何指定事項 * github repository 尚未提交任何 commit ### Reviewed by `vestata` - github repository 尚未發現任何 commit - 是否可以設計實驗來觀察 overcommit 情況? ## Overcommit 在 Linux 核心內建一項名為 overcommit 的記憶體管理策略,可以使用 `cat /proc/sys/vm/overcommit_memory` 命令來查看核心目前的配置狀態,預設為 0 引用 [Linux 官方文件](https://www.kernel.org/doc/Documentation/vm/overcommit-accounting): * 0 - Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It ensures a seriously wild allocation fails while allowing overcommit to reduce swap usage. root is allowed to allocate slightly more memory in this mode. This is the default. * 1 - Always overcommit. Appropriate for some scientific applications. Classic example is code using sparse arrays and just relying on the virtual memory consisting almost entirely of zero pages. * 2 - Don't overcommit. The total address space commit for the system is not permitted to exceed swap + a configurable amount (default is 50%) of physical RAM. Depending on the amount you use, in most situations this means a process will not be killed while accessing pages but will receive errors on memory allocation as appropriate. Useful for applications that want to guarantee their memory allocations will be available in the future without having to initialize every page. 在預設狀態下呼叫 `malloc()` 函式時,Linux 核心會回傳一個記憶體地址,若要求的空間超過 Linux 核心的記憶體定址空間或是在配置時發生其他的錯誤則會回傳 NULL。而在回傳地址的當下 Linux 核心可能還未建立對應的記憶體映射,直到初次使用該空間時才會引發 page fault 並註冊 page table :::warning > [name=I-HSIN Cheng] > TODO : 完整作業一指定事項,並設計實驗觀察 malloc 是否發生 overcommit 。 ::: ## OOM killer (out-of-memory killer) ## WIP