2024-10-21 23:35:32 +08:00
|
|
|
#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>
|
|
|
|
|
|
|
|
|
|
unsigned long long tv_to_ms(struct timeval tv)
|
|
|
|
|
{
|
|
|
|
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2024-11-18 21:33:03 +08:00
|
|
|
char c;
|
|
|
|
|
pid_t pid;
|
|
|
|
|
int i;
|
|
|
|
|
int j = 0;
|
2024-10-21 23:35:32 +08:00
|
|
|
struct timeval tv_b, tv_e;;
|
2024-11-18 21:33:03 +08:00
|
|
|
#define SIZE 100*1024*1024
|
|
|
|
|
unsigned long *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
|
2024-10-21 23:35:32 +08:00
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
|
|
|
if (!p) {
|
|
|
|
|
perror("fail to get memory");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
madvise(p, SIZE, MADV_HUGEPAGE);
|
|
|
|
|
|
2024-11-18 21:33:03 +08:00
|
|
|
for (j = 0; j < SIZE / 8; j+=128)
|
|
|
|
|
*(p + j) = j;
|
2024-10-21 23:35:32 +08:00
|
|
|
|
2024-11-18 21:33:03 +08:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv_b, NULL);
|
|
|
|
|
for (j = 0; j < SIZE / 8; j+=128)
|
|
|
|
|
*(p + j) = j;
|
|
|
|
|
gettimeofday(&tv_e, NULL);
|
|
|
|
|
printf("swp in bandwidth: %ld bytes/ms\n",
|
|
|
|
|
SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//madvise(p, SIZE, MADV_PAGEOUT);
|
|
|
|
|
|
|
|
|
|
//while(1) {
|
|
|
|
|
// sleep(100);
|
|
|
|
|
//}
|
2024-10-21 23:35:32 +08:00
|
|
|
}
|