When multiple huge page sizes are available, libhugetlbfs behavior is to use the huge page size reported in /proc/meminfo as the default size. Allow other sizes to be used as the default via a new environment variable: HUGETLB_DEFAULT_PAGE_SIZE. If this variable is specified, libhugetlbfs will attempt to find a mounted filesystem of this size and use it as the default. If this is unsuccessful, the first size that was found is used.
Signed-off-by: Adam Litke <[EMAIL PROTECTED]> --- hugeutils.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hugeutils.c b/hugeutils.c index 4572001..8a40640 100644 --- a/hugeutils.c +++ b/hugeutils.c @@ -61,6 +61,33 @@ static int hpage_sizes_default_idx = -1; #define BUF_SZ 256 #define MEMINFO_SIZE 2048 +static long parse_page_size(const char *str) +{ + char *pos; + unsigned long size; + + size = strtoul(str, &pos, 0); + if (str == pos) + return -1; + /* Catch strtoul errors and sizes that overflow the native word size */ + if (size > LONG_MAX) + return -1; + + switch (*pos) { + case 'G': + case 'g': + size *= 1024; + case 'M': + case 'm': + size *= 1024; + case 'K': + case 'k': + size *= 1024; + } + + return size; +} + static long read_meminfo(const char *tag) { int fd; @@ -138,6 +165,7 @@ static int hpage_size_to_index(unsigned long size) static void probe_default_hpage_size(void) { + char *env; long size; int index; @@ -147,8 +175,18 @@ static void probe_default_hpage_size(void) return; } - size = read_meminfo("Hugepagesize:"); - size *= 1024; /* convert from kB to B */ + /* + * Check if the user specified a default size, otherwise use the + * system default size as reported by /proc/meminfo. + */ + env = getenv("HUGETLB_DEFAULT_PAGE_SIZE"); + if (env && strlen(env) > 0) + size = parse_page_size(env); + else { + size = read_meminfo("Hugepagesize:"); + size *= 1024; /* convert from kB to B */ + } + if (size >= 0) { index = hpage_size_to_index(size); if (index >= 0) ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel