linux nocache idea

Sun 09 June 2013 by admin

Each time when you read file it's content is put into cache:

# grep -w "Cached" /proc/meminfo
Cached:           255220 kB
# cat sample.file >/dev/null
# grep -w "Cached" /proc/meminfo
Cached:           357628 kB

of course it happens when there is enough free memory. But imagine situation when you read huge amount of data not related to current server activity i.e. read some big files on database server with plenty of cached data, it should hurt on performance. So what about disabling caching data on specific activity:

https://github.com/Feh/nocache

nocache it's doing its job pretty well, some notes:

# cachestats sample.file
pages in cache: 0/25600 (0.0%)  [filesize=102400.0K, pagesize=4K]
# for i in $(seq 0 2); do /usr/bin/time --format '%E' nocache cp -f sample.file /tmp; done
0:07.60
0:08.16
0:07.98
# cachestats sample.file
pages in cache: 0/25600 (0.0%)  [filesize=102400.0K, pagesize=4K]
# for i in $(seq 0 2); do /usr/bin/time --format '%E' cp -f sample.file /tmp; done
0:06.38
0:02.66
0:04.80
# cachestats sample.file
pages in cache: 25600/25600 (100.0%)  [filesize=102400.0K, pagesize=4K]

it shows us that using nocache copy couple times it gives us pure IO performance not boost by cache, similar to situation when you wipe out all pagecache by:

# echo 1 > /proc/sys/vm/drop_caches

Comments