Esempio n. 1
0
static ino_t do_test(struct test_entry *te)
{
	int i;
	volatile int *p = te->data;

	if (te->writable) {
		for (i = 0; i < (te->size / sizeof(*p)); i++)
			p[i] = CONST ^ i;

		barrier();

		for (i = 0; i < (te->size / sizeof(*p)); i++) {
			if (p[i] != (CONST ^ i)) {
				verbose_printf("mismatch on %s", te->name);
				exit(RC_FAIL);
			}
		}
	} else if (te->execable) {
		int (*pf)(int) = te->data;

		if ((*pf)(CONST) != CONST) {
			verbose_printf("%s returns incorrect results", te->name);
			exit(RC_FAIL);
		}
	} else {
		/* Otherwise just read touch it */
		for (i = 0; i < (te->size / sizeof(*p)); i++)
			p[i];
	}

	te->is_huge = (test_addr_huge(te->data) == 1);

	return get_addr_inode(te->data);
}
Esempio n. 2
0
static int child_process(char *self, int index)
{
	int i;
	ino_t ino;

	get_link_string(self);

	shmid = shmget(SHM_KEY, NUM_CHILDREN * NUM_TESTS *
						sizeof(ino_t), 0666);
	if (shmid < 0) {
		verbose_printf("Child's shmget failed: %s", strerror(errno));
		exit(RC_FAIL);
	}

	shm = shmat(shmid, NULL, 0);
	if (shm == (void *)-1) {
		verbose_printf("Child's shmat failed: %s", strerror(errno));
		exit(RC_FAIL);
	}

	for (i = 0; i < NUM_TESTS; i++) {
		if (!test_addr_huge(testtab + i)) {
			/* don't care about non-huge addresses */
			shm[index * NUM_TESTS + i] = 0;
		} else {
			ino = do_test(testtab + i);
			if ((int)ino < 0) {
				shmdt(shm);
				exit(RC_FAIL);
			}
			shm[index * NUM_TESTS + i] = ino;
		}
	}
	shmdt(shm);
	return 0;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	long hpagesize;
	int freepages;
	long size1, size2;
	void *p1, *p2;
	int st, pid, rv;

	test_init(argc, argv);

	if (!getenv("HUGETLB_MORECORE"))
		CONFIG("Must have HUGETLB_MORECORE=yes");

	hpagesize = check_hugepagesize();

	freepages = read_meminfo("HugePages_Free:");
	if (freepages < 3)
		CONFIG("Must have at least 3 free hugepages");

	/*
	 * Allocation 1: one hugepage.  Due to malloc overhead, morecore
	 * will probably mmap two hugepages.
	 */
	size1 = hpagesize;
	p1 = malloc(size1);
	if (!p1)
		FAIL("Couldn't malloc %ld bytes", size1);
	if (!test_addr_huge(p1))
		FAIL("First allocation %p not on hugepages", p1);

	/*
	 * Allocation 2: all free hugepages to ensure we exhaust the free pool.
	 */
	size2 = freepages * hpagesize;
	p2 = malloc(size2);
	if (!p2)
		FAIL("Couldn't malloc %ld bytes", size2);
	st = test_addr_huge(p2);
	verbose_printf("Second allocation %p huge?  %s\n", p2, st < 0 ? "??" :
		       (st ? "yes" : "no"));

	/*
	 * Touch the pages in a child process.  Kernel sends a SIGKILL if
	 * we run out of hugepages.
	 */
	pid = fork();
	if (pid < 0)
		FAIL("fork: %s", strerror(errno));

	if (pid == 0) {
		memset(p1, 0, size1);
		memset(p2, 0, size2);
		exit(0);
	}

	rv = waitpid(pid, &st, 0);
	if (rv < 0)
		FAIL("waitpid: %s\n", strerror(errno));
	if (WIFSIGNALED(st))
		FAIL("Child killed by signal %d touching malloc'ed memory",
		     WTERMSIG(st));

	PASS();
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
	long hpage_size;
	int fd;
	void *p;
	unsigned long straddle_addr;

	test_init(argc, argv);

	hpage_size = check_hugepagesize();

	if (sizeof(void *) <= 4)
		TEST_BUG("64-bit only");

	if (hpage_size > FOURGB)
		CONFIG("Huge page size too large");

	fd = hugetlbfs_unlinked_fd();
	if (fd < 0)
		FAIL("hugetlbfs_unlinked_fd()");

	straddle_addr = FOURGB - hpage_size;

	/* We first try to get the mapping without MAP_FIXED */
	verbose_printf("Mapping without MAP_FIXED at %lx...", straddle_addr);
	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
		 MAP_SHARED, fd, 0);
	if (p == (void *)straddle_addr) {
		/* These tests irrelevant if we didn't get the
		 * straddle address */
		verbose_printf("done\n");

		if (test_addr_huge(p) != 1)
			FAIL("Mapped address is not hugepage");

		if (test_addr_huge(p + hpage_size) != 1)
			FAIL("Mapped address is not hugepage");

		verbose_printf("Clearing below 4GB...");
		memset(p, 0, hpage_size);
		verbose_printf("done\n");

		verbose_printf("Clearing above 4GB...");
		memset(p + hpage_size, 0, hpage_size);
		verbose_printf("done\n");
	} else {
		verbose_printf("got %p instead, never mind\n", p);
		munmap(p, 2*hpage_size);
	}

	verbose_printf("Mapping with MAP_FIXED at %lx...", straddle_addr);
	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
		 MAP_SHARED|MAP_FIXED, fd, 0);
	if (p == MAP_FAILED) {
		/* this area crosses last low slice and first high slice */
		unsigned long below_start = FOURGB - 256L*1024*1024;
		unsigned long above_end = 1024L*1024*1024*1024;
		if (range_is_mapped(below_start, above_end) == 1) {
			verbose_printf("region (4G-256M)-1T is not free\n");
			verbose_printf("mmap() failed: %s\n", strerror(errno));
			PASS_INCONCLUSIVE();
		} else
			FAIL("mmap() FIXED failed: %s\n", strerror(errno));
	}
	if (p != (void *)straddle_addr) {
		verbose_printf("got %p instead\n", p);
		FAIL("Wrong address with MAP_FIXED");
	}
	verbose_printf("done\n");

	if (test_addr_huge(p) != 1)
		FAIL("Mapped address is not hugepage");

	if (test_addr_huge(p + hpage_size) != 1)
		FAIL("Mapped address is not hugepage");

	verbose_printf("Clearing below 4GB...");
	memset(p, 0, hpage_size);
	verbose_printf("done\n");

	verbose_printf("Clearing above 4GB...");
	memset(p + hpage_size, 0, hpage_size);
	verbose_printf("done\n");

	verbose_printf("Tested above 4GB\n");

	PASS();
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	long hpage_size;
	int fd;
	void *p;
	unsigned long straddle_addr;

	test_init(argc, argv);

	hpage_size = check_hugepagesize();

	if (sizeof(void *) <= 4)
		TEST_BUG("64-bit only");

	if (hpage_size > FOURGB)
		CONFIG("Huge page size too large");

	fd = hugetlbfs_unlinked_fd();
	if (fd < 0)
		FAIL("hugetlbfs_unlinked_fd()");

	straddle_addr = FOURGB - hpage_size;

	/* We first try to get the mapping without MAP_FIXED */
	verbose_printf("Mapping without MAP_FIXED at %lx...", straddle_addr);
	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
		 MAP_SHARED, fd, 0);
	if (p == (void *)straddle_addr) {
		/* These tests irrelevant if we didn't get the
		 * straddle address */
		verbose_printf("done\n");

		if (test_addr_huge(p) != 1)
			FAIL("Mapped address is not hugepage");

		if (test_addr_huge(p + hpage_size) != 1)
			FAIL("Mapped address is not hugepage");

		verbose_printf("Clearing below 4GB...");
		memset(p, 0, hpage_size);
		verbose_printf("done\n");

		verbose_printf("Clearing above 4GB...");
		memset(p + hpage_size, 0, hpage_size);
		verbose_printf("done\n");
	} else {
		verbose_printf("got %p instead, never mind\n", p);
		munmap(p, 2*hpage_size);
	}

	verbose_printf("Mapping with MAP_FIXED at %lx...", straddle_addr);
	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
		 MAP_SHARED|MAP_FIXED, fd, 0);
	if (p == MAP_FAILED)
		FAIL("mmap() FIXED: %s", strerror(errno));
	if (p != (void *)straddle_addr) {
		verbose_printf("got %p instead\n", p);
		FAIL("Wrong address with MAP_FIXED");
	}
	verbose_printf("done\n");

	if (test_addr_huge(p) != 1)
		FAIL("Mapped address is not hugepage");

	if (test_addr_huge(p + hpage_size) != 1)
		FAIL("Mapped address is not hugepage");

	verbose_printf("Clearing below 4GB...");
	memset(p, 0, hpage_size);
	verbose_printf("done\n");

	verbose_printf("Clearing above 4GB...");
	memset(p + hpage_size, 0, hpage_size);
	verbose_printf("done\n");

	verbose_printf("Tested above 4GB\n");

	PASS();
}