Add a function to convert a policy into a string. Add string conversion function to policy layer and use that function for /proc//numa_maps Syntax of textual representation: default preferred= bind= interleave= Signed-off-by: Christoph Lameter Index: linux-2.6.14-rc5-mm1/mm/mempolicy.c =================================================================== --- linux-2.6.14-rc5-mm1.orig/mm/mempolicy.c 2005-11-03 11:50:02.000000000 -0800 +++ linux-2.6.14-rc5-mm1/mm/mempolicy.c 2005-11-03 11:52:55.000000000 -0800 @@ -1583,15 +1583,67 @@ static struct numa_maps *get_numa_maps(c return md; } +static const char *policy_types[] = { "default", "prefer", "bind", "interleave" }; + +/* + * Convert a mempolicy into a string. + * Returns the number of characters in buffer (if positive) + * or an error (negative) + */ +static int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) +{ + char *p = buffer; + int l; + nodemask_t nodes; + int mode = pol ? pol->policy : MPOL_DEFAULT; + + switch (mode) { + case MPOL_DEFAULT: + nodes_clear(nodes); + break; + + case MPOL_PREFERRED: + nodes_clear(nodes); + node_set(pol->v.preferred_node, nodes); + break; + + case MPOL_BIND: + get_zonemask(pol, &nodes); + break; + + case MPOL_INTERLEAVE: + nodes = pol->v.nodes; + break; + + default: + BUG(); + return -EFAULT; + } + + l = strlen(policy_types[mode]); + if (buffer + maxlen < p + l + 1) + return -ENOSPC; + + strcpy(p, policy_types[mode]); + p += l; + + if (!nodes_empty(nodes)) { + if (buffer + maxlen < p + 2) + return -ENOSPC; + *p++ = '='; + p += nodelist_scnprintf(p, buffer + maxlen - p, nodes); + } + + return p - buffer; +} + static int show_numa_map(struct seq_file *m, void *v) { struct task_struct *task = m->private; struct vm_area_struct *vma = v; - struct mempolicy *pol; struct numa_maps *md; - struct zone **z; int n; - int first; + char buffer[50]; if (!vma->vm_mm) return 0; @@ -1600,47 +1652,10 @@ static int show_numa_map(struct seq_file if (!md) return 0; - seq_printf(m, "%08lx", vma->vm_start); - pol = get_vma_policy(task, vma, vma->vm_start); - /* Print policy */ - switch (pol->policy) { - case MPOL_PREFERRED: - seq_printf(m, " prefer=%d", pol->v.preferred_node); - break; - case MPOL_BIND: - seq_printf(m, " bind={"); - first = 1; - for (z = pol->v.zonelist->zones; *z; z++) { - - if (!first) - seq_putc(m, ','); - else - first = 0; - seq_printf(m, "%d/%s", (*z)->zone_pgdat->node_id, - (*z)->name); - } - seq_putc(m, '}'); - break; - case MPOL_INTERLEAVE: - seq_printf(m, " interleave={"); - first = 1; - for_each_node(n) { - if (node_isset(n, pol->v.nodes)) { - if (!first) - seq_putc(m,','); - else - first = 0; - seq_printf(m, "%d",n); - } - } - seq_putc(m, '}'); - break; - default: - seq_printf(m," default"); - break; - } - seq_printf(m, " MaxRef=%lu Pages=%lu Mapped=%lu", - md->mapcount_max, md->pages, md->mapped); + mpol_to_str(buffer, sizeof(buffer), get_vma_policy(task, vma, vma->vm_start)); + seq_printf(m, "%08lx %s MaxRef=%lu Pages=%lu Mapped=%lu", + vma->vm_start, buffer, md->mapcount_max, md->pages, md->mapped); + if (md->anon) seq_printf(m," Anon=%lu",md->anon); @@ -1661,3 +1676,4 @@ struct seq_operations proc_pid_numa_maps .stop = m_stop, .show = show_numa_map }; +