A question about page caching

From: Matvejchikov Ilya
Date: Tue Mar 04 2008 - 11:57:24 EST


Hi folks,

I have a little question about such thing as a page caching while file
reading. As I know there is mechanism that optimise system performance
when file read occurs repeatedly. But I can't simulate it. The test
program that I wrote doesn't show acceptable results.
Here is it.

--- [main.c] ---
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <asm/msr.h>

#define RSIZE (4096*1024*128)

int main()
{
int fd;
char * data;
unsigned long long counter0;
unsigned long long counter1;

fd = open("junkfile", O_RDONLY);
if (fd == -1) {
printf("ERROR: open() = %d\n", fd);
exit(1);
}

data = (char *)malloc(RSIZE);
if (data == NULL) {
printf("ERROR: malloc() fails\n");
exit(1);
}

rdtscll(counter0);
read(fd, (void *)data, RSIZE);
rdtscll(counter1);

printf("D = %lu\n", counter1 - counter0);

fgetc(stdin);

close(fd);

return 0;
}
--- [main.c] ---

When I run first copy of program I have such result:
(1) D = 191860948
When I run second copy of program (i.e. when first copy waits on
fgetc()) I have the similar result:
(2) D = 192320613

Where I be wrong?

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/