aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Schermerhorn <lee.schermerhorn@hp.com>2008-04-28 05:13:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-28 11:58:24 -0400
commit2291990ab36b4b2d8a81b1f92e7a046e51632a60 (patch)
treeb5b6b8ca9c92bc3c84cd7e7aefb5010d3793db4d
parentfc36b8d3d819047eb4d23ca079fb4d3af20ff076 (diff)
mempolicy: clean-up mpol-to-str() mempolicy formatting
mpol-to-str() formats memory policies into printable strings. Currently this is only used to display "numa_maps". A subsequent patch will use mpol_to_str() for formatting tmpfs [shmem] mpol mount options, allowing us to remove essentially duplicate code in mm/shmem.c. This patch cleans up mpol_to_str() generally and in preparation for that patch. 1) show_numa_maps() is not checking the return code from mpol_to_str(). There's not a lot we can do in this context if mpol_to_str() did return the error [insufficient space in buffer]. Proposed "solution": just check, under DEBUG_VM, that callers are providing sufficient buffer space for the policy, flags, and a few nodes. This way, we'll get some display. show_numa_maps() is providing a 50-byte buffer, so it won't trip this check. 50-bytes should be sufficient unless one has a large number of nodes in a very sparse nodemask. 2) The display of the new mode flags ["static" & "relative"] was set up to display multiple flags, separated by a "bar" '|'. However, this support is incomplete--e.g., need_bar was never incremented; and currently, these two flags are mutually exclusive. So remove the "bar" support, for now, and only display one flag. 3) Use snprint() to format flags, so as not to overflow the buffer. Not that it's ever happed, AFAIK. Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Cc: Christoph Lameter <clameter@sgi.com> Cc: David Rientjes <rientjes@google.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Andi Kleen <ak@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/mempolicy.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 143b019e9834..3c8ee31572ec 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1965,6 +1965,11 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
1965 unsigned short mode; 1965 unsigned short mode;
1966 unsigned short flags = pol ? pol->flags : 0; 1966 unsigned short flags = pol ? pol->flags : 0;
1967 1967
1968 /*
1969 * Sanity check: room for longest mode, flag and some nodes
1970 */
1971 VM_BUG_ON(maxlen < strlen("interleave") + strlen("relative") + 16);
1972
1968 if (!pol || pol == &default_policy) 1973 if (!pol || pol == &default_policy)
1969 mode = MPOL_DEFAULT; 1974 mode = MPOL_DEFAULT;
1970 else 1975 else
@@ -1991,7 +1996,6 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
1991 1996
1992 default: 1997 default:
1993 BUG(); 1998 BUG();
1994 return -EFAULT;
1995 } 1999 }
1996 2000
1997 l = strlen(policy_types[mode]); 2001 l = strlen(policy_types[mode]);
@@ -2002,16 +2006,17 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
2002 p += l; 2006 p += l;
2003 2007
2004 if (flags & MPOL_MODE_FLAGS) { 2008 if (flags & MPOL_MODE_FLAGS) {
2005 int need_bar = 0;
2006
2007 if (buffer + maxlen < p + 2) 2009 if (buffer + maxlen < p + 2)
2008 return -ENOSPC; 2010 return -ENOSPC;
2009 *p++ = '='; 2011 *p++ = '=';
2010 2012
2013 /*
2014 * Currently, the only defined flags are mutually exclusive
2015 */
2011 if (flags & MPOL_F_STATIC_NODES) 2016 if (flags & MPOL_F_STATIC_NODES)
2012 p += sprintf(p, "%sstatic", need_bar++ ? "|" : ""); 2017 p += snprintf(p, buffer + maxlen - p, "static");
2013 if (flags & MPOL_F_RELATIVE_NODES) 2018 else if (flags & MPOL_F_RELATIVE_NODES)
2014 p += sprintf(p, "%srelative", need_bar++ ? "|" : ""); 2019 p += snprintf(p, buffer + maxlen - p, "relative");
2015 } 2020 }
2016 2021
2017 if (!nodes_empty(nodes)) { 2022 if (!nodes_empty(nodes)) {