简体   繁体   中英

Is there a way to disable system(unix) caching for disk files?

I'm currently doing a performance test for b+tree vs. ordinary-balanced-tree on disk file operations(maybe a kind of dbms) in C. b+tree is expected to be faster than bbst because it performs fewer disk I/O operations. But I found that, after some testing, the system is doing caching for the disk files, the file was entirely saved in memory(my memory size is 32GB)! b+tree can by no means be faster than bbst because no disk I/O will be performed. So I wonder if there is a way to disable system caching so that b+tree will win in perf? I've tried open the file with O_DIRECT|O_SYNC:

int fd = Open("sb.dat", O_DIRECT|O_SYNC|O_CREAT|O_RDWR, S_IRWXU|S_IRWXG|S_IRWXO);

but it seems not work.

Here is some info provided by getrusage()

page reclaims: 1359821

page faults: 9

即使你使用O_DIRECT ,AFAIK内核仍然会从磁盘缓存块,你可以删除内核缓存,但这只能在第一次运行:

echo 3 > /proc/sys/vm/drop_caches

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM