1 /* 2 * Copyright (c) 1983,1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)mbuf.c 5.5 (Berkeley) 02/07/88"; 15 #endif not lint 16 17 #include <stdio.h> 18 #include <sys/param.h> 19 #include <sys/mbuf.h> 20 #define YES 1 21 typedef int bool; 22 23 struct mbstat mbstat; 24 extern int kmem; 25 26 static struct mbtypes { 27 int mt_type; 28 char *mt_name; 29 } mbtypes[] = { 30 { MT_DATA, "data" }, 31 { MT_HEADER, "packet headers" }, 32 { MT_SOCKET, "socket structures" }, 33 { MT_PCB, "protocol control blocks" }, 34 { MT_RTABLE, "routing table entries" }, 35 { MT_HTABLE, "IMP host table entries" }, 36 { MT_ATABLE, "address resolution tables" }, 37 { MT_FTABLE, "fragment reassembly queue headers" }, 38 { MT_SONAME, "socket names and addresses" }, 39 { MT_SOOPTS, "socket options" }, 40 { MT_RIGHTS, "access rights" }, 41 { MT_IFADDR, "interface addresses" }, 42 { 0, 0 } 43 }; 44 45 int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); 46 bool seen[256]; /* "have we seen this type yet?" */ 47 48 /* 49 * Print mbuf statistics. 50 */ 51 mbpr(mbaddr) 52 off_t mbaddr; 53 { 54 register int totmem, totfree, totmbufs; 55 register int i; 56 register struct mbtypes *mp; 57 58 if (nmbtypes != 256) { 59 fprintf(stderr, "unexpected change to mbstat; check source\n"); 60 return; 61 } 62 if (mbaddr == 0) { 63 printf("mbstat: symbol not in namelist\n"); 64 return; 65 } 66 klseek(kmem, mbaddr, 0); 67 if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) { 68 printf("mbstat: bad read\n"); 69 return; 70 } 71 printf("%u/%u mbufs in use:\n", 72 mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs); 73 totmbufs = 0; 74 for (mp = mbtypes; mp->mt_name; mp++) 75 if (mbstat.m_mtypes[mp->mt_type]) { 76 seen[mp->mt_type] = YES; 77 printf("\t%u mbufs allocated to %s\n", 78 mbstat.m_mtypes[mp->mt_type], mp->mt_name); 79 totmbufs += mbstat.m_mtypes[mp->mt_type]; 80 } 81 seen[MT_FREE] = YES; 82 for (i = 0; i < nmbtypes; i++) 83 if (!seen[i] && mbstat.m_mtypes[i]) { 84 printf("\t%u mbufs allocated to <mbuf type %d>\n", 85 mbstat.m_mtypes[i], i); 86 totmbufs += mbstat.m_mtypes[i]; 87 } 88 if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) 89 printf("*** %u mbufs missing ***\n", 90 (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); 91 printf("%u/%u mapped pages in use\n", 92 mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); 93 totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES; 94 totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES; 95 printf("%u Kbytes allocated to network (%d%% in use)\n", 96 totmem / 1024, (totmem - totfree) * 100 / totmem); 97 printf("%u requests for memory denied\n", mbstat.m_drops); 98 printf("%u requests for memory delayed\n", mbstat.m_wait); 99 printf("%u calls to protocol drain routines\n", mbstat.m_drain); 100 } 101