git: f0d6377a3eab - stable/14 - swap-like pagers: assert that writemapping decrease does not pass zero

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 20 May 2024 00:25:31 UTC
The branch stable/14 has been updated by kib:

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

commit f0d6377a3eab6d07f73d5b34922c2b3d9019554c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-08 13:58:52 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-19 00:57:54 +0000

    swap-like pagers: assert that writemapping decrease does not pass zero
    
    (cherry picked from commit 6ada4e8a0ae901f0012015c8d277d80aad7d8f37)
---
 sys/fs/tmpfs/tmpfs_subr.c | 3 +++
 sys/vm/swap_pager.c       | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index 13323d50228a..b12e9b91fabc 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -179,6 +179,9 @@ tmpfs_pager_release_writecount(vm_object_t object, vm_offset_t start,
 	KASSERT((object->flags & OBJ_ANON) == 0,
 	    ("%s: object %p with OBJ_ANON", __func__, object));
 	old = object->un_pager.swp.writemappings;
+	KASSERT(old >= (vm_ooffset_t)end - start,
+	    ("tmpfs obj %p writecount %jx dec %jx", object, (uintmax_t)old,
+	    (uintmax_t)((vm_ooffset_t)end - start)));
 	object->un_pager.swp.writemappings -= (vm_ooffset_t)end - start;
 	new = object->un_pager.swp.writemappings;
 	tmpfs_pager_writecount_recalc(object, old, new);
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index c8b08e0e8315..ce578cc4fd8b 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -3161,6 +3161,10 @@ swap_pager_release_writecount(vm_object_t object, vm_offset_t start,
 	VM_OBJECT_WLOCK(object);
 	KASSERT((object->flags & OBJ_ANON) == 0,
 	    ("Splittable object with writecount"));
+	KASSERT(object->un_pager.swp.writemappings >= (vm_ooffset_t)end - start,
+	    ("swap obj %p writecount %jx dec %jx", object,
+	    (uintmax_t)object->un_pager.swp.writemappings,
+	    (uintmax_t)((vm_ooffset_t)end - start)));
 	object->un_pager.swp.writemappings -= (vm_ooffset_t)end - start;
 	VM_OBJECT_WUNLOCK(object);
 }