git: 1e1727a7d7bd - stable/15 - vm_object_coalesce(): do not account holes twice

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 24 Jan 2026 00:32:20 UTC
The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=1e1727a7d7bdead736c221b0e4971bcba307fc94

commit 1e1727a7d7bdead736c221b0e4971bcba307fc94
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-11-27 21:53:24 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-01-24 00:26:44 +0000

    vm_object_coalesce(): do not account holes twice
    
    (cherry picked from commit 353ba3bf08fdef69b77e3e565435e50784a51412)
---
 sys/vm/vm_object.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index 36edb279bbce..c216fdc01af1 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -2202,7 +2202,8 @@ vm_object_coalesce(vm_object_t prev_object, vm_ooffset_t prev_offset,
 	/*
 	 * 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
@@ -2213,12 +2214,14 @@ vm_object_coalesce(vm_object_t prev_object, vm_ooffset_t prev_offset,
 		 * 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;
 	}
 
 	/*