overcommit-accounting 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. The Linux kernel supports the following overcommit handling modes
  2. 0 - Heuristic overcommit handling. Obvious overcommits of
  3. address space are refused. Used for a typical system. It
  4. ensures a seriously wild allocation fails while allowing
  5. overcommit to reduce swap usage. root is allowed to
  6. allocate slighly more memory in this mode. This is the
  7. default.
  8. 1 - Always overcommit. Appropriate for some scientific
  9. applications.
  10. 2 - Don't overcommit. The total address space commit
  11. for the system is not permitted to exceed swap + a
  12. configurable percentage (default is 50) of physical RAM.
  13. Depending on the percentage you use, in most situations
  14. this means a process will not be killed while accessing
  15. pages but will receive errors on memory allocation as
  16. appropriate.
  17. The overcommit policy is set via the sysctl `vm.overcommit_memory'.
  18. The overcommit percentage is set via `vm.overcommit_ratio'.
  19. The current overcommit limit and amount committed are viewable in
  20. /proc/meminfo as CommitLimit and Committed_AS respectively.
  21. Gotchas
  22. -------
  23. The C language stack growth does an implicit mremap. If you want absolute
  24. guarantees and run close to the edge you MUST mmap your stack for the
  25. largest size you think you will need. For typical stack usage this does
  26. not matter much but it's a corner case if you really really care
  27. In mode 2 the MAP_NORESERVE flag is ignored.
  28. How It Works
  29. ------------
  30. The overcommit is based on the following rules
  31. For a file backed map
  32. SHARED or READ-only - 0 cost (the file is the map not swap)
  33. PRIVATE WRITABLE - size of mapping per instance
  34. For an anonymous or /dev/zero map
  35. SHARED - size of mapping
  36. PRIVATE READ-only - 0 cost (but of little use)
  37. PRIVATE WRITABLE - size of mapping per instance
  38. Additional accounting
  39. Pages made writable copies by mmap
  40. shmfs memory drawn from the same pool
  41. Status
  42. ------
  43. o We account mmap memory mappings
  44. o We account mprotect changes in commit
  45. o We account mremap changes in size
  46. o We account brk
  47. o We account munmap
  48. o We report the commit status in /proc
  49. o Account and check on fork
  50. o Review stack handling/building on exec
  51. o SHMfs accounting
  52. o Implement actual limit enforcement
  53. To Do
  54. -----
  55. o Account ptrace pages (this is hard)