[PATCH 016/18] kdb-add-mempolicy-cmd

quilt at tsunami.ccur.com quilt at tsunami.ccur.com
Thu Jul 10 13:25:03 PDT 2008


Create the KDB mempolicy command.

Added a new kdbm_mpol() routine, which supports a new
'mempolicy' command, where the command format is:

    mempolicy <addr>

and 'addr' is the address of the mempolicy structure.
This command is not present if CONFIG_NUMA is disabled.
This command parses the mempolicy type, and for the bind
policy it outputs the zonelist and decodes which node's
zones are in the zonelist.  It also decodes the info for
the other mempolicies.

Author: John Blackwood <john.blackwood at ccur.com>
Signed-off-by: Joe Korty <joe.korty at ccur.com>

Index: 2.6.26-rc9/kdb/modules/kdbm_vm.c
===================================================================
--- 2.6.26-rc9.orig/kdb/modules/kdbm_vm.c	2008-07-10 13:35:56.000000000 -0400
+++ 2.6.26-rc9/kdb/modules/kdbm_vm.c	2008-07-10 13:36:59.000000000 -0400
@@ -134,6 +134,89 @@
 	return 0;
 }
 
+
+#ifdef CONFIG_NUMA
+#include <linux/mempolicy.h>
+
+/*
+ * kdbm_mpol
+ *
+ *	This function implements the 'mempolicy' command.
+ *	Print a struct mempolicy.
+ *
+ *	mempolicy <address>	Print struct mempolicy at <address>
+ */
+static int
+kdbm_mpol(int argc, const char **argv)
+{
+	unsigned long addr;
+	long offset = 0;
+	int nextarg;
+	int err = 0;
+	struct mempolicy *mp = NULL;
+
+	if (argc != 1)
+		return KDB_ARGCOUNT;
+
+	nextarg = 1;
+	if ((err = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
+				NULL)) != 0)
+		return(err);
+
+	if (!(mp = kmalloc(sizeof(*mp), GFP_ATOMIC))) {
+		kdb_printf("%s: cannot kmalloc mp\n", __FUNCTION__);
+		goto out;
+	}
+
+	if ((err = kdb_getarea(*mp, addr))) {
+		kdb_printf("%s: invalid mempolicy address\n", __FUNCTION__);
+		goto out;
+	}
+
+	kdb_printf("struct mempolicy at 0x%p\n", (struct mempolicy *)addr);
+	kdb_printf("  refcnt %d\n", atomic_read(&mp->refcnt));
+
+	switch (mp->mode) {
+	  case MPOL_DEFAULT:
+		kdb_printf("  mode %d (MPOL_DEFAULT)\n", mp->mode);
+		break;
+
+	  case MPOL_PREFERRED:
+		kdb_printf("  mode %d (MPOL_PREFERRED)\n", mp->mode);
+		kdb_printf("  preferred_node %d\n", mp->v.preferred_node);
+		break;
+
+	  case MPOL_BIND:
+	  case MPOL_INTERLEAVE:
+	  {
+		int i, nlongs;
+		unsigned long *longp;
+
+		kdb_printf("  mode %d (%s)\n", mp->mode,
+			mp->mode == MPOL_INTERLEAVE
+				? "MPOL_INTERLEAVE"
+				: "MPOL_BIND");
+		nlongs = (int)BITS_TO_LONGS(MAX_NUMNODES);
+		kdb_printf("  nodes:");
+		longp = mp->v.nodes.bits;
+		for (i = 0; i < nlongs; i++, longp++)
+			kdb_printf("  0x%lx ", *longp);
+		kdb_printf("\n");
+		break;
+	  }
+
+	  default:
+		kdb_printf("  mode %d (unknown)\n", mp->mode);
+		break;
+	}
+out:
+	if (mp)
+		kfree(mp);
+	return err;
+}
+
+#endif /* CONFIG_NUMA */
+
 /*
  * kdbm_vm
  *
@@ -819,6 +902,9 @@
 {
 	kdb_register("vm", kdbm_vm, "[-v] <vaddr>", "Display vm_area_struct", 0);
 	kdb_register("vmp", kdbm_vm, "[-v] <pid>", "Display all vm_area_struct for <pid>", 0);
+#ifdef CONFIG_NUMA
+	kdb_register("mempolicy", kdbm_mpol, "<vaddr>", "Display mempolicy structure", 0);
+#endif
 	kdb_register("pte", kdbm_pte, "( -m <mm> | -p <pid> ) <vaddr> [<nbytes>]", "Display pte_t for mm_struct or pid", 0);
 	kdb_register("rpte", kdbm_rpte, "( -m <mm> | -p <pid> ) <pfn> [<npages>]", "Find pte_t containing pfn for mm_struct or pid", 0);
 	kdb_register("dentry", kdbm_dentry, "<dentry>", "Display interesting dentry stuff", 0);
@@ -836,6 +922,9 @@
 {
 	kdb_unregister("vm");
 	kdb_unregister("vmp");
+#ifdef CONFIG_NUMA
+	kdb_unregister("mempolicy");
+#endif
 	kdb_unregister("pte");
 	kdb_unregister("rpte");
 	kdb_unregister("dentry");
---------------------------
Use http://oss.sgi.com/ecartis to modify your settings or to unsubscribe.


More information about the kdb mailing list