I have this little C89 program -- what it does, how it works, and the undefined behaviour aren't important, just that it does some long memory & math operations on just one thread:x, c, * b, m, t, i, a;g (n) {  for (b = malloc(0); c < n; b[c - 1] = x++, t = 1) {    char s[9];    for (i = m = 0; i < sprintf(s, %d, x); m += a, t *= a) a = s[i++] - 48;    b = m * t ? x % m + x % t ? b : realloc(b, 4 * ++c) : b;  }  return b[c - 1];}main (j) {  printf(%d\n, g(--j));}Compile it like this: gcc -std=c89 tt.c -o tt -O3. Then, if I use a shell script to run it in a loop, to get an idea of its running time:#!/bin/bashecho using input $1for _ in `seq 1 10`; do  ( time ./tt $(seq 1 $1) ) 3>&1 1>/dev/null 2>&3 \    | grep real \    | cut -f2  # sleep 5doneI see output like this:$ ./tt.sh 50using input 500m0.016s0m0.008s0m0.008s0m0.007s0m0.007s0m0.007s0m0.008s0m0.008s0m0.007s0m0.007sOr like this:$ ./tt.sh 34using input 340m0.007s0m0.004s0m0.004s0m0.004s0m0.005s0m0.004s0m0.003s0m0.003s0m0.003s0m0.004sThere is an initial speedup in the real runtime of the program after the first call, and then all subsequent calls run at this fake speedup.If I uncomment the # sleep 5 line in the shell script, we see these results:using input 500m0.008s0m0.020s0m0.018s0m0.012s0m0.009s0m0.006s0m0.013s0m0.012s0m0.009s0m0.012susing input 340m0.006s0m0.007s0m0.004s0m0.007s0m0.008s0m0.003s0m0.004s0m0.004s0m0.005s0m0.007sThe times appear more expected and accurate, and discrepancies therein must be attributed to the random state of the processor in that moment (i.e. they are small natural variations).If I want to get an average running time for my program, I should average these numbers, but sleep 5 between each call, while it is the only way I can find to stop this behaviour, adds up to 50 seconds for 10 tests instead of a few seconds for 20 tests.I've seen this replay caching behaviour before with single-threaded programs that do long operations over and over (tight loops), and I understand it's desirable in 99.9% of all cases.Assuming this isn't a consequence of some Intel Magic at the hardware level, is this something the Linux kernel or Bash are doing intentionally, and how can I make it stop?I'd like reproducible runtimes for my programs, including library loading and paging from cold start, without sleep 5ing, because the times affected by caching do not represent a cold start each time.
How to prevent this replay caching behaviour?
bash;ubuntu;exec
As in my comment:Probably won't help but try echo 3 > /proc/sys/vm/drop_caches before  each invocation of ttQuestioner's response:Yes, echo 1 | sudo tee /proc/sys/vm/drop_caches does exactly what I  want (echoing 3 instead gives a weird result). You should put that as  an answerDocumentation of values:To free pagecache:    echo 1 > /proc/sys/vm/drop_cachesTo free reclaimable slab objects (includes dentries and inodes):    echo 2 > /proc/sys/vm/drop_cachesTo free slab objects and pagecache:    echo 3 > /proc/sys/vm/drop_caches