Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/swap_pager.c
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return (swap_reserve_by_cred(incr, curthread->td_ucred)); | return (swap_reserve_by_cred(incr, curthread->td_ucred)); | ||||
} | } | ||||
int | int | ||||
swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred) | swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred) | ||||
{ | { | ||||
vm_ooffset_t r, s; | vm_ooffset_t r, s, new; | ||||
int res, error; | int res, error; | ||||
static int curfail; | static int curfail; | ||||
static struct timeval lastfail; | static struct timeval lastfail; | ||||
struct uidinfo *uip; | struct uidinfo *uip; | ||||
uip = cred->cr_ruidinfo; | uip = cred->cr_ruidinfo; | ||||
if (incr & PAGE_MASK) | if (incr & PAGE_MASK) | ||||
panic("swap_reserve: & PAGE_MASK"); | panic("swap_reserve: & PAGE_MASK"); | ||||
#ifdef RACCT | #ifdef RACCT | ||||
if (racct_enable) { | if (racct_enable) { | ||||
PROC_LOCK(curproc); | PROC_LOCK(curproc); | ||||
error = racct_add(curproc, RACCT_SWAP, incr); | error = racct_add(curproc, RACCT_SWAP, incr); | ||||
PROC_UNLOCK(curproc); | PROC_UNLOCK(curproc); | ||||
if (error != 0) | if (error != 0) | ||||
return (0); | return (0); | ||||
} | } | ||||
#endif | #endif | ||||
res = 0; | res = 0; | ||||
mtx_lock(&sw_dev_mtx); | new = atomic_fetchadd_long(&swap_reserved, incr); | ||||
kib: I would not call this variable 'new'.
Also, I do not believe that the patch compiles on 32bit… | |||||
r = swap_reserved + incr; | r = new + incr; | ||||
if (overcommit & SWAP_RESERVE_ALLOW_NONWIRED) { | if (overcommit & SWAP_RESERVE_ALLOW_NONWIRED) { | ||||
s = vm_cnt.v_page_count - vm_cnt.v_free_reserved - | s = vm_cnt.v_page_count - vm_cnt.v_free_reserved - | ||||
vm_wire_count(); | vm_wire_count(); | ||||
s *= PAGE_SIZE; | s *= PAGE_SIZE; | ||||
} else | } else | ||||
s = 0; | s = 0; | ||||
s += swap_total; | s += swap_total; | ||||
if ((overcommit & SWAP_RESERVE_FORCE_ON) == 0 || r <= s || | if ((overcommit & SWAP_RESERVE_FORCE_ON) == 0 || r <= s || | ||||
(error = priv_check(curthread, PRIV_VM_SWAP_NOQUOTA)) == 0) { | (error = priv_check(curthread, PRIV_VM_SWAP_NOQUOTA)) == 0) { | ||||
res = 1; | res = 1; | ||||
swap_reserved = r; | } else | ||||
} | atomic_subtract_long(&swap_reserved, incr); | ||||
mtx_unlock(&sw_dev_mtx); | |||||
if (res) { | if (res) { | ||||
UIDINFO_VMSIZE_LOCK(uip); | new = atomic_fetchadd_long(&uip->ui_vmsize, incr); | ||||
if ((overcommit & SWAP_RESERVE_RLIMIT_ON) != 0 && | if ((overcommit & SWAP_RESERVE_RLIMIT_ON) != 0 && | ||||
uip->ui_vmsize + incr > lim_cur(curthread, RLIMIT_SWAP) && | new + incr > lim_cur(curthread, RLIMIT_SWAP) && | ||||
priv_check(curthread, PRIV_VM_SWAP_NORLIMIT)) | priv_check(curthread, PRIV_VM_SWAP_NORLIMIT)) { | ||||
res = 0; | res = 0; | ||||
else | atomic_subtract_long(&uip->ui_vmsize, incr); | ||||
uip->ui_vmsize += incr; | |||||
UIDINFO_VMSIZE_UNLOCK(uip); | |||||
if (!res) { | |||||
mtx_lock(&sw_dev_mtx); | |||||
swap_reserved -= incr; | |||||
mtx_unlock(&sw_dev_mtx); | |||||
} | } | ||||
if (!res) | |||||
atomic_add_long(&swap_reserved, -incr); | |||||
} | } | ||||
if (!res && ppsratecheck(&lastfail, &curfail, 1)) { | if (!res && ppsratecheck(&lastfail, &curfail, 1)) { | ||||
printf("uid %d, pid %d: swap reservation for %jd bytes failed\n", | printf("uid %d, pid %d: swap reservation for %jd bytes failed\n", | ||||
uip->ui_uid, curproc->p_pid, incr); | uip->ui_uid, curproc->p_pid, incr); | ||||
} | } | ||||
#ifdef RACCT | #ifdef RACCT | ||||
if (!res) { | if (racct_enable && !res) { | ||||
PROC_LOCK(curproc); | PROC_LOCK(curproc); | ||||
racct_sub(curproc, RACCT_SWAP, incr); | racct_sub(curproc, RACCT_SWAP, incr); | ||||
PROC_UNLOCK(curproc); | PROC_UNLOCK(curproc); | ||||
} | } | ||||
#endif | #endif | ||||
return (res); | return (res); | ||||
} | } | ||||
void | void | ||||
swap_reserve_force(vm_ooffset_t incr) | swap_reserve_force(vm_ooffset_t incr) | ||||
{ | { | ||||
struct uidinfo *uip; | struct uidinfo *uip; | ||||
mtx_lock(&sw_dev_mtx); | atomic_add_long(&swap_reserved, incr); | ||||
swap_reserved += incr; | |||||
mtx_unlock(&sw_dev_mtx); | |||||
#ifdef RACCT | #ifdef RACCT | ||||
if (racct_enable) { | |||||
PROC_LOCK(curproc); | PROC_LOCK(curproc); | ||||
racct_add_force(curproc, RACCT_SWAP, incr); | racct_add_force(curproc, RACCT_SWAP, incr); | ||||
PROC_UNLOCK(curproc); | PROC_UNLOCK(curproc); | ||||
} | |||||
#endif | #endif | ||||
uip = curthread->td_ucred->cr_ruidinfo; | uip = curthread->td_ucred->cr_ruidinfo; | ||||
PROC_LOCK(curproc); | atomic_add_long(&uip->ui_vmsize, incr); | ||||
UIDINFO_VMSIZE_LOCK(uip); | |||||
uip->ui_vmsize += incr; | |||||
UIDINFO_VMSIZE_UNLOCK(uip); | |||||
PROC_UNLOCK(curproc); | |||||
} | } | ||||
void | void | ||||
swap_release(vm_ooffset_t decr) | swap_release(vm_ooffset_t decr) | ||||
{ | { | ||||
struct ucred *cred; | struct ucred *cred; | ||||
PROC_LOCK(curproc); | |||||
cred = curthread->td_ucred; | cred = curthread->td_ucred; | ||||
swap_release_by_cred(decr, cred); | swap_release_by_cred(decr, cred); | ||||
PROC_UNLOCK(curproc); | |||||
} | } | ||||
void | void | ||||
swap_release_by_cred(vm_ooffset_t decr, struct ucred *cred) | swap_release_by_cred(vm_ooffset_t decr, struct ucred *cred) | ||||
{ | { | ||||
struct uidinfo *uip; | struct uidinfo *uip; | ||||
uip = cred->cr_ruidinfo; | uip = cred->cr_ruidinfo; | ||||
if (decr & PAGE_MASK) | if (decr & PAGE_MASK) | ||||
panic("swap_release: & PAGE_MASK"); | panic("swap_release: & PAGE_MASK"); | ||||
mtx_lock(&sw_dev_mtx); | |||||
if (swap_reserved < decr) | if (swap_reserved < decr) | ||||
panic("swap_reserved < decr"); | panic("swap_reserved < decr"); | ||||
swap_reserved -= decr; | atomic_subtract_long(&swap_reserved, -decr); | ||||
mtx_unlock(&sw_dev_mtx); | |||||
UIDINFO_VMSIZE_LOCK(uip); | |||||
if (uip->ui_vmsize < decr) | if (uip->ui_vmsize < decr) | ||||
printf("negative vmsize for uid = %d\n", uip->ui_uid); | printf("negative vmsize for uid = %d\n", uip->ui_uid); | ||||
uip->ui_vmsize -= decr; | atomic_subtract_long(&uip->ui_vmsize, decr); | ||||
UIDINFO_VMSIZE_UNLOCK(uip); | if (racct_enable) | ||||
kibUnsubmitted Not Done Inline ActionsThis does not compole for kernels without RACCT. kib: This does not compole for kernels without RACCT. | |||||
racct_sub_cred(cred, RACCT_SWAP, decr); | racct_sub_cred(cred, RACCT_SWAP, decr); | ||||
} | } | ||||
#define SWM_POP 0x01 /* pop out */ | #define SWM_POP 0x01 /* pop out */ | ||||
static int swap_pager_full = 2; /* swap space exhaustion (task killing) */ | static int swap_pager_full = 2; /* swap space exhaustion (task killing) */ | ||||
static int swap_pager_almost_full = 1; /* swap space exhaustion (w/hysteresis)*/ | static int swap_pager_almost_full = 1; /* swap space exhaustion (w/hysteresis)*/ | ||||
static int nsw_rcount; /* free read buffers */ | static int nsw_rcount; /* free read buffers */ | ||||
static int nsw_wcount_sync; /* limit write buffers / synchronous */ | static int nsw_wcount_sync; /* limit write buffers / synchronous */ | ||||
▲ Show 20 Lines • Show All 2,562 Lines • Show Last 20 Lines |
I would not call this variable 'new'.
Also, I do not believe that the patch compiles on 32bit architectures.