Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

unix

caching

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

like image 853
Clann Chen Avatar asked Nov 04 '22 07:11

Clann Chen


1 Answers

AFAIK the kernel will still cache blocks from the disk even when you use O_DIRECT, you could drop the kernel cache but this only works the first time:

echo 3 > /proc/sys/vm/drop_caches
like image 196
iabdalkader Avatar answered Nov 09 '22 12:11

iabdalkader