Hi,

Here is a proof-of-concept patch that adds sockets related statistics to
netstat(1)'s -m option, which could make SA's life easier.  Inspired by
a local user's suggestion.

Comments?

Cheers,
-- 
Xin LI <[EMAIL PROTECTED]>      http://www.delphij.net/
FreeBSD - The Power to Serve!
Index: mbuf.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/mbuf.c,v
retrieving revision 1.53
diff -u -p -r1.53 mbuf.c
--- mbuf.c      16 Jul 2007 17:15:55 -0000      1.53
+++ mbuf.c      29 Aug 2007 06:45:26 -0000
@@ -1,4 +1,4 @@
-/*
+/*-
  * Copyright (c) 1983, 1988, 1993
  *     The Regents of the University of California.
  * Copyright (c) 2005 Robert N. M. Watson
@@ -58,6 +58,8 @@ __FBSDID("$FreeBSD: src/usr.bin/netstat/
 #include <string.h>
 #include "netstat.h"
 
+#define SOCKET_MEM_NAME "socket"
+
 /*
  * Print mbuf statistics.
  */
@@ -70,6 +72,7 @@ mbpr(void *kvmd, u_long mbaddr)
        uintmax_t cluster_count, cluster_bytes, cluster_limit, cluster_free;
        uintmax_t cluster_failures, cluster_size;
        uintmax_t packet_count, packet_bytes, packet_free, packet_failures;
+       uintmax_t socket_count, socket_bytes, socket_limit, socket_free, 
socket_failures;
        uintmax_t tag_count, tag_bytes;
        uintmax_t jumbop_count, jumbop_bytes, jumbop_limit, jumbop_free;
        uintmax_t jumbop_failures, jumbop_size;
@@ -134,6 +137,18 @@ mbpr(void *kvmd, u_long mbaddr)
        packet_free = memstat_get_free(mtp);
        packet_failures = memstat_get_failures(mtp);
 
+       mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, SOCKET_MEM_NAME);
+       if (mtp == NULL) {
+               warnx("memstat_mtl_find: zone %s not found",
+                   SOCKET_MEM_NAME);
+               goto out;
+       }
+       socket_count = memstat_get_count(mtp);
+       socket_bytes = memstat_get_bytes(mtp);
+       socket_free = memstat_get_free(mtp);
+       socket_limit = memstat_get_countlimit(mtp);
+       socket_failures = memstat_get_failures(mtp);
+
        mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME);
        if (mtp == NULL) {
                warnx("memstat_mtl_find: zone %s not found",
@@ -208,6 +223,9 @@ mbpr(void *kvmd, u_long mbaddr)
            "(current/cache)\n",
            packet_count, packet_free);
 
+       printf("%ju/%ju/%ju/%ju socket UMA in use (current/cache/total/max)\n",
+           socket_count, socket_free, socket_count + socket_free, 
socket_limit);
+
        printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use "
            "(current/cache/total/max)\n",
            jumbop_count, jumbop_free, jumbop_count + jumbop_free,
@@ -280,6 +298,11 @@ mbpr(void *kvmd, u_long mbaddr)
            "mbuf+clusters)\n", mbuf_failures, cluster_failures,
            packet_failures);
 
+       printf("%juK bytes allocated to socket\n",
+           socket_bytes / 1024);
+
+       printf("%ju request for socket UMA denied\n", socket_failures);
+
        printf("%ju/%ju/%ju requests for jumbo clusters denied "
            "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
            jumbo16_failures, jumbop_size / 1024);

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to