Back to home page

OSCL-LXR

 
 

    


0001 =====================
0002 Overcommit Accounting
0003 =====================
0004 
0005 The Linux kernel supports the following overcommit handling modes
0006 
0007 0
0008         Heuristic overcommit handling. Obvious overcommits of address
0009         space are refused. Used for a typical system. It ensures a
0010         seriously wild allocation fails while allowing overcommit to
0011         reduce swap usage.  root is allowed to allocate slightly more
0012         memory in this mode. This is the default.
0013 
0014 1
0015         Always overcommit. Appropriate for some scientific
0016         applications. Classic example is code using sparse arrays and
0017         just relying on the virtual memory consisting almost entirely
0018         of zero pages.
0019 
0020 2
0021         Don't overcommit. The total address space commit for the
0022         system is not permitted to exceed swap + a configurable amount
0023         (default is 50%) of physical RAM.  Depending on the amount you
0024         use, in most situations this means a process will not be
0025         killed while accessing pages but will receive errors on memory
0026         allocation as appropriate.
0027 
0028         Useful for applications that want to guarantee their memory
0029         allocations will be available in the future without having to
0030         initialize every page.
0031 
0032 The overcommit policy is set via the sysctl ``vm.overcommit_memory``.
0033 
0034 The overcommit amount can be set via ``vm.overcommit_ratio`` (percentage)
0035 or ``vm.overcommit_kbytes`` (absolute value). These only have an effect
0036 when ``vm.overcommit_memory`` is set to 2.
0037 
0038 The current overcommit limit and amount committed are viewable in
0039 ``/proc/meminfo`` as CommitLimit and Committed_AS respectively.
0040 
0041 Gotchas
0042 =======
0043 
0044 The C language stack growth does an implicit mremap. If you want absolute
0045 guarantees and run close to the edge you MUST mmap your stack for the
0046 largest size you think you will need. For typical stack usage this does
0047 not matter much but it's a corner case if you really really care
0048 
0049 In mode 2 the MAP_NORESERVE flag is ignored.
0050 
0051 
0052 How It Works
0053 ============
0054 
0055 The overcommit is based on the following rules
0056 
0057 For a file backed map
0058         | SHARED or READ-only   -       0 cost (the file is the map not swap)
0059         | PRIVATE WRITABLE      -       size of mapping per instance
0060 
0061 For an anonymous or ``/dev/zero`` map
0062         | SHARED                        -       size of mapping
0063         | PRIVATE READ-only     -       0 cost (but of little use)
0064         | PRIVATE WRITABLE      -       size of mapping per instance
0065 
0066 Additional accounting
0067         | Pages made writable copies by mmap
0068         | shmfs memory drawn from the same pool
0069 
0070 Status
0071 ======
0072 
0073 *       We account mmap memory mappings
0074 *       We account mprotect changes in commit
0075 *       We account mremap changes in size
0076 *       We account brk
0077 *       We account munmap
0078 *       We report the commit status in /proc
0079 *       Account and check on fork
0080 *       Review stack handling/building on exec
0081 *       SHMfs accounting
0082 *       Implement actual limit enforcement
0083 
0084 To Do
0085 =====
0086 *       Account ptrace pages (this is hard)