linux中有一個overcomit的配置,這個配置關係到進程在過多申請memory資源的時候,系統的表現(啓發式容許,不檢查,or 阻止)linux
/proc/sys/vm/overcommit_memory This file contains the kernel virtual memory accounting mode. Values are: 0: heuristic overcommit (this is the default) 1: always overcommit, never check 2: always check, never overcommit In mode 0, calls of mmap(2) with MAP_NORESERVE are not checked, and the default check is very weak, leading to the risk of getting a process "OOM-killed". In mode 2 (available since Linux 2.6), the total virtual address space that can be allocated (CommitLimit in /proc/mem‐ info) is calculated as CommitLimit = (total_RAM - total_huge_TLB) * overcommit_ratio / 100 + total_swap
詳細的理解能夠參見這個博客: http://linuxperf.com/?p=102redis
在實際項目中,若是機器是跑redis的通常都會把overcomit開成1 (https://redis.io/topics/faq#background-saving-fails-with-a-fork-error-under-linux-even-if-i-have-a-lot-of-free-ram)this
Short answer: echo 1 > /proc/sys/vm/overcommit_memory :)
跑ffmepg的時候,也會設置成1。避免ffmepg一些進程在申請內存的時候發生內部錯誤。spa
根本緣由是進程申請了這麼多memory,實際不必定佔用這麼多memory,並且物理內存頁的分配發生在使用的瞬間,而不是在申請的瞬間。因此咱們能夠容許系統overcommit,知足進程申請,能夠經過cgroup memory來限制用戶使用內存的上限。code