The default page size is returned in KB but we compare it directly
to the requested page size which is in bytes.  This will lead us to
use the sysfs interface when we should be using the proc/meminfo ones
for the default page size.  This will break backwards compatibility.

As the default page size in bytes may be larger than a long (for example
when 16GB pages are the default) therefore when determinining whether
the pagesize we are probing is the default we need to be wary of errors
when converting the default.  As the default page size is in KB already
it makes sense to convert the user page size and do the comparison in KB
as that is always safe.

Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
---
 hugeutils.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hugeutils.c b/hugeutils.c
index 3c30b41..e32f049 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -211,7 +211,7 @@ static int file_write_ulong(char *file, unsigned long val)
 static int select_pool_counter(unsigned int counter, unsigned long pagesize,
                                char *filename, char **key)
 {
-       long default_size;
+       long default_size_kb;
        char *meminfo_key;
        char *sysfs_file;
 
@@ -231,14 +231,14 @@ static int select_pool_counter(unsigned int counter, 
unsigned long pagesize,
         * between libhugetlbfs and the test suite.  For now we will just
         * read /proc/meminfo. 
         */
-       default_size = file_read_ulong("/proc/meminfo", "Hugepagesize:");
-       if (default_size < 0) {
+       default_size_kb = file_read_ulong("/proc/meminfo", "Hugepagesize:");
+       if (default_size_kb < 0) {
                ERROR("Cannot determine the default page size\n");
                return -1;
        }
 
        /* If the user is dealing in the default page size, we can use /proc */
-       if (pagesize == default_size) {
+       if (pagesize / 1024 == default_size_kb) {
                if (meminfo_key && key) {
                        strcpy(filename, "/proc/meminfo");
                        *key = meminfo_key;
-- 
1.6.0.1.451.gc8d31


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

Reply via email to