The problem is here...
https://nxr.netbsd.org/xref/src/sys/uvm/pmap/pmap.c#1275
1275 if (pte_valid_p(opte) && pte_to_paddr(opte) != pa) {
1276 pmap_remove(pmap, va, va + NBPG);
1277 PMAP_COUNT(user_mappings_changed);
1278 }
1279
1280 KASSERT(pte_valid_p(npte));
1281 const bool resident = pte_valid_p(opte);
1282 if (resident) {
1283 update_flags |= PMAP_TLB_NEED_IPI;
1284 } else {
1285 pmap->pm_stats.resident_count++;
1286 }
if the mapping changes PA then the resident_count gets reduced by pmap_{,pte_}remove, but not increased again.
I'm working on a fix.