Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Mar 2015 10:02:29 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r280805 - head/sys/kern
Message-ID:  <201503291002.t2TA2TbM021925@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Mar 29 10:02:29 2015
New Revision: 280805
URL: https://svnweb.freebsd.org/changeset/base/280805

Log:
  Add four new DDB commands to display vmem(9) statistics.
  
  In particular, such DDB commands were added:
          show vmem <addr>
          show all vmem
          show vmemdump <addr>
          show all vmemdump
  
  As possible usage, that allows to see KVA usage and fragmentation.

Modified:
  head/sys/kern/subr_vmem.c

Modified: head/sys/kern/subr_vmem.c
==============================================================================
--- head/sys/kern/subr_vmem.c	Sun Mar 29 07:48:02 2015	(r280804)
+++ head/sys/kern/subr_vmem.c	Sun Mar 29 10:02:29 2015	(r280805)
@@ -1390,6 +1390,8 @@ vmem_dump(const vmem_t *vm , int (*pr)(c
 #endif /* defined(DDB) || defined(DIAGNOSTIC) */
 
 #if defined(DDB)
+#include <ddb/ddb.h>
+
 static bt_t *
 vmem_whatis_lookup(vmem_t *vm, vmem_addr_t addr)
 {
@@ -1443,6 +1445,78 @@ vmem_print(vmem_addr_t addr, const char 
 
 	vmem_dump(vm, pr);
 }
+
+DB_SHOW_COMMAND(vmemdump, vmemdump)
+{
+
+	if (!have_addr) {
+		db_printf("usage: show vmemdump <addr>\n");
+		return;
+	}
+
+	vmem_dump((const vmem_t *)addr, db_printf);
+}
+
+DB_SHOW_ALL_COMMAND(vmemdump, vmemdumpall)
+{
+	const vmem_t *vm;
+
+	LIST_FOREACH(vm, &vmem_list, vm_alllist)
+		vmem_dump(vm, db_printf);
+}
+
+DB_SHOW_COMMAND(vmem, vmem_summ)
+{
+	const vmem_t *vm = (const void *)addr;
+	const bt_t *bt;
+	size_t ft[VMEM_MAXORDER], ut[VMEM_MAXORDER];
+	size_t fs[VMEM_MAXORDER], us[VMEM_MAXORDER];
+	int ord;
+
+	if (!have_addr) {
+		db_printf("usage: show vmem <addr>\n");
+		return;
+	}
+
+	db_printf("vmem %p '%s'\n", vm, vm->vm_name);
+	db_printf("\tquantum:\t%zu\n", vm->vm_quantum_mask + 1);
+	db_printf("\tsize:\t%zu\n", vm->vm_size);
+	db_printf("\tinuse:\t%zu\n", vm->vm_inuse);
+	db_printf("\tfree:\t%zu\n", vm->vm_size - vm->vm_inuse);
+	db_printf("\tbusy tags:\t%d\n", vm->vm_nbusytag);
+	db_printf("\tfree tags:\t%d\n", vm->vm_nfreetags);
+
+	memset(&ft, 0, sizeof(ft));
+	memset(&ut, 0, sizeof(ut));
+	memset(&fs, 0, sizeof(fs));
+	memset(&us, 0, sizeof(us));
+	TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
+		ord = SIZE2ORDER(bt->bt_size >> vm->vm_quantum_shift);
+		if (bt->bt_type == BT_TYPE_BUSY) {
+			ut[ord]++;
+			us[ord] += bt->bt_size;
+		} else if (bt->bt_type == BT_TYPE_FREE) {
+			ft[ord]++;
+			fs[ord] += bt->bt_size;
+		}
+	}
+	db_printf("\t\t\tinuse\tsize\t\tfree\tsize\n");
+	for (ord = 0; ord < VMEM_MAXORDER; ord++) {
+		if (ut[ord] == 0 && ft[ord] == 0)
+			continue;
+		db_printf("\t%-15zu %zu\t%-15zu %zu\t%-16zu\n",
+		    ORDER2SIZE(ord) << vm->vm_quantum_shift,
+		    ut[ord], us[ord], ft[ord], fs[ord]);
+	}
+}
+
+DB_SHOW_ALL_COMMAND(vmem, vmem_summall)
+{
+	const vmem_t *vm;
+
+	LIST_FOREACH(vm, &vmem_list, vm_alllist)
+		vmem_summ((db_expr_t)vm, TRUE, count, modif);
+}
 #endif /* defined(DDB) */
 
 #define vmem_printf printf



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503291002.t2TA2TbM021925>