aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2008-10-21 17:02:42 +0100
committerAndy Whitcroft <apw@shadowen.org>2008-10-24 13:19:26 +0100
commitea45ea0c9067bda5f31ea489a0895ef99dd9d051 (patch)
tree8dbe41971693507fca106fcf92fd75c4cdfe87cd
parentdcfd32353a7af7bfd695ddefa18e5a55833d7af8 (diff)
downloadlibhugetlbfs-ea45ea0c9067bda5f31ea489a0895ef99dd9d051.tar.gz
hugeadm: cleanup pool size adjustment for kernels without overcommit
In older kernels we have no overcommit support. This means that there can never be a minimum/maximum spread. Also it means we do not have overcommit counters on read. Basically we make --pool-pages-max error indicating that there is no overcommit support. When we attempt to change the minimum where there is no overcommit support we simply always update the maximum to match. 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--hugeadm.c16
-rw-r--r--hugeutils.c30
-rw-r--r--libhugetlbfs_privutils.h3
3 files changed, 47 insertions, 2 deletions
diff --git a/hugeadm.c b/hugeadm.c
index 9c7ae1c..036d603 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -108,6 +108,7 @@ void pool_list(void)
enum {
POOL_MIN,
POOL_MAX,
+ POOL_BOTH,
};
static long value_adjust(char *adjust_str, long base)
@@ -184,7 +185,10 @@ void pool_adjust(char *cmd, unsigned int counter)
min = pools[pos].minimum;
max = pools[pos].maximum;
- if (counter == POOL_MIN) {
+ if (counter == POOL_BOTH) {
+ min = value_adjust(adjust_str, min);
+ max = min;
+ } else if (counter == POOL_MIN) {
min = value_adjust(adjust_str, min);
if (min > max)
max = min;
@@ -284,10 +288,18 @@ int main(int argc, char** argv)
break;
case LONG_POOL_MIN_ADJ:
- pool_adjust(optarg, POOL_MIN);
+ if (! kernel_has_overcommit())
+ pool_adjust(optarg, POOL_BOTH);
+ else
+ pool_adjust(optarg, POOL_MIN);
break;
case LONG_POOL_MAX_ADJ:
+ if (! kernel_has_overcommit()) {
+ ERROR("kernel does not support overcommit, "
+ "max cannot be adjusted\n");
+ exit(EXIT_FAILURE);
+ }
pool_adjust(optarg, POOL_MAX);
break;
diff --git a/hugeutils.c b/hugeutils.c
index abcf29f..36a91c0 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -456,8 +456,14 @@ int get_pool_size(long size, struct hpage_pool *pool)
/*
* Pick up those values which are basically stable with respect to
* the admin; ie. only changed by them.
+ *
+ * nr_over may be negative if this kernel does not support overcommit
+ * in that case we will consider it always 0 and max will track min
+ * always.
*/
nr_over = get_huge_page_counter(size, HUGEPAGES_OC);
+ if (nr_over < 0)
+ nr_over = 0;
/* Sample the volatile values until they are stable. */
while (nr_used != it_used || nr_surp != it_surp || nr_resv != it_resv) {
@@ -469,6 +475,10 @@ int get_pool_size(long size, struct hpage_pool *pool)
it_surp = get_huge_page_counter(size, HUGEPAGES_SURP);
it_resv = get_huge_page_counter(size, HUGEPAGES_RSVD);
}
+ if (nr_surp < 0)
+ nr_surp = 0;
+ if (nr_resv < 0)
+ nr_resv = 0;
nr_static = nr_used - nr_surp;
@@ -528,6 +538,23 @@ int hpool_sizes(struct hpage_pool *pools, int pcnt)
return (which < pcnt) ? which : -1;
}
+/*
+ * If we can find the default page size, and if we can find an overcommit
+ * control for it then the kernel must support overcommit.
+ */
+int kernel_has_overcommit(void)
+{
+ long default_size = file_read_ulong(MEMINFO, "Hugepagesize:");
+ default_size = size_to_smaller_unit(default_size);
+ if (default_size < 0)
+ return 0;
+
+ if (get_huge_page_counter(default_size, HUGEPAGES_OC) < 0)
+ return 0;
+
+ return 1;
+}
+
/********************************************************************/
/* Library user visible functions */
/********************************************************************/
@@ -793,6 +820,9 @@ long get_huge_page_counter(long pagesize, unsigned int counter)
if (select_pool_counter(counter, pagesize, file, &key))
return -1;
+ if (access(file, O_RDONLY))
+ return -1;
+
return file_read_ulong(file, key);
}
diff --git a/libhugetlbfs_privutils.h b/libhugetlbfs_privutils.h
index 008955e..e11583b 100644
--- a/libhugetlbfs_privutils.h
+++ b/libhugetlbfs_privutils.h
@@ -52,6 +52,9 @@ int set_nr_hugepages(long pagesize, unsigned long val);
#define set_nr_overcommit_hugepages __pu_set_nr_overcommit_hugepages
int set_nr_overcommit_hugepages(long pagesize, unsigned long val);
+#define kernel_has_overcommit __pu_kernel_has_overcommit
+int kernel_has_overcommit(void);
+
#define read_meminfo __pu_read_meminfo
long read_meminfo(const char *tag);