When specifying the amount of memory to allocate as huge pages with
--pool-pages-max, it is possible to overflow the huge page count on 32 bit
systems with large amounts of memory. For example, specifying --pool-pages-max
DEFAULT:8G will overflow long and set the wrong value.

This patch converts size_to_smaller_units() to unsigned long long to manage
the overflow.  The existing callers of size_to_smaller_units() should be
all right as they are always talking about the context of a huge page size
which is never going to overflow the long type.

Tested on 32-bit X86.

Signed-off-by: Mel Gorman <m...@csn.ul.ie>
--- 
 hugeadm.c               |    2 +-
 hugeutils.c             |    8 ++++----
 libhugetlbfs_internal.h |    2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hugeadm.c b/hugeadm.c
index 6cb0c78..41ade02 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -1004,7 +1004,7 @@ enum {
 
 static long value_adjust(char *adjust_str, long base, long page_size)
 {
-       long adjust;
+       unsigned long long adjust;
        char *iter;
 
        /* Convert and validate the adjust. */
diff --git a/hugeutils.c b/hugeutils.c
index d6f8940..bfa4512 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -84,12 +84,12 @@ void kernel_default_hugepage_size_reset(void)
 /*
  * Convert a quantity in a given unit to the next smallest unit by
  * multiplying the quantity by 1024 (eg. convert 1MB to 1024kB).
- * If the conversion would overflow the variable, return LONG_MAX to signify
- * the error.
+ * If the conversion would overflow the variable, return ULONGLONG_MAX to
+ * signify the error.
  */
-long size_to_smaller_unit(long size)
+unsigned long long size_to_smaller_unit(unsigned long long size)
 {
-       if (size < 0 || size * 1024 < size)
+       if (size * 1024 < size)
                return -1;
        else
                return size * 1024;
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index 05c22e0..da32f84 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -163,7 +163,7 @@ struct hpage_pool {
 };
 
 #define size_to_smaller_unit __lh_size_to_smaller_unit
-extern long size_to_smaller_unit(long size);
+extern unsigned long long size_to_smaller_unit(unsigned long long size);
 
 #define file_read_ulong __lh_file_read_ulong
 extern long file_read_ulong(char *file, const char *tag);

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to