Author: avg
Date: Tue Feb 14 13:54:05 2017
New Revision: 313730
URL: https://svnweb.freebsd.org/changeset/base/313730

Log:
  try to fix RACCT_RSS accounting
  
  There could be a race between the vm daemon setting RACCT_RSS based on
  the vm space and vmspace_exit (called from exit1) resetting RACCT_RSS to
  zero.  In that case we can get a zombie process with non-zero RACCT_RSS.
  If the process is jailed, that may break accounting for the jail.
  There could be other consequences.
  
  Fix this race in the vm daemon by updating RACCT_RSS only when a process
  is in the normal state.  Also, make accounting a little bit more
  accurate by refreshing the page resident count after calling
  vm_pageout_map_deactivate_pages().
  Finally, add an assert that the RSS is zero when a process is reaped.
  
  PR:           210315
  Reviewed by:  trasz
  Differential Revision: https://reviews.freebsd.org/D9464

Modified:
  head/sys/kern/kern_racct.c
  head/sys/vm/vm_pageout.c

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c  Tue Feb 14 13:45:38 2017        (r313729)
+++ head/sys/kern/kern_racct.c  Tue Feb 14 13:54:05 2017        (r313730)
@@ -1010,10 +1010,13 @@ racct_proc_exit(struct proc *p)
        racct_set_locked(p, RACCT_CPU, runtime, 0);
        racct_add_cred_locked(p->p_ucred, RACCT_PCTCPU, pct);
 
+       KASSERT(p->p_racct->r_resources[RACCT_RSS] == 0,
+           ("process reaped with %ju allocated for RSS\n",
+           p->p_racct->r_resources[RACCT_RSS]));
        for (i = 0; i <= RACCT_MAX; i++) {
                if (p->p_racct->r_resources[i] == 0)
                        continue;
-               if (!RACCT_IS_RECLAIMABLE(i))
+               if (!RACCT_IS_RECLAIMABLE(i))
                        continue;
                racct_set_locked(p, i, 0, 0);
        }

Modified: head/sys/vm/vm_pageout.c
==============================================================================
--- head/sys/vm/vm_pageout.c    Tue Feb 14 13:45:38 2017        (r313729)
+++ head/sys/vm/vm_pageout.c    Tue Feb 14 13:54:05 2017        (r313730)
@@ -2268,12 +2268,14 @@ again:
                        if (size >= limit) {
                                vm_pageout_map_deactivate_pages(
                                    &vm->vm_map, limit);
+                               size = vmspace_resident_count(vm);
                        }
 #ifdef RACCT
                        if (racct_enable) {
                                rsize = IDX_TO_OFF(size);
                                PROC_LOCK(p);
-                               racct_set(p, RACCT_RSS, rsize);
+                               if (p->p_state == PRS_NORMAL)
+                                       racct_set(p, RACCT_RSS, rsize);
                                ravailable = racct_get_available(p, RACCT_RSS);
                                PROC_UNLOCK(p);
                                if (rsize > ravailable) {
@@ -2299,7 +2301,8 @@ again:
                                        size = vmspace_resident_count(vm);
                                        rsize = IDX_TO_OFF(size);
                                        PROC_LOCK(p);
-                                       racct_set(p, RACCT_RSS, rsize);
+                                       if (p->p_state == PRS_NORMAL)
+                                               racct_set(p, RACCT_RSS, rsize);
                                        PROC_UNLOCK(p);
                                        if (rsize > ravailable)
                                                tryagain = 1;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to