[server] vm.overcommit_memory는 어떻게 작동합니까?

기본 설정을 사용하는 경우 :

vm.overcommit_memory = 0
vm.overcommit_ratio = 50

/proc/meminfo파일 에서 다음 값을 읽을 수 있습니다 .

CommitLimit:     2609604 kB
Committed_AS:    1579976 kB

내가 변경할 때 vm.overcommit_memory부터 02, 나는 특히 아마록, 나는 변경하기 전에 시작할 수있는 응용 프로그램의 동일한 세트를 시작할 수 없습니다입니다. 로 변경 vm.overcommit_ratio해야 300했기 때문에 한도를 늘릴 수있었습니다. 이제 amarok을 시작할 때 /proc/meminfo다음을 보여줍니다.

CommitLimit:     5171884 kB
Committed_AS:    3929668 kB

이 시스템에는 1GiB의 RAM 만 있지만 amarok는 vm.overcommit_memory0으로 설정 되어도 문제없이 작동 합니다. 그러나로 설정하면 2amarok는 2GiB 이상의 메모리를 할당해야합니다. 정상적인 행동입니까? 그렇다면 왜 누군가가 변경 전후에 같은 방식으로 파이어 폭스 (아마 로크보다 4-6 배 더 많은 메모리를 소비)가 작동하는지 설명 할 수 있습니까?



답변

설명서는 man 5 proc( 또는 kernel.org ) 에서 찾을 수 있습니다 .

/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

간단한 대답은 overcommit을 1로 설정하면 프로그램 malloc()이 메모리 청크를 할당하는 것과 같은 것을 호출 할 때 man 3 malloc시스템이 모든 메모리를 가지고 있지 않다는 것을 알고 있더라도 항상 성공할 수 있도록 단계를 설정 한다는 것입니다. 물었다.

이해해야 할 기본 개념은 가상 메모리 라는 개념입니다 . 프로그램은 실제 물리적 메모리에 매핑되거나 매핑되지 않을 수있는 가상 주소 공간을 봅니다. 오버 커밋 검사를 비활성화하면 OS에 가상 공간을 백업하기에 충분한 물리적 메모리가 항상 있다고 가정합니다.

이것이 왜 중요한지 강조하기 위해 Redis 지침 을 왜 vm.overcommit_memory1로 설정해야하는지 살펴보십시오 .


답변