1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)mbuf.c 5.1 (Berkeley) 06/04/85"; 9 #endif not lint 10 11 #include <stdio.h> 12 #include <sys/param.h> 13 #include <sys/mbuf.h> 14 #define YES 1 15 typedef int bool; 16 17 struct mbstat mbstat; 18 extern int kmem; 19 20 static struct mbtypes { 21 int mt_type; 22 char *mt_name; 23 } mbtypes[] = { 24 { MT_DATA, "data" }, 25 { MT_HEADER, "packet headers" }, 26 { MT_SOCKET, "socket structures" }, 27 { MT_PCB, "protocol control blocks" }, 28 { MT_RTABLE, "routing table entries" }, 29 { MT_HTABLE, "IMP host table entries" }, 30 { MT_ATABLE, "address resolution tables" }, 31 { MT_FTABLE, "fragment reassembly queue headers" }, 32 { MT_SONAME, "socket names and addresses" }, 33 { MT_ZOMBIE, "zombie process information" }, 34 { MT_SOOPTS, "socket options" }, 35 { MT_RIGHTS, "access rights" }, 36 { MT_IFADDR, "interface addresses" }, 37 { 0, 0 } 38 }; 39 40 int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); 41 bool seen[256]; /* "have we seen this type yet?" */ 42 43 /* 44 * Print mbuf statistics. 45 */ 46 mbpr(mbaddr) 47 off_t mbaddr; 48 { 49 register int totmem, totfree, totmbufs; 50 register int i; 51 register struct mbtypes *mp; 52 53 if (nmbtypes != 256) { 54 fprintf(stderr, "unexpected change to mbstat; check source\n"); 55 return; 56 } 57 if (mbaddr == 0) { 58 printf("mbstat: symbol not in namelist\n"); 59 return; 60 } 61 klseek(kmem, mbaddr, 0); 62 if (read(kmem, &mbstat, sizeof (mbstat)) != sizeof (mbstat)) { 63 printf("mbstat: bad read\n"); 64 return; 65 } 66 printf("%d/%d mbufs in use:\n", 67 mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs); 68 totmbufs = 0; 69 for (mp = mbtypes; mp->mt_name; mp++) 70 if (mbstat.m_mtypes[mp->mt_type]) { 71 seen[mp->mt_type] = YES; 72 printf("\t%d mbufs allocated to %s\n", 73 mbstat.m_mtypes[mp->mt_type], mp->mt_name); 74 totmbufs += mbstat.m_mtypes[mp->mt_type]; 75 } 76 seen[MT_FREE] = YES; 77 for (i = 0; i < nmbtypes; i++) 78 if (!seen[i] && mbstat.m_mtypes[i]) { 79 printf("\t%d mbufs allocated to <mbuf type %d>\n", 80 mbstat.m_mtypes[i], i); 81 totmbufs += mbstat.m_mtypes[i]; 82 } 83 if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) 84 printf("*** %d mbufs missing ***\n", 85 (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); 86 printf("%d/%d mapped pages in use\n", 87 mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); 88 totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES; 89 totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES; 90 printf("%d Kbytes allocated to network (%d%% in use)\n", 91 totmem / 1024, (totmem - totfree) * 100 / totmem); 92 printf("%d requests for memory denied\n", mbstat.m_drops); 93 } 94