parent
36db457bf7
commit
a78d53518f
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
|
#define SIZE 19*1024*1024
|
||||||
|
#define PAGE_SIZE 4096 // 4KB
|
||||||
|
#define CHUNK_SIZE 8 * 1024 // 8KB
|
||||||
|
|
||||||
|
unsigned long long tv_to_ms(struct timeval tv)
|
||||||
|
{
|
||||||
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *c;
|
||||||
|
unsigned long *p;
|
||||||
|
struct timeval tv_b, tv_e;;
|
||||||
|
|
||||||
|
p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
if (!p) {
|
||||||
|
perror("fail to get memory");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
c = (unsigned char *)p;
|
||||||
|
|
||||||
|
/* fill data */
|
||||||
|
for (i = 0; i < SIZE / 8; i += 8)
|
||||||
|
*(p + i) = i;
|
||||||
|
|
||||||
|
/* trigger pageout and get time of pageout */
|
||||||
|
gettimeofday(&tv_b, NULL);
|
||||||
|
madvise(p, SIZE, MADV_PAGEOUT);
|
||||||
|
gettimeofday(&tv_e, NULL);
|
||||||
|
|
||||||
|
printf("swp out bandwidth: %ld bytes/ms\n",
|
||||||
|
SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b)));
|
||||||
|
|
||||||
|
/* read to trigger swapin and */
|
||||||
|
gettimeofday(&tv_b, NULL);
|
||||||
|
for (i = 0; i < SIZE; i += PAGE_SIZE)
|
||||||
|
*(c + i) = i;
|
||||||
|
gettimeofday(&tv_e, NULL);
|
||||||
|
|
||||||
|
printf("swp in bandwidth: %ld bytes/ms\n",
|
||||||
|
SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue