usr/src/cmd/mdb/common/modules/genunix/memory.c
changeset 3290 256464cbb73c
parent 436 c9ab97f06761
child 5084 7d838c5c0eed
equal deleted inserted replaced
3289:95e8ec05aa83 3290:256464cbb73c
     1 /*
     1 /*
     2  * CDDL HEADER START
     2  * CDDL HEADER START
     3  *
     3  *
     4  * The contents of this file are subject to the terms of the
     4  * The contents of this file are subject to the terms of the
     5  * Common Development and Distribution License, Version 1.0 only
     5  * Common Development and Distribution License (the "License").
     6  * (the "License").  You may not use this file except in compliance
     6  * You may not use this file except in compliance with the License.
     7  * with the License.
       
     8  *
     7  *
     9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
    10  * or http://www.opensolaris.org/os/licensing.
     9  * or http://www.opensolaris.org/os/licensing.
    11  * See the License for the specific language governing permissions
    10  * See the License for the specific language governing permissions
    12  * and limitations under the License.
    11  * and limitations under the License.
    18  * information: Portions Copyright [yyyy] [name of copyright owner]
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
    19  *
    18  *
    20  * CDDL HEADER END
    19  * CDDL HEADER END
    21  */
    20  */
    22 /*
    21 /*
    23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
    22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
    24  * Use is subject to license terms.
    23  * Use is subject to license terms.
    25  */
    24  */
    26 
    25 
    27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    28 
    27 
   216 }
   215 }
   217 
   216 
   218 /* Summary statistics of pages */
   217 /* Summary statistics of pages */
   219 typedef struct memstat {
   218 typedef struct memstat {
   220 	struct vnode    *ms_kvp;	/* Cached address of kernel vnode */
   219 	struct vnode    *ms_kvp;	/* Cached address of kernel vnode */
       
   220 	struct vnode    *ms_zvp;	/* Cached address of zio vnode    */
   221 	uint64_t	ms_kmem;	/* Pages of kernel memory	  */
   221 	uint64_t	ms_kmem;	/* Pages of kernel memory	  */
   222 	uint64_t	ms_anon;	/* Pages of anonymous memory	  */
   222 	uint64_t	ms_anon;	/* Pages of anonymous memory	  */
   223 	uint64_t	ms_vnode;	/* Pages of named (vnode) memory  */
   223 	uint64_t	ms_vnode;	/* Pages of named (vnode) memory  */
   224 	uint64_t	ms_exec;	/* Pages of exec/library memory	  */
   224 	uint64_t	ms_exec;	/* Pages of exec/library memory	  */
   225 	uint64_t	ms_cachelist;	/* Pages on the cachelist (free)  */
   225 	uint64_t	ms_cachelist;	/* Pages on the cachelist (free)  */
   226 	uint64_t	ms_total;	/* Pages on page hash		  */
   226 	uint64_t	ms_total;	/* Pages on page hash		  */
   227 } memstat_t;
   227 } memstat_t;
   228 
   228 
       
   229 #define	MS_PP_ISKAS(pp, stats)				\
       
   230 	(((pp)->p_vnode == (stats)->ms_kvp) ||		\
       
   231 	    (((stats)->ms_zvp != NULL) && ((pp)->p_vnode == (stats)->ms_zvp)))
       
   232 
   229 /*
   233 /*
   230  * Summarize pages by type; called from page walker.
   234  * Summarize pages by type; called from page walker.
   231  */
   235  */
   232 
   236 
   233 /* ARGSUSED */
   237 /* ARGSUSED */
   250 
   254 
   251 	if (PP_ISFREE(pp))
   255 	if (PP_ISFREE(pp))
   252 		stats->ms_cachelist++;
   256 		stats->ms_cachelist++;
   253 	else if (vp && IS_SWAPFSVP(vp))
   257 	else if (vp && IS_SWAPFSVP(vp))
   254 		stats->ms_anon++;
   258 		stats->ms_anon++;
   255 	else if (pp->p_vnode == stats->ms_kvp)
   259 	else if (MS_PP_ISKAS(pp, stats))
   256 		stats->ms_kmem++;
   260 		stats->ms_kmem++;
   257 	else if (vp && (((vp)->v_flag & VVMEXEC)) != 0)
   261 	else if (vp && (((vp)->v_flag & VVMEXEC)) != 0)
   258 		stats->ms_exec++;
   262 		stats->ms_exec++;
   259 	else
   263 	else
   260 		stats->ms_vnode++;
   264 		stats->ms_vnode++;
   305 		mdb_warn("unable to read kvp");
   309 		mdb_warn("unable to read kvp");
   306 		return (DCMD_ERR);
   310 		return (DCMD_ERR);
   307 	}
   311 	}
   308 
   312 
   309 	stats.ms_kvp = (struct vnode *)(uintptr_t)sym.st_value;
   313 	stats.ms_kvp = (struct vnode *)(uintptr_t)sym.st_value;
       
   314 
       
   315 	/*
       
   316 	 * Read the zio vnode pointer.  It may not exist on all kernels, so it
       
   317 	 * it isn't found, it's not a fatal error.
       
   318 	 */
       
   319 	if (mdb_lookup_by_obj(MDB_OBJ_EXEC, "zvp",
       
   320 		(GElf_Sym *)&sym) == -1) {
       
   321 		stats.ms_zvp = NULL;
       
   322 	} else {
       
   323 		stats.ms_zvp = (struct vnode *)(uintptr_t)sym.st_value;
       
   324 	}
   310 
   325 
   311 	/* Walk page structures, summarizing usage */
   326 	/* Walk page structures, summarizing usage */
   312 	if (mdb_walk("page", (mdb_walk_cb_t)memstat_callback,
   327 	if (mdb_walk("page", (mdb_walk_cb_t)memstat_callback,
   313 		&stats) == -1) {
   328 		&stats) == -1) {
   314 		mdb_warn("can't walk pages");
   329 		mdb_warn("can't walk pages");