Index: sys/compat/svr4/svr4_misc.c =================================================================== RCS file: /cvsroot/src/sys/compat/svr4/svr4_misc.c,v retrieving revision 1.158 diff -p -u -r1.158 svr4_misc.c --- sys/compat/svr4/svr4_misc.c 28 Jul 2017 15:34:07 -0000 1.158 +++ sys/compat/svr4/svr4_misc.c 5 Feb 2018 22:09:20 -0000 @@ -729,6 +729,7 @@ svr4_sys_break(struct lwp *l, const stru uvm_deallocate(&vm->vm_map, new, old - new); vm->vm_dsize -= btoc(old - new); } + rusage_sync_proc(p); return 0; } Index: sys/compat/svr4_32/svr4_32_misc.c =================================================================== RCS file: /cvsroot/src/sys/compat/svr4_32/svr4_32_misc.c,v retrieving revision 1.79 diff -p -u -r1.79 svr4_32_misc.c --- sys/compat/svr4_32/svr4_32_misc.c 16 Sep 2017 09:04:50 -0000 1.79 +++ sys/compat/svr4_32/svr4_32_misc.c 5 Feb 2018 22:09:20 -0000 @@ -742,6 +742,7 @@ svr4_32_sys_break(struct lwp *l, const s uvm_deallocate(&vm->vm_map, new, old - new); vm->vm_dsize -= btoc(old - new); } + rusage_sync_proc(p); return 0; } Index: sys/kern/kern_exec.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_exec.c,v retrieving revision 1.455 diff -p -u -r1.455 kern_exec.c --- sys/kern/kern_exec.c 9 Jan 2018 20:55:43 -0000 1.455 +++ sys/kern/kern_exec.c 5 Feb 2018 22:09:20 -0000 @@ -105,6 +105,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_exec.c, #include #include #include +#include #include @@ -1155,6 +1156,7 @@ execve_runproc(struct lwp *l, struct exe vm->vm_issize = 0; vm->vm_maxsaddr = (void *)epp->ep_maxsaddr; vm->vm_minsaddr = (void *)epp->ep_minsaddr; + rusage_sync_proc(p); pax_aslr_init_vm(l, vm, epp); Index: sys/kern/kern_resource.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_resource.c,v retrieving revision 1.176 diff -p -u -r1.176 kern_resource.c --- sys/kern/kern_resource.c 24 Mar 2017 21:43:20 -0000 1.176 +++ sys/kern/kern_resource.c 5 Feb 2018 22:09:20 -0000 @@ -552,6 +552,26 @@ calcru(struct proc *p, struct timeval *u } } +/* + * Sync members of struct rusage with the address space. + * + * Approximate old style usage by saying text and swap are as old, + * and unshared data is everything else. Re-define "unshared data" + * to match this. It had been zero since NetBSD day 0. + */ +void +rusage_sync_proc(struct proc *p) +{ + struct rusage *ru = &p->p_stats->p_ru; + + mutex_enter(p->p_lock); + ru->ru_ixrss = p->p_vmspace->vm_tsize; + ru->ru_isrss = p->p_vmspace->vm_ssize; + ru->ru_idrss = curproc->p_vmspace->vm_map.size - + (ru->ru_ixrss + ru->ru_isrss); + mutex_exit(p->p_lock); +} + int sys___getrusage50(struct lwp *l, const struct sys___getrusage50_args *uap, register_t *retval) @@ -572,7 +592,8 @@ sys___getrusage50(struct lwp *l, const s } int -getrusage1(struct proc *p, int who, struct rusage *ru) { +getrusage1(struct proc *p, int who, struct rusage *ru) +{ switch (who) { case RUSAGE_SELF: Index: sys/sys/resourcevar.h =================================================================== RCS file: /cvsroot/src/sys/sys/resourcevar.h,v retrieving revision 1.56 diff -p -u -r1.56 resourcevar.h --- sys/sys/resourcevar.h 18 Oct 2015 00:28:15 -0000 1.56 +++ sys/sys/resourcevar.h 5 Feb 2018 22:09:20 -0000 @@ -122,6 +122,7 @@ void pstatsfree(struct pstats *); extern rlim_t maxdmap; extern rlim_t maxsmap; +void rusage_sync_proc(struct proc *); int getrusage1(struct proc *, int, struct rusage *); #endif Index: sys/uvm/uvm_mmap.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v retrieving revision 1.169 diff -p -u -r1.169 uvm_mmap.c --- sys/uvm/uvm_mmap.c 19 Dec 2017 18:34:47 -0000 1.169 +++ sys/uvm/uvm_mmap.c 5 Feb 2018 22:09:20 -0000 @@ -386,6 +386,7 @@ sys_mmap(struct lwp *l, const struct sys out: if (fp != NULL) fd_putfile(fd); + rusage_sync_proc(p); return error; } @@ -542,6 +543,7 @@ sys_munmap(struct lwp *l, const struct s vm_map_unlock(map); if (dead_entries != NULL) uvm_unmap_detach(dead_entries, 0); + rusage_sync_proc(p); return 0; } @@ -1042,6 +1044,7 @@ uvm_mmap_dev(struct proc *p, void **addr error = uvm_mmap(&p->p_vmspace->vm_map, (vaddr_t *)addrp, (vsize_t)len, prot, prot, flags, UVM_ADV_RANDOM, uobj, off, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur); + rusage_sync_proc(p); return error; } @@ -1062,5 +1065,6 @@ uvm_mmap_anon(struct proc *p, void **add error = uvm_mmap(&p->p_vmspace->vm_map, (vaddr_t *)addrp, (vsize_t)len, prot, prot, flags, UVM_ADV_NORMAL, NULL, 0, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur); + rusage_sync_proc(p); return error; } Index: sys/uvm/uvm_unix.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_unix.c,v retrieving revision 1.50 diff -p -u -r1.50 uvm_unix.c --- sys/uvm/uvm_unix.c 6 Jan 2018 16:41:24 -0000 1.50 +++ sys/uvm/uvm_unix.c 5 Feb 2018 22:09:20 -0000 @@ -122,6 +122,7 @@ sys_obreak(struct lwp *l, const struct s vm->vm_dsize -= atop(obreak - nbreak); } mutex_exit(&p->p_auxlock); + rusage_sync_proc(p); return (0); } @@ -167,6 +168,7 @@ uvm_grow(struct proc *p, vaddr_t sp) if (nss > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) return (0); vm->vm_ssize = nss; + rusage_sync_proc(p); return (1); }