xref: /onnv-gate/usr/src/uts/common/vm/vm_rm.c (revision 10169:116daeae7223)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10169SSudheer.Abdul-Salam@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/t_lock.h>
410Sstevel@tonic-gate #include <sys/param.h>
420Sstevel@tonic-gate #include <sys/systm.h>
430Sstevel@tonic-gate #include <sys/mman.h>
440Sstevel@tonic-gate #include <sys/sysmacros.h>
450Sstevel@tonic-gate #include <sys/errno.h>
460Sstevel@tonic-gate #include <sys/signal.h>
470Sstevel@tonic-gate #include <sys/user.h>
480Sstevel@tonic-gate #include <sys/proc.h>
490Sstevel@tonic-gate #include <sys/cmn_err.h>
500Sstevel@tonic-gate #include <sys/debug.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #include <vm/hat.h>
530Sstevel@tonic-gate #include <vm/as.h>
540Sstevel@tonic-gate #include <vm/seg_vn.h>
550Sstevel@tonic-gate #include <vm/rm.h>
560Sstevel@tonic-gate #include <vm/seg.h>
570Sstevel@tonic-gate #include <vm/page.h>
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * Yield the memory claim requirement for an address space.
610Sstevel@tonic-gate  *
620Sstevel@tonic-gate  * This is currently implemented as the number of active hardware
630Sstevel@tonic-gate  * translations that have page structures.  Therefore, it can
640Sstevel@tonic-gate  * underestimate the traditional resident set size, eg, if the
650Sstevel@tonic-gate  * physical page is present and the hardware translation is missing;
660Sstevel@tonic-gate  * and it can overestimate the rss, eg, if there are active
670Sstevel@tonic-gate  * translations to a frame buffer with page structs.
680Sstevel@tonic-gate  * Also, it does not take sharing and XHATs into account.
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate size_t
rm_asrss(as)710Sstevel@tonic-gate rm_asrss(as)
720Sstevel@tonic-gate 	register struct as *as;
730Sstevel@tonic-gate {
740Sstevel@tonic-gate 	if (as != (struct as *)NULL && as != &kas)
750Sstevel@tonic-gate 		return ((size_t)btop(hat_get_mapped_size(as->a_hat)));
760Sstevel@tonic-gate 	else
770Sstevel@tonic-gate 		return (0);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * Return a 16-bit binary fraction representing the percent of total memory
820Sstevel@tonic-gate  * used by this address space.  Binary point is to right of high-order bit.
830Sstevel@tonic-gate  * Defined as the ratio of a_rss for the process to total physical memory.
840Sstevel@tonic-gate  * This assumes 2s-complement arithmetic and that shorts and longs are
850Sstevel@tonic-gate  * 16 bits and 32 bits, respectively.
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate ushort_t
rm_pctmemory(struct as * as)880Sstevel@tonic-gate rm_pctmemory(struct as *as)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	/* This can't overflow */
910Sstevel@tonic-gate 	ulong_t num = (ulong_t)rm_asrss(as) << (PAGESHIFT-1);
920Sstevel@tonic-gate 	int shift = 16 - PAGESHIFT;
930Sstevel@tonic-gate 	ulong_t total = total_pages;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	if (shift < 0) {
960Sstevel@tonic-gate 		num >>= (-shift);
970Sstevel@tonic-gate 		shift = 0;
980Sstevel@tonic-gate 	}
990Sstevel@tonic-gate 	while (shift > 0 && (num & 0x80000000) == 0) {
1000Sstevel@tonic-gate 		shift--;
1010Sstevel@tonic-gate 		num <<= 1;
1020Sstevel@tonic-gate 	}
1030Sstevel@tonic-gate 	if (shift > 0)
1040Sstevel@tonic-gate 		total >>= shift;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	return (num / total);
1070Sstevel@tonic-gate }
108