Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
	const int test_value = 123456;
	char *dir = NULL;
	int count = DEFAULT_COUNT;
	int n = DEFAULT_N;
	VMEM *vmp;
	int opt;
	int i, j;
	int use_calloc = 0;

	START(argc, argv, "vmem_pages_purging");

	while ((opt = getopt(argc, argv, "z")) != -1) {
		switch (opt) {
		case 'z':
			use_calloc = 1;
			break;
		default:
			usage(argv[0]);
		}
	}

	if (optind < argc) {
		dir = argv[optind];
	} else {
		usage(argv[0]);
	}

	vmp = vmem_create(dir, VMEM_MIN_POOL);
	if (vmp == NULL)
		FATAL("!vmem_create");

	for (i = 0; i < n; i++) {
		int *test = NULL;
		if (use_calloc)
			test = vmem_calloc(vmp, 1, count * sizeof (int));
		else
			test = vmem_malloc(vmp, count * sizeof (int));
		ASSERTne(test, NULL);

		if (use_calloc) {
			/* vmem_calloc should return zeroed memory */
			for (j = 0; j < count; j++)
				ASSERTeq(test[j], 0);
		}
		for (j = 0; j < count; j++)
			test[j] = test_value;
		for (j = 0; j < count; j++)
			ASSERTeq(test[j], test_value);

		vmem_free(vmp, test);
	}

	vmem_delete(vmp);

	DONE(NULL);
}
Ejemplo n.º 2
0
int
main(int argc, char *argv[])
{
	const int test_value = 123456;
	char *dir = NULL;
	void *mem_pool = NULL;
	VMEM *vmp;

	START(argc, argv, "vmem_calloc");

	if (argc == 2) {
		dir = argv[1];
	} else if (argc > 2) {
		UT_FATAL("usage: %s [directory]", argv[0]);
	}

	if (dir == NULL) {
		/* allocate memory for function vmem_create_in_region() */
		mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);

		vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
		if (vmp == NULL)
			UT_FATAL("!vmem_create_in_region");
	} else {
		vmp = vmem_create(dir, VMEM_MIN_POOL);
		if (vmp == NULL)
			UT_FATAL("!vmem_create");
	}

	int *test = vmem_calloc(vmp, 1, sizeof(int));
	UT_ASSERTne(test, NULL);

	/* pool_calloc should return zeroed memory */
	UT_ASSERTeq(*test, 0);

	*test = test_value;
	UT_ASSERTeq(*test, test_value);

	/* check that pointer came from mem_pool */
	if (dir == NULL) {
		UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
	}

	vmem_free(vmp, test);

	vmem_delete(vmp);

	DONE(NULL);
}
static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;

/******************************************************************************
 ** JNI implementations
 *****************************************************************************/

JNIEXPORT
jlong JNICALL Java_com_intel_bigdatamem_BigDataMemAllocator_nallocate(
             JNIEnv* env,
             jobject this, jlong id,
             jlong size, jboolean initzero)
{
	pthread_rwlock_rdlock(&g_vmem_rwlock);
	pthread_mutex_lock(g_vmem_mutex_ptr + id);
    void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
    pthread_mutex_unlock(g_vmem_mutex_ptr + id);
    pthread_rwlock_unlock(&g_vmem_rwlock);
    return addr_to_java(nativebuf);
}

JNIEXPORT
jlong JNICALL Java_com_intel_bigdatamem_BigDataMemAllocator_nreallocate(
             JNIEnv* env,
             jobject this, jlong id,
             jlong address,
             jlong size, jboolean initzero)
{
	pthread_rwlock_rdlock(&g_vmem_rwlock);
	pthread_mutex_lock(g_vmem_mutex_ptr + id);
Ejemplo n.º 4
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "vmem_delete");

	VMEM *vmp;
	void *ptr;

	if (argc < 2)
		FATAL("usage: %s op:h|f|m|c|r|a|s|d", argv[0]);

	/* allocate memory for function vmem_create_in_region() */
	void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);

	vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
	if (vmp == NULL)
		FATAL("!vmem_create_in_region");

	ptr = vmem_malloc(vmp, sizeof (long long int));
	if (ptr == NULL)
		ERR("!vmem_malloc");
	vmem_delete(vmp);

	/* arrange to catch SEGV */
	struct sigaction v;
	sigemptyset(&v.sa_mask);
	v.sa_flags = 0;
	v.sa_handler = signal_handler;
	SIGACTION(SIGSEGV, &v, NULL);
	SIGACTION(SIGABRT, &v, NULL);
	SIGACTION(SIGILL, &v, NULL);

	/* go through all arguments one by one */
	for (int arg = 1; arg < argc; arg++) {
		/* Scan the character of each argument. */
		if (strchr("hfmcrasd", argv[arg][0]) == NULL ||
				argv[arg][1] != '\0')
			FATAL("op must be one of: h, f, m, c, r, a, s, d");

		switch (argv[arg][0]) {
		case 'h':
			OUT("Testing vmem_check...");
			if (!sigsetjmp(Jmp, 1)) {
				OUT("\tvmem_check returned %i",
							vmem_check(vmp));
			}
			break;

		case 'f':
			OUT("Testing vmem_free...");
			if (!sigsetjmp(Jmp, 1)) {
				vmem_free(vmp, ptr);
				OUT("\tvmem_free succeeded");
			}
			break;

		case 'm':
			OUT("Testing vmem_malloc...");
			if (!sigsetjmp(Jmp, 1)) {
				ptr = vmem_malloc(vmp, sizeof (long long int));
				if (ptr != NULL)
					OUT("\tvmem_malloc succeeded");
				else
					OUT("\tvmem_malloc returned NULL");
			}
			break;

		case 'c':
			OUT("Testing vmem_calloc...");
			if (!sigsetjmp(Jmp, 1)) {
				ptr = vmem_calloc(vmp, 10, sizeof (int));
				if (ptr != NULL)
					OUT("\tvmem_calloc succeeded");
				else
					OUT("\tvmem_calloc returned NULL");
			}
			break;

		case 'r':
			OUT("Testing vmem_realloc...");
			if (!sigsetjmp(Jmp, 1)) {
				ptr = vmem_realloc(vmp, ptr, 128);
				if (ptr != NULL)
					OUT("\tvmem_realloc succeeded");
				else
					OUT("\tvmem_realloc returned NULL");
			}
			break;

		case 'a':
			OUT("Testing vmem_aligned_alloc...");
			if (!sigsetjmp(Jmp, 1)) {
				ptr = vmem_aligned_alloc(vmp, 128, 128);
				if (ptr != NULL)
					OUT("\tvmem_aligned_alloc succeeded");
				else
					OUT("\tvmem_aligned_alloc"
							" returned NULL");
			}
			break;

		case 's':
			OUT("Testing vmem_strdup...");
			if (!sigsetjmp(Jmp, 1)) {
				ptr = vmem_strdup(vmp, "Test string");
				if (ptr != NULL)
					OUT("\tvmem_strdup succeeded");
				else
					OUT("\tvmem_strdup returned NULL");
			}
			break;

		case 'd':
			OUT("Testing vmem_delete...");
			if (!sigsetjmp(Jmp, 1)) {
				vmem_delete(vmp);
				if (errno != 0)
					OUT("\tvmem_delete failed: %s",
						vmem_errormsg());
				else
					OUT("\tvmem_delete succeeded");
			}
			break;
		}
	}

	DONE(NULL);
}