git: 6ada4e8a0ae9 - main - swap-like pagers: assert that writemapping decrease does not pass zero

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 13 May 2024 18:34:25 UTC
The branch main has been updated by kib:

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

commit 6ada4e8a0ae901f0012015c8d277d80aad7d8f37
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-08 13:58:52 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-13 18:33:29 +0000

    swap-like pagers: assert that writemapping decrease does not pass zero
    
    Reviewed by:    markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D45119
---
 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 84ce323441c1..4ddf2b4ba5ff 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -183,6 +183,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 ee236c7f3988..a07a38481490 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -3158,6 +3158,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);
 }