To avoid confusion, the library should store page sizes in bytes and library
interfaces should take page size parameters in bytes as well.

Signed-off-by: Adam Litke <[EMAIL PROTECTED]>
Acked-by: David Gibson <[EMAIL PROTECTED]>
---

 hugeutils.c             |   26 ++++++++++----------------
 libhugetlbfs_internal.h |    2 +-
 tests/hugetests.h       |    4 ++--
 tests/testutils.c       |   20 ++++++++++----------
 4 files changed, 23 insertions(+), 29 deletions(-)


diff --git a/hugeutils.c b/hugeutils.c
index ce3391f..4572001 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -110,6 +110,7 @@ static long read_meminfo(const char *tag)
        return val;
 }
 
+/* Return the page size for the given mount point in bytes */
 static long hugetlbfs_test_pagesize(const char *mount)
 {
        struct statfs64 sb;
@@ -122,7 +123,7 @@ static long hugetlbfs_test_pagesize(const char *mount)
        if ((sb.f_bsize <= 0) || (sb.f_bsize > LONG_MAX))
                return -1;
 
-       return sb.f_bsize / 1024; /* Return in kB */
+       return sb.f_bsize;
 }
 
 static int hpage_size_to_index(unsigned long size)
@@ -130,7 +131,7 @@ static int hpage_size_to_index(unsigned long size)
        int i;
 
        for (i = 0; i < nr_hpage_sizes; i++)
-               if (hpage_sizes[i].pagesize_kb == size)
+               if (hpage_sizes[i].pagesize == size)
                        return i;
        return -1;
 }
@@ -147,6 +148,7 @@ static void probe_default_hpage_size(void)
        }
 
        size = read_meminfo("Hugepagesize:");
+       size *= 1024; /* convert from kB to B */
        if (size >= 0) {
                index = hpage_size_to_index(size);
                if (index >= 0)
@@ -190,7 +192,7 @@ static void add_hugetlbfs_mount(char *path, int user_mount)
                }
 
                idx = nr_hpage_sizes;
-               hpage_sizes[nr_hpage_sizes++].pagesize_kb = size;
+               hpage_sizes[nr_hpage_sizes++].pagesize = size;
        }
 
        if (strlen(hpage_sizes[idx].mount)) {
@@ -210,7 +212,7 @@ static void debug_show_page_sizes(void)
        DEBUG("Detected page sizes:\n");
        for (i = 0; i < nr_hpage_sizes; i++)
                DEBUG("   Size: %li kB %s  Mount: %s\n",
-                       hpage_sizes[i].pagesize_kb,
+                       hpage_sizes[i].pagesize / 1024,
                        i == hpage_sizes_default_idx ? "(default)" : "",
                        hpage_sizes[i].mount); 
 }
@@ -310,8 +312,7 @@ void __lh_setup_mounts(void)
  */
 long gethugepagesize(void)
 {
-       long hpage_kb;
-       long max_hpage_kb = LONG_MAX / 1024;
+       long hpage_size;
 
        /* Are huge pages available and have they been initialized? */
        if (hpage_sizes_default_idx == -1) {
@@ -319,16 +320,9 @@ long gethugepagesize(void)
                return -1;
        }
 
-       hpage_kb = hpage_sizes[hpage_sizes_default_idx].pagesize_kb;
-       if (hpage_kb > max_hpage_kb) {
-               /* would overflow if converted to bytes */
-               errno = hugepagesize_errno = EOVERFLOW;
-               return -1;
-       } else {
-               errno = 0;
-               /* convert from kb to bytes */
-               return (1024 * hpage_kb);
-       }
+       errno = 0;
+       hpage_size = hpage_sizes[hpage_sizes_default_idx].pagesize;
+       return hpage_size;
 }
 
 int hugetlbfs_test_path(const char *mount)
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index cf5f4fa..005aa21 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -81,7 +81,7 @@ extern int __lh_hugetlbfs_prefault(int fd, void *addr, size_t 
length);
 
 /* Multiple huge page size support */
 struct hpage_size {
-       unsigned long pagesize_kb;
+       unsigned long pagesize;
        char mount[PATH_MAX+1];
 };
 
diff --git a/tests/hugetests.h b/tests/hugetests.h
index 0afc00d..71a1e21 100644
--- a/tests/hugetests.h
+++ b/tests/hugetests.h
@@ -141,9 +141,9 @@ struct hugetlb_pool_counter_info_t {
        char *sysfs_file;
 };
 extern struct hugetlb_pool_counter_info_t hugetlb_counter_info[];
-long get_pool_counter(unsigned int counter, unsigned long pagesize_kb);
+long get_pool_counter(unsigned int counter, unsigned long pagesize);
 int set_pool_counter(unsigned int counter, unsigned long val,
-                               unsigned long pagesize_kb);
+                               unsigned long pagesize);
 
 int using_system_hpage_size(const char *mount);
 
diff --git a/tests/testutils.c b/tests/testutils.c
index 76ce860..172ce61 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -289,7 +289,7 @@ int file_write_ulong(char *file, unsigned long val)
        return ret > 0 ? 0 : -1;
 }
 
-int select_pool_counter(unsigned int counter, unsigned long pagesize_kb,
+int select_pool_counter(unsigned int counter, unsigned long pagesize,
                                char *filename, char **key)
 {
        long default_size;
@@ -318,12 +318,12 @@ int select_pool_counter(unsigned int counter, unsigned 
long pagesize_kb,
                return -1;
        }
 
-       /* Convert a pagesize_kb of 0 to the libhugetlbfs default size */
-       if (pagesize_kb == 0)
-               pagesize_kb = gethugepagesize() / 1024;
+       /* Convert a pagesize of 0 to the libhugetlbfs default size */
+       if (pagesize == 0)
+               pagesize = gethugepagesize();
 
        /* If the user is dealing in the default page size, we can use /proc */
-       if (pagesize_kb == default_size) {
+       if (pagesize == default_size) {
                if (meminfo_key && key) {
                        strcpy(filename, "/proc/meminfo");
                        *key = meminfo_key;
@@ -331,27 +331,27 @@ int select_pool_counter(unsigned int counter, unsigned 
long pagesize_kb,
                        sprintf(filename, "/proc/sys/vm/%s", sysfs_file);
        } else /* Use the sysfs interface */
                sprintf(filename, "/sys/kernel/mm/hugepages/hugepages-%lukB/%s",
-                       pagesize_kb, sysfs_file);
+                       pagesize / 1024, sysfs_file);
        return 0;
 }
 
-long get_pool_counter(unsigned int counter, unsigned long pagesize_kb)
+long get_pool_counter(unsigned int counter, unsigned long pagesize)
 {
        char file[PATH_MAX+1];
        char *key;
 
-       if (select_pool_counter(counter, pagesize_kb, file, &key))
+       if (select_pool_counter(counter, pagesize, file, &key))
                return -1;
 
        return file_read_ulong(file, key);
 }
 
 int set_pool_counter(unsigned int counter, unsigned long val,
-                       unsigned long pagesize_kb)
+                       unsigned long pagesize)
 {
        char file[PATH_MAX+1];
 
-       if (select_pool_counter(counter, pagesize_kb, file, NULL))
+       if (select_pool_counter(counter, pagesize, file, NULL))
                return -1;
 
        return file_write_ulong(file, val);


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