17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5da6c28aaSamw * Common Development and Distribution License (the "License"). 6da6c28aaSamw * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2240688216SSudheer A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 417c478bd9Sstevel@tonic-gate #include <sys/param.h> 427c478bd9Sstevel@tonic-gate #include <sys/systm.h> 437c478bd9Sstevel@tonic-gate #include <sys/mman.h> 447c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 457c478bd9Sstevel@tonic-gate #include <sys/errno.h> 467c478bd9Sstevel@tonic-gate #include <sys/signal.h> 477c478bd9Sstevel@tonic-gate #include <sys/user.h> 487c478bd9Sstevel@tonic-gate #include <sys/proc.h> 497c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 507c478bd9Sstevel@tonic-gate #include <sys/debug.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <vm/hat.h> 537c478bd9Sstevel@tonic-gate #include <vm/as.h> 547c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h> 557c478bd9Sstevel@tonic-gate #include <vm/rm.h> 567c478bd9Sstevel@tonic-gate #include <vm/seg.h> 577c478bd9Sstevel@tonic-gate #include <vm/page.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate * Yield the memory claim requirement for an address space. 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * This is currently implemented as the number of active hardware 637c478bd9Sstevel@tonic-gate * translations that have page structures. Therefore, it can 647c478bd9Sstevel@tonic-gate * underestimate the traditional resident set size, eg, if the 657c478bd9Sstevel@tonic-gate * physical page is present and the hardware translation is missing; 667c478bd9Sstevel@tonic-gate * and it can overestimate the rss, eg, if there are active 677c478bd9Sstevel@tonic-gate * translations to a frame buffer with page structs. 68*0d5ae8c1SJosef 'Jeff' Sipek * Also, it does not take sharing into account. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate size_t 717c478bd9Sstevel@tonic-gate rm_asrss(as) 727c478bd9Sstevel@tonic-gate register struct as *as; 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate if (as != (struct as *)NULL && as != &kas) 757c478bd9Sstevel@tonic-gate return ((size_t)btop(hat_get_mapped_size(as->a_hat))); 767c478bd9Sstevel@tonic-gate else 777c478bd9Sstevel@tonic-gate return (0); 787c478bd9Sstevel@tonic-gate } 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Return a 16-bit binary fraction representing the percent of total memory 827c478bd9Sstevel@tonic-gate * used by this address space. Binary point is to right of high-order bit. 837c478bd9Sstevel@tonic-gate * Defined as the ratio of a_rss for the process to total physical memory. 847c478bd9Sstevel@tonic-gate * This assumes 2s-complement arithmetic and that shorts and longs are 857c478bd9Sstevel@tonic-gate * 16 bits and 32 bits, respectively. 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate ushort_t 887c478bd9Sstevel@tonic-gate rm_pctmemory(struct as *as) 897c478bd9Sstevel@tonic-gate { 907c478bd9Sstevel@tonic-gate /* This can't overflow */ 917c478bd9Sstevel@tonic-gate ulong_t num = (ulong_t)rm_asrss(as) << (PAGESHIFT-1); 927c478bd9Sstevel@tonic-gate int shift = 16 - PAGESHIFT; 937c478bd9Sstevel@tonic-gate ulong_t total = total_pages; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate if (shift < 0) { 967c478bd9Sstevel@tonic-gate num >>= (-shift); 977c478bd9Sstevel@tonic-gate shift = 0; 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate while (shift > 0 && (num & 0x80000000) == 0) { 1007c478bd9Sstevel@tonic-gate shift--; 1017c478bd9Sstevel@tonic-gate num <<= 1; 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate if (shift > 0) 1047c478bd9Sstevel@tonic-gate total >>= shift; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate return (num / total); 1077c478bd9Sstevel@tonic-gate } 108