aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2017-04-12 10:02:23 +0800
committerFengguang Wu <fengguang.wu@intel.com>2017-04-12 10:02:23 +0800
commitc1bb226a1bfcebe1d116a1627575c4b0ebf4545a (patch)
tree9b914ded4c6ea2f62d9e3c85bbead9beb8fd6085
parentca3035658d99e8d5e044d4375f9d63bcc964762f (diff)
downloadvm-scalability-c1bb226a1bfcebe1d116a1627575c4b0ebf4545a.tar.gz
Fix free memory size
The original free memory size is incorrect, fixed via using unit size and last unit size. Signed-off-by: Huang Ying <ying.huang@intel.com>
-rw-r--r--usemem.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usemem.c b/usemem.c
index f0807bd..867624f 100644
--- a/usemem.c
+++ b/usemem.c
@@ -390,7 +390,8 @@ unsigned long * allocate(unsigned long bytes)
return p;
}
-void free_memory(void *ptrs[], unsigned int nptr, unsigned long bytes)
+void free_memory(void *ptrs[], unsigned int nptr,
+ unsigned long unit, unsigned long last_unit)
{
unsigned int i;
@@ -398,7 +399,7 @@ void free_memory(void *ptrs[], unsigned int nptr, unsigned long bytes)
if (opt_malloc)
free(ptrs[i]);
else
- munmap(ptrs[i], bytes);
+ munmap(ptrs[i], i == nptr - 1 ? last_unit : unit);
}
}
@@ -676,13 +677,14 @@ static void output_statistics(unsigned long unit_bytes)
write(1, buf, len);
}
-static void timing_free(void *ptrs[], unsigned int nptr, unsigned long bytes)
+static void timing_free(void *ptrs[], unsigned int nptr,
+ unsigned long unit, unsigned long last_unit)
{
struct timeval start, stop;
unsigned long delta_us;
gettimeofday(&start, NULL);
- free_memory(ptrs, nptr, bytes);
+ free_memory(ptrs, nptr, unit, last_unit);
gettimeofday(&stop, NULL);
delta_us = (stop.tv_sec - start.tv_sec) * 1000000 +
(stop.tv_usec - start.tv_usec);
@@ -696,6 +698,7 @@ long do_units(void)
struct drand48_data rand_data;
unsigned long unit_bytes = done_bytes;
unsigned long bytes = opt_bytes;
+ unsigned long last_unit;
void *ptrs[MAX_POINTERS];
unsigned int nptr = 0;
@@ -722,6 +725,7 @@ long do_units(void)
unit_bytes += do_unit(size, &rand_data,
nptr < MAX_POINTERS ? &ptrs[nptr] : NULL);
nptr++;
+ last_unit = size;
bytes -= size;
if (runtime_exceeded())
break;
@@ -757,7 +761,7 @@ long do_units(void)
}
if (!prealloc && nptr <= MAX_POINTERS)
- timing_free(ptrs, nptr, bytes);
+ timing_free(ptrs, nptr, unit, last_unit);
return 0;
}