- 论坛徽章:
- 0
|
最近大数据做索引的时候发现的一个问题, 只要是读很频繁的, 系统内存不停的增长,
我在os x 和 linux测试都是这样, 这个不是内存泄露的问题, 我认为是内核对文件做cache的问题.
os x会影响系统性能, linux只要内存用光以后会明显的想能下降, 有哪位遇到过或者解决过这样的问题, 按理应该是可以设置内核cache的.
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <errno.h>
- #define BUF_SIZE 1024 * 1024 * 8
- // gcc -o test test.c -D_FILE_OFFSET_BITS=64
- int main(int argc, char **argv)
- {
- int fd = 0, n = 0, i = 0;
- char *s = (char *)calloc(1, BUF_SIZE);
- if(argc < 2)
- {
- fprintf(stderr, "Usage:%s hispider_file\n", argv[0]);
- _exit(-1);
- }
- for(i = 1; i < argc; i++)
- {
- if((fd = open(argv[i], O_RDONLY)) > 0)
- {
- n = 0;
- while((read(fd, s, BUF_SIZE)) > 0)n++;
- fprintf(stdout, "times:%d\n", n);
- close(fd);
- }
- else
- {
- fprintf(stderr, "open file failed, %s\n", strerror(errno));
- }
- }
- if(s) free(s);
- return 0;
- }
复制代码 |
|