When using --set-recommended-shmmax, it attempts to set the value based
on the maximum number of huge pages that can be allocated. In the event
the total number of huge pages exceeds the size of the virtual address
space, this counter can overflow and shmmax is set to a value that makes
no sense. This patch catches when this situation occurs and truncates the
recommended shmmax based on a unsigned long.

Tested on a 32-bit X86 machine.

Signed-off-by: Mel Gorman <m...@csn.ul.ie>
--- 
 hugeadm.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/hugeadm.c b/hugeadm.c
index 41ade02..467830b 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -709,10 +709,10 @@ void check_minfreekbytes(void)
        }
 }
 
-long recommended_shmmax(void)
+unsigned long long recommended_shmmax(void)
 {
        struct hpage_pool pools[MAX_POOLS];
-       long recommended_shmmax = 0;
+       unsigned long long recommended_shmmax = 0;
        int pos, cnt;
 
        cnt = hpool_sizes(pools, MAX_POOLS);
@@ -722,7 +722,8 @@ long recommended_shmmax(void)
        }
 
        for (pos = 0; cnt--; pos++)
-               recommended_shmmax += (pools[pos].maximum * 
pools[pos].pagesize);
+               recommended_shmmax += ((unsigned long long)pools[pos].maximum *
+                                                       pools[pos].pagesize);
 
        return recommended_shmmax;
 }
@@ -730,7 +731,8 @@ long recommended_shmmax(void)
 void set_recommended_shmmax(void)
 {
        int ret;
-       long recommended = recommended_shmmax();
+       unsigned long max_recommended = -1UL;
+       unsigned long long recommended = recommended_shmmax();
 
        if (recommended == 0) {
                printf("\n");
@@ -738,12 +740,15 @@ void set_recommended_shmmax(void)
                return;
        }
 
-       DEBUG("Setting shmmax to %ld\n", recommended);
+       if (recommended > max_recommended) 
+               recommended = max_recommended;
+
+       DEBUG("Setting shmmax to %llu\n", recommended);
        ret = file_write_ulong(PROCSHMMAX, (unsigned long)recommended);
 
        if (!ret) {
                INFO("To make shmmax settings persistent, add the following 
line to /etc/sysctl.conf:\n");
-               INFO("  kernel.shmmax = %ld\n", recommended);
+               INFO("  kernel.shmmax = %llu\n", recommended);
        }
 }
 

------------------------------------------------------------------------------
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