[CRIU] Re: [PATCH] zdtm: maps02 -- Make sure HugeTLB is present

Cyrill Gorcunov gorcunov at openvz.org
Fri Oct 26 04:54:31 EDT 2012


On Fri, Oct 26, 2012 at 12:52:04PM +0400, Cyrill Gorcunov wrote:
> Reported-by: Pavel Emelyanov <xemul at parallels.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Updated
-------------- next part --------------
>From 5654ff9f74eb60f2b4c6b878f9432c924badb74c Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 26 Oct 2012 12:51:40 +0400
Subject: [PATCH] zdtm: maps02 -- Make sure HugeTLB is present

Reported-by: Pavel Emelyanov <xemul at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/live/static/maps02.c |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/test/zdtm/live/static/maps02.c b/test/zdtm/live/static/maps02.c
index 5394a71..1cb1c46 100644
--- a/test/zdtm/live/static/maps02.c
+++ b/test/zdtm/live/static/maps02.c
@@ -116,6 +116,9 @@ static int get_smaps_bits(unsigned long where, unsigned long *flags, unsigned lo
 	FILE *smaps = NULL;
 	char buf[1024];
 
+	if (!where)
+		return 0;
+
 	smaps = fopen("/proc/self/smaps", "r");
 	if (!smaps) {
 		err("Can't open smaps: %m");
@@ -141,6 +144,31 @@ static int get_smaps_bits(unsigned long where, unsigned long *flags, unsigned lo
 	return 0;
 }
 
+static int has_hugetlb(void)
+{
+	FILE *meminfo = NULL;
+	char buf[1024];
+	int ret = -1;
+
+	meminfo = fopen("/proc/meminfo", "r");
+	if (!meminfo) {
+		err("Can't open meminfo: %m");
+		return 0;
+	}
+
+	while (fgets(buf, sizeof(buf), meminfo)) {
+		if (!strncmp(buf, "HugePages_Total:", 16)) {
+			unsigned long size = 0;
+			sscanf(&buf[16], "%lu", &size);
+			ret = size > 0 ? 1 : 0;
+			break;
+		}
+	}
+
+	fclose(meminfo);
+	return ret;
+}
+
 #define MEM_SIZE (8192)
 
 static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv)
@@ -179,9 +207,11 @@ int main(int argc, char **argv)
 	if (alloc_anon_mmap(&m[2], MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, MADV_DONTDUMP))
 		return -1;
 
-	test_msg("Alloc hugetlb/hugepage\n");
-	if (alloc_anon_mmap(&m[3], MAP_PRIVATE | MAP_ANONYMOUS, MADV_HUGEPAGE))
-		return -1;
+	if (has_hugetlb()) {
+		test_msg("Alloc hugetlb/hugepage\n");
+		if (alloc_anon_mmap(&m[3], MAP_PRIVATE | MAP_ANONYMOUS, MADV_HUGEPAGE))
+			return -1;
+	}
 
 	test_msg("Alloc dontfork/random|mergeable\n");
 	if (alloc_anon_mmap(&m[4], MAP_PRIVATE | MAP_ANONYMOUS, MADV_MERGEABLE))
-- 
1.7.7.6



More information about the CRIU mailing list