4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #include <sys/mman.h>
  29 #include <sys/param.h>
  30 #include <sys/stat.h>
  31 #include <sys/types.h>
  32 #include <assert.h>
  33 #include <errno.h>
  34 #include <fcntl.h>
  35 #include <libproc.h>
  36 #include <limits.h>
  37 #include <procfs.h>
  38 #include <stdio.h>
  39 #include <stdlib.h>
  40 #include <strings.h>
  41 #include <time.h>
  42 #include <unistd.h>
  43 #include "rcapd.h"
 
 
 534                 if (mappings_changed_cb != NULL)
 535                         mappings_changed_cb(lpc);
 536         }
 537         return (0);
 538 }
 539 
 540 /*
 541  * Attempt to page out a region of the given process's address space.  May
 542  * return nonzero if not all of the pages may are pageable, for any reason.
 543  */
 544 static int
 545 pageout(pid_t pid, struct ps_prochandle *Pr, caddr_t start, caddr_t end)
 546 {
 547         int res;
 548 
 549         if (end <= start)
 550                 return (0);
 551 
 552         errno = 0;
 553         res = pr_memcntl(Pr, start, (end - start), MC_SYNC,
 554             (caddr_t)(MS_ASYNC | MS_INVALIDATE), 0, 0);
 555         debug_high("pr_memcntl [%p-%p): %d", (void *)start, (void *)end, res);
 556 
 557         /*
 558          * EBUSY indicates none of the pages have backing store allocated, or
 559          * some pages were locked, which are less interesting than other
 560          * conditions, which are noted.
 561          */
 562         if (res != 0)
 563                 if (errno == EBUSY)
 564                         res = 0;
 565                 else
 566                         debug("%d: can't pageout %p+%llx (errno %d)", (int)pid,
 567                             (void *)start, (long long)(end - start), errno);
 568 
 569         return (res);
 570 }
 571 
 572 /*
 573  * Compute the delta of the victim process's RSS since the last call.  If the
 574  * psinfo cannot be obtained, no work is done, and no error is returned; it is
 
 | 
 
 
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2012 Joyent, Inc.  All rights reserved.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <sys/mman.h>
  30 #include <sys/param.h>
  31 #include <sys/stat.h>
  32 #include <sys/types.h>
  33 #include <assert.h>
  34 #include <errno.h>
  35 #include <fcntl.h>
  36 #include <libproc.h>
  37 #include <limits.h>
  38 #include <procfs.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <strings.h>
  42 #include <time.h>
  43 #include <unistd.h>
  44 #include "rcapd.h"
 
 
 535                 if (mappings_changed_cb != NULL)
 536                         mappings_changed_cb(lpc);
 537         }
 538         return (0);
 539 }
 540 
 541 /*
 542  * Attempt to page out a region of the given process's address space.  May
 543  * return nonzero if not all of the pages may are pageable, for any reason.
 544  */
 545 static int
 546 pageout(pid_t pid, struct ps_prochandle *Pr, caddr_t start, caddr_t end)
 547 {
 548         int res;
 549 
 550         if (end <= start)
 551                 return (0);
 552 
 553         errno = 0;
 554         res = pr_memcntl(Pr, start, (end - start), MC_SYNC,
 555             (caddr_t)(MS_ASYNC | MS_INVALCURPROC), 0, 0);
 556         debug_high("pr_memcntl [%p-%p): %d", (void *)start, (void *)end, res);
 557 
 558         /*
 559          * EBUSY indicates none of the pages have backing store allocated, or
 560          * some pages were locked, which are less interesting than other
 561          * conditions, which are noted.
 562          */
 563         if (res != 0)
 564                 if (errno == EBUSY)
 565                         res = 0;
 566                 else
 567                         debug("%d: can't pageout %p+%llx (errno %d)", (int)pid,
 568                             (void *)start, (long long)(end - start), errno);
 569 
 570         return (res);
 571 }
 572 
 573 /*
 574  * Compute the delta of the victim process's RSS since the last call.  If the
 575  * psinfo cannot be obtained, no work is done, and no error is returned; it is
 
 |