diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -2200,7 +2200,8 @@ /* * Account for the charge. */ - if (prev_object->cred != NULL) { + if (prev_object->cred != NULL && + next_pindex + next_size > prev_object->size) { /* * If prev_object was charged, then this mapping, * although not charged now, may become writable @@ -2211,12 +2212,14 @@ * entry, and swap reservation for this entry is * managed in appropriate time. */ - if (!reserved && !swap_reserve_by_cred(ptoa(next_size), - prev_object->cred)) { + vm_size_t charge = ptoa(next_pindex + next_size - + prev_object->size); + if (!reserved && + !swap_reserve_by_cred(charge, prev_object->cred)) { VM_OBJECT_WUNLOCK(prev_object); return (FALSE); } - prev_object->charge += ptoa(next_size); + prev_object->charge += charge; } /* @@ -2226,16 +2229,6 @@ if (next_pindex < prev_object->size) { vm_object_page_remove(prev_object, next_pindex, next_pindex + next_size, 0); -#if 0 - if (prev_object->cred != NULL) { - KASSERT(prev_object->charge >= - ptoa(prev_object->size - next_pindex), - ("object %p overcharged 1 %jx %jx", prev_object, - (uintmax_t)next_pindex, (uintmax_t)next_size)); - prev_object->charge -= ptoa(prev_object->size - - next_pindex); - } -#endif } /*