]>
Commit | Line | Data |
---|---|---|
8d83d826 MR |
1 | ===================== |
2 | Overcommit Accounting | |
3 | ===================== | |
4 | ||
1da177e4 LT |
5 | The Linux kernel supports the following overcommit handling modes |
6 | ||
8d83d826 MR |
7 | 0 |
8 | Heuristic overcommit handling. Obvious overcommits of address | |
9 | space are refused. Used for a typical system. It ensures a | |
10 | seriously wild allocation fails while allowing overcommit to | |
11 | reduce swap usage. root is allowed to allocate slightly more | |
12 | memory in this mode. This is the default. | |
1da177e4 | 13 | |
8d83d826 MR |
14 | 1 |
15 | Always overcommit. Appropriate for some scientific | |
16 | applications. Classic example is code using sparse arrays and | |
17 | just relying on the virtual memory consisting almost entirely | |
18 | of zero pages. | |
1da177e4 | 19 | |
8d83d826 MR |
20 | 2 |
21 | Don't overcommit. The total address space commit for the | |
22 | system is not permitted to exceed swap + a configurable amount | |
23 | (default is 50%) of physical RAM. Depending on the amount you | |
24 | use, in most situations this means a process will not be | |
25 | killed while accessing pages but will receive errors on memory | |
26 | allocation as appropriate. | |
1da177e4 | 27 | |
8d83d826 MR |
28 | Useful for applications that want to guarantee their memory |
29 | allocations will be available in the future without having to | |
30 | initialize every page. | |
c9b1d098 | 31 | |
8d83d826 | 32 | The overcommit policy is set via the sysctl ``vm.overcommit_memory``. |
1da177e4 | 33 | |
8d83d826 | 34 | The overcommit amount can be set via ``vm.overcommit_ratio`` (percentage) |
dc10ec98 AH |
35 | or ``vm.overcommit_kbytes`` (absolute value). These only have an effect |
36 | when ``vm.overcommit_memory`` is set to 2. | |
1da177e4 LT |
37 | |
38 | The current overcommit limit and amount committed are viewable in | |
8d83d826 | 39 | ``/proc/meminfo`` as CommitLimit and Committed_AS respectively. |
1da177e4 LT |
40 | |
41 | Gotchas | |
8d83d826 | 42 | ======= |
1da177e4 LT |
43 | |
44 | The C language stack growth does an implicit mremap. If you want absolute | |
8d83d826 | 45 | guarantees and run close to the edge you MUST mmap your stack for the |
1da177e4 LT |
46 | largest size you think you will need. For typical stack usage this does |
47 | not matter much but it's a corner case if you really really care | |
48 | ||
8d83d826 | 49 | In mode 2 the MAP_NORESERVE flag is ignored. |
1da177e4 LT |
50 | |
51 | ||
52 | How It Works | |
8d83d826 | 53 | ============ |
1da177e4 LT |
54 | |
55 | The overcommit is based on the following rules | |
56 | ||
57 | For a file backed map | |
8d83d826 MR |
58 | | SHARED or READ-only - 0 cost (the file is the map not swap) |
59 | | PRIVATE WRITABLE - size of mapping per instance | |
1da177e4 | 60 | |
8d83d826 MR |
61 | For an anonymous or ``/dev/zero`` map |
62 | | SHARED - size of mapping | |
63 | | PRIVATE READ-only - 0 cost (but of little use) | |
64 | | PRIVATE WRITABLE - size of mapping per instance | |
1da177e4 LT |
65 | |
66 | Additional accounting | |
8d83d826 MR |
67 | | Pages made writable copies by mmap |
68 | | shmfs memory drawn from the same pool | |
1da177e4 LT |
69 | |
70 | Status | |
8d83d826 MR |
71 | ====== |
72 | ||
73 | * We account mmap memory mappings | |
74 | * We account mprotect changes in commit | |
75 | * We account mremap changes in size | |
76 | * We account brk | |
77 | * We account munmap | |
78 | * We report the commit status in /proc | |
79 | * Account and check on fork | |
80 | * Review stack handling/building on exec | |
81 | * SHMfs accounting | |
82 | * Implement actual limit enforcement | |
1da177e4 LT |
83 | |
84 | To Do | |
8d83d826 MR |
85 | ===== |
86 | * Account ptrace pages (this is hard) |