* The pagedaemon threads randlomly select one to perform the * OOM. Trying to kill processes before all pagedaemons * failed to reach free target is premature. */
| 1792 | * failed to reach free target is premature. |
| 1793 | */ |
| 1794 | static void |
| 1795 | vm_pageout_mightbe_oom(struct vm_domain *vmd, int page_shortage, |
| 1796 | int starting_page_shortage) |
| 1797 | { |
| 1798 | int old_vote; |
| 1799 | |
| 1800 | if (starting_page_shortage <= 0 || starting_page_shortage != |
| 1801 | page_shortage) |
| 1802 | vmd->vmd_oom_seq = 0; |
| 1803 | else |
| 1804 | vmd->vmd_oom_seq++; |
| 1805 | if (vmd->vmd_oom_seq < vm_pageout_oom_seq) { |
| 1806 | if (vmd->vmd_oom) { |
| 1807 | vmd->vmd_oom = FALSE; |
| 1808 | atomic_subtract_int(&vm_pageout_oom_vote, 1); |
| 1809 | } |
| 1810 | return; |
| 1811 | } |
| 1812 | |
| 1813 | /* |
| 1814 | * Do not follow the call sequence until OOM condition is |
| 1815 | * cleared. |
| 1816 | */ |
| 1817 | vmd->vmd_oom_seq = 0; |
| 1818 | |
| 1819 | if (vmd->vmd_oom) |
| 1820 | return; |
| 1821 | |
| 1822 | vmd->vmd_oom = TRUE; |
| 1823 | old_vote = atomic_fetchadd_int(&vm_pageout_oom_vote, 1); |
| 1824 | if (old_vote != vm_ndomains - 1) |
| 1825 | return; |
| 1826 | |
| 1827 | /* |
| 1828 | * The current pagedaemon thread is the last in the quorum to |
| 1829 | * start OOM. Initiate the selection and signaling of the |
| 1830 | * victim. |
| 1831 | */ |
| 1832 | vm_pageout_oom(VM_OOM_MEM); |
| 1833 | |
| 1834 | /* |
| 1835 | * After one round of OOM terror, recall our vote. On the |
| 1836 | * next pass, current pagedaemon would vote again if the low |
| 1837 | * memory condition is still there, due to vmd_oom being |
| 1838 | * false. |
| 1839 | */ |
| 1840 | vmd->vmd_oom = FALSE; |
| 1841 | atomic_subtract_int(&vm_pageout_oom_vote, 1); |
| 1842 | } |
| 1843 | |
| 1844 | /* |
| 1845 | * The OOM killer is the page daemon's action of last resort when |
no test coverage detected