aboutsummaryrefslogtreecommitdiff
path: root/hugeadm.c
diff options
context:
space:
mode:
authorMel Gorman <mel@csn.ul.ie>2009-10-29 17:22:15 +0000
committerEric B Munson <ebmunson@us.ibm.com>2009-10-30 15:25:07 +0000
commitc77742d80f4a17be14046239c763b52298663c57 (patch)
treefc9e04fa7603ddad2f16d13859d0294a1deb0a84 /hugeadm.c
parent66c797cc2ba17dcc98f3dbce1a9b2e320564a0c6 (diff)
downloadlibhugetlbfs-c77742d80f4a17be14046239c763b52298663c57.tar.gz
hugeadm: Handle overflows when setting shmmax
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 <mel@csn.ul.ie> Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
Diffstat (limited to 'hugeadm.c')
-rw-r--r--hugeadm.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/hugeadm.c b/hugeadm.c
index 41ade02..4eca64d 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);
}
}