• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

How to disable the buffer cache of linux fs.

发布: 2007-5-26 11:32 | 作者: 未知 | 来源: Blog.ChinaUnix.net | 查看: 26次 | 进入软件测试论坛讨论

领测软件测试网
try opening the file with O_DIRECT in the flags.
O_DIRECT allows reads and writes to avoid the linux fs cache

举例;

#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

unsigned long long get_sys_time();
int main(int argc,char*argv[])
{
int i;
int nRet=0;
if(argc!=3)
{
printf("Usage:pro file size\n");
return 0;
}
unsigned long long llBeg =0;
unsigned long long llEnd =0;
int fp;
int nLen = atoi(argv[2]);

char *pBuf = (char*)calloc(1,nLen);
llBeg = get_sys_time();
fp = open(argv[1],O_RDONLY,O_DIRECT);
assert(fp>0);
memset(pBuf,0,nLen);
nRet = read(fp,pBuf,nLen);
close(fp);
llEnd = get_sys_time();
free(pBuf);
printf("readed=%d\n",nRet);
printf("elapsed time:=%d\n",(llEnd-llBeg)/1000);
return 0;

}


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/