* Returns true if the number of free pages exceeds the minimum * for the request class and false otherwise. */
| 2021 | * for the request class and false otherwise. |
| 2022 | */ |
| 2023 | static int |
| 2024 | _vm_domain_allocate(struct vm_domain *vmd, int req_class, int npages) |
| 2025 | { |
| 2026 | u_int limit, old, new; |
| 2027 | |
| 2028 | if (req_class == VM_ALLOC_INTERRUPT) |
| 2029 | limit = 0; |
| 2030 | else if (req_class == VM_ALLOC_SYSTEM) |
| 2031 | limit = vmd->vmd_interrupt_free_min; |
| 2032 | else |
| 2033 | limit = vmd->vmd_free_reserved; |
| 2034 | |
| 2035 | /* |
| 2036 | * Attempt to reserve the pages. Fail if we're below the limit. |
| 2037 | */ |
| 2038 | limit += npages; |
| 2039 | old = vmd->vmd_free_count; |
| 2040 | do { |
| 2041 | if (old < limit) |
| 2042 | return (0); |
| 2043 | new = old - npages; |
| 2044 | } while (atomic_fcmpset_int(&vmd->vmd_free_count, &old, new) == 0); |
| 2045 | |
| 2046 | /* Wake the page daemon if we've crossed the threshold. */ |
| 2047 | if (vm_paging_needed(vmd, new) && !vm_paging_needed(vmd, old)) |
| 2048 | pagedaemon_wakeup(vmd->vmd_domain); |
| 2049 | |
| 2050 | /* Only update bitsets on transitions. */ |
| 2051 | if ((old >= vmd->vmd_free_min && new < vmd->vmd_free_min) || |
| 2052 | (old >= vmd->vmd_free_severe && new < vmd->vmd_free_severe)) |
| 2053 | vm_domain_set(vmd); |
| 2054 | |
| 2055 | return (1); |
| 2056 | } |
| 2057 | |
| 2058 | int |
| 2059 | vm_domain_allocate(struct vm_domain *vmd, int req, int npages) |
no test coverage detected