On Tue, 3 Jul 2018 09:42:46 +0200 Maximilian Pichler <maxim.pich...@gmail.com> wrote:
> I'm doing some performance tests that include reading files from disk > and want to make sure that each test takes place under similar > conditions. > > In particular, how can one clear the disk cache? (I want to make sure > that the second test isn't faster than the first one, just because > some files they both use are still in cache.) > > Right now I'm doing: > $ cat some_file_the_size_of_RAM > /dev/null > > Does this indeed clear the cache? Is there a better way? $ doas sysctl kern.bufcachepercent=5 This will knock the disk cache down to 5% of RAM space. You can not go lower, so a reboot between tests is the best way to have a clean state. Default is 20%, max. is 90% (which I use). > Also, are there several level of file/disk caches or just one? Just the one buffercache.