aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2008-10-22 16:43:58 +0100
committerAndy Whitcroft <apw@shadowen.org>2008-10-24 13:20:10 +0100
commitf127be900818d000bd5089995c1d3c0218291648 (patch)
tree31374ea248513045e289bd5eda837c2c04b15062
parent9b1efd2840b0cf26eb8b0a52b55ed4d80d9e0b07 (diff)
downloadlibhugetlbfs-f127be900818d000bd5089995c1d3c0218291648.tar.gz
privutils: expose the kernel default page size
We use the kernel default page size all over the place. We use it approximatly 6 times when setting the boundaries on a single pool. Currently every place looks this value up in /proc/meminfo which is very costly. As this value is essentially static per boot we can cache this value. Create a new routine kernel_default_hugepage_size() which looks this up and caches the result. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Acked-by: Eric B Munson <ebmunson@us.ibm.com> Acked-by: Mel Gorman <mel@csn.ul.ie>
-rw-r--r--hugeutils.c32
-rw-r--r--libhugetlbfs_privutils.h3
-rw-r--r--shm.c2
3 files changed, 24 insertions, 13 deletions
diff --git a/hugeutils.c b/hugeutils.c
index a3a677d..810bf13 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -55,10 +55,23 @@ static struct hpage_size hpage_sizes[MAX_HPAGE_SIZES];
static int nr_hpage_sizes;
static int hpage_sizes_default_idx = -1;
+static int default_size;
+
/********************************************************************/
/* Internal functions */
/********************************************************************/
+/*
+ * Lookup the kernel default page size.
+ */
+long kernel_default_hugepage_size()
+{
+ if (default_size == 0) {
+ default_size = file_read_ulong(MEMINFO, "Hugepagesize:");
+ default_size = size_to_smaller_unit(default_size); /* kB to B */ }
+ return default_size;
+}
+
#define BUF_SZ 256
#define MEMINFO_SIZE 2048
@@ -240,8 +253,7 @@ 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(MEMINFO, "Hugepagesize:");
- default_size = size_to_smaller_unit(default_size); /* kB to B */
+ default_size = kernel_default_hugepage_size();
if (default_size < 0) {
ERROR("Cannot determine the default page size\n");
return -1;
@@ -290,8 +302,7 @@ static void probe_default_hpage_size(void)
if (env && strlen(env) > 0)
size = parse_page_size(env);
else {
- size = file_read_ulong(MEMINFO, "Hugepagesize:");
- size *= 1024; /* convert from kB to B */
+ size = kernel_default_hugepage_size();
}
if (size >= 0) {
@@ -506,8 +517,7 @@ int hpool_sizes(struct hpage_pool *pools, int pcnt)
DIR *dir;
struct dirent *entry;
- default_size = size_to_smaller_unit(file_read_ulong(MEMINFO,
- "Hugepagesize:"));
+ default_size = kernel_default_hugepage_size();
if (default_size >= 0 && which < pcnt)
if (get_pool_size(default_size, &pools[which])) {
pools[which].is_default = 1;
@@ -543,8 +553,7 @@ int hpool_sizes(struct hpage_pool *pools, int pcnt)
*/
int kernel_has_hugepages(void)
{
- long default_size = file_read_ulong(MEMINFO, "Hugepagesize:");
- default_size = size_to_smaller_unit(default_size);
+ long default_size = kernel_default_hugepage_size();
if (default_size < 0)
return 0;
@@ -557,8 +566,7 @@ int kernel_has_hugepages(void)
*/
int kernel_has_overcommit(void)
{
- long default_size = file_read_ulong(MEMINFO, "Hugepagesize:");
- default_size = size_to_smaller_unit(default_size);
+ long default_size = kernel_default_hugepage_size();
if (default_size < 0)
return 0;
@@ -616,8 +624,8 @@ int gethugepagesizes(long pagesizes[], int n_elem)
errno = 0;
- /* Get the system default size from /proc/meminfo */
- default_size = read_meminfo("Hugepagesize:") * 1024;
+ /* Get the system default size. */
+ default_size = kernel_default_hugepage_size();
if (default_size < 0)
return 0;
diff --git a/libhugetlbfs_privutils.h b/libhugetlbfs_privutils.h
index 4e01aac..c31d526 100644
--- a/libhugetlbfs_privutils.h
+++ b/libhugetlbfs_privutils.h
@@ -61,6 +61,9 @@ int kernel_has_overcommit(void);
#define read_meminfo __pu_read_meminfo
long read_meminfo(const char *tag);
+#define kernel_default_hugepage_size __pu_kernel_default_hugepage_size
+long kernel_default_hugepage_size(void);
+
/* Kernel feature testing */
/* This enum defines the bits in a feature bitmask */
enum {
diff --git a/shm.c b/shm.c
index 8a56725..ac3b52a 100644
--- a/shm.c
+++ b/shm.c
@@ -60,7 +60,7 @@ int shmget(key_t key, size_t size, int shmflg)
* Use /proc/meminfo because shm always uses the system
* default huge page size.
*/
- long hpage_size = read_meminfo("Hugepagesize:") * 1024;
+ long hpage_size = kernel_default_hugepage_size();
aligned_size = ALIGN(size, hpage_size);
if (size != aligned_size) {
DEBUG("hugetlb_shmem: size growth align %zd -> %zd\n",