diff options
author | Fengguang Wu <fengguang.wu@intel.com> | 2012-11-27 20:21:57 +0800 |
---|---|---|
committer | Fengguang Wu <fengguang.wu@intel.com> | 2012-11-27 20:29:05 +0800 |
commit | b51e80afc43a5404c4081dae61eff720b76849c2 (patch) | |
tree | 3439b2e5bc420929c7b5f5a4b85c16a41f515620 | |
parent | 2719c27843988956fec8240d23572f371bf3bee2 (diff) | |
download | vm-scalability-b51e80afc43a5404c4081dae61eff720b76849c2.tar.gz |
Abhinav's work on usemem_mincore.c
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
-rw-r--r-- | usemem_mincore.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/usemem_mincore.c b/usemem_mincore.c new file mode 100644 index 0000000..9e06d61 --- /dev/null +++ b/usemem_mincore.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/mman.h> + +#define HUGEPAGE_SIZE (2UL * 1024 * 1024) /* Assuming 2MB hugepage size */ + +unsigned char *mincore_hugepages(unsigned char *addr, unsigned long bytes) +{ + /* hugepage size assumed to be 2MB and */ + unsigned long length_of_vector = (bytes / HUGEPAGE_SIZE) + 1; + unsigned char *ptr = NULL; /* initialize to NULL */ + + /* allocate 'length_of_vector' bytes for mincore page information */ + if ((ptr = (unsigned char *)malloc(length_of_vector)) == NULL) { + fprintf(stderr, "Unable to allocate requested memory"); + fprintf(stdout, "exiting now..."); + exit(1); + } + + if ((mincore(addr, bytes, ptr)) == -1) { + fprintf(stderr, "mincore failed with error: %s", strerror(errno)); + free(ptr); + exit(1); + } + + return ptr; +} + |