Compare commits

..

No commits in common. "a3ad058a2f992f20ef2f4994a260ca9ae5c7356a" and "3ad98707c78ba6c1bf59d22d29d5d1229dbb7132" have entirely different histories.

3 changed files with 10 additions and 93 deletions

56
bak.c
View File

@ -1,56 +0,0 @@
#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()
{
char c;
pid_t pid;
int i;
struct timeval tv_b, tv_e;;
#define SIZE 400*1024*1024
void *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (!p) {
perror("fail to get memory");
exit(-1);
}
for (i = 0; i < 100000; i++) {
madvise(p, SIZE, MADV_HUGEPAGE);
memset(p, 0x11, SIZE); /* write to get mem */
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)));
//pid = fork();
//if (pid) {
//scanf("%c", &c);
gettimeofday(&tv_b, NULL);
memset(p, 0x33, SIZE); /* write to get mem */
gettimeofday(&tv_e, NULL);
printf("swp in bandwidth: %ld bytes/ms\n",
SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b)));
//}
}
while(1) {
sleep(100);
}
}

10
demo.c
View File

@ -33,7 +33,7 @@ int main(int argc, char **argv)
size_t file_size = sb.st_size; size_t file_size = sb.st_size;
printf("%ld, %d Kb\n", file_size, file_size/1024); printf("%ld, %d Kb\n", file_size, file_size/1024);
void *mapped = mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); void *mapped = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (mapped == MAP_FAILED) { if (mapped == MAP_FAILED) {
perror("mmap"); perror("mmap");
close(fd); close(fd);
@ -44,14 +44,8 @@ int main(int argc, char **argv)
max = file_size / 8; max = file_size / 8;
p = malloc(file_size); p = malloc(file_size);
for (i = 0; i < max; i++) { for (i = 0; i < max; i++)
*(p + i) = *(m + i); *(p + i) = *(m + i);
*(m + i) = *(p + i);
}
fork();
fork();
fork();
while(1); while(1);

View File

@ -15,13 +15,9 @@ unsigned long long tv_to_ms(struct timeval tv)
void main() void main()
{ {
char c;
pid_t pid;
int i;
int j = 0;
struct timeval tv_b, tv_e;; struct timeval tv_b, tv_e;;
#define SIZE 100*1024*1024 #define SIZE 400*1024*1024
unsigned long *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, void *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (!p) { if (!p) {
perror("fail to get memory"); perror("fail to get memory");
@ -29,29 +25,12 @@ void main()
} }
madvise(p, SIZE, MADV_HUGEPAGE); madvise(p, SIZE, MADV_HUGEPAGE);
memset(p, 0x11, SIZE); /* write to get mem */
for (j = 0; j < SIZE / 8; j+=128)
*(p + j) = j;
for (i = 0; i < 3; i++) {
gettimeofday(&tv_b, NULL); gettimeofday(&tv_b, NULL);
madvise(p, SIZE, MADV_PAGEOUT); madvise(p, SIZE, MADV_PAGEOUT);
gettimeofday(&tv_e, NULL); gettimeofday(&tv_e, NULL);
printf("swp out bandwidth: %ld bytes/ms\n", printf("swp out bandwidth: %ld bytes/ms\n",
SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b))); 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);
//}
} }