From: Adam Litke <[EMAIL PROTECTED]> As originally written, the functions hugetlbfs_find_path_for_size() and hugetlbfs_unlinked_fd_for_size() accepted 0 as a valid page size. A page size of zero was interpreted to mean the default size (as defined by libhugetlbfs, not the kernel).
This behavior is undesirable in pagesize-specific functions for two reasons. First, the libhugetlbfs default size can be nebulous since it depends on what page sizes are available, which sizes have appropriate mount points, and the value of an environment variable. This amount of variability adds uncertainty to what should be an explicit API. Second, the functions hugetlbfs_find_path() and hugetlbfs_unlinked_fd() already exist as a means to delegate page size selection to the library. It is my view that all functions that take a page size paramater shall expect a valid page size. Signed-off-by: Adam Litke <[EMAIL PROTECTED]> Acked-by: Mel Gorman <[EMAIL PROTECTED]> Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]> --- hugeutils.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hugeutils.c b/hugeutils.c index 22ea487..ae97902 100644 --- a/hugeutils.c +++ b/hugeutils.c @@ -248,10 +248,6 @@ int select_pool_counter(unsigned int counter, unsigned long pagesize, return -1; } - /* Convert a pagesize of 0 to the libhugetlbfs default size */ - if (pagesize == 0) - pagesize = default_size; - /* If the user is dealing in the default page size, we can use /proc */ if (pagesize == default_size) { if (meminfo_key && key) { @@ -522,11 +518,7 @@ const char *hugetlbfs_find_path_for_size(long page_size) char *path; int idx; - if (page_size == 0) - idx = hpage_sizes_default_idx; - else - idx = hpage_size_to_index(page_size); - + idx = hpage_size_to_index(page_size); if (idx >= 0) { path = hpage_sizes[idx].mount; if (strlen(path)) @@ -537,7 +529,11 @@ const char *hugetlbfs_find_path_for_size(long page_size) const char *hugetlbfs_find_path(void) { - return hugetlbfs_find_path_for_size(0); + long hpage_size = gethugepagesize(); + if (hpage_size > 0) + return hugetlbfs_find_path_for_size(hpage_size); + else + return NULL; } int hugetlbfs_unlinked_fd_for_size(long page_size) @@ -570,7 +566,11 @@ int hugetlbfs_unlinked_fd_for_size(long page_size) int hugetlbfs_unlinked_fd(void) { - return hugetlbfs_unlinked_fd_for_size(0); + long hpage_size = gethugepagesize(); + if (hpage_size > 0) + return hugetlbfs_unlinked_fd_for_size(hpage_size); + else + return -1; } #define IOV_LEN 64 -- 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