Freeing buffer/cache
Warning This explain a strong method not recommended on production server!
So you're warned, don't blame me if something goes wrong.
For understanding, the thing, you could force your system to delegate as many memory as possible to cache than drop the cached file:
Preamble
Before of doing the test, you could open another window an hit:
$ vmstat -n 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 1 39132 59740 39892 1038820 0 0 1 0 3 3 5 13 81 1
1 0 39132 59140 40076 1038812 0 0 184 0 10566 2157 27 15 48 11
...
for following evolution of swap in real time.
Nota: You must dispose of as many disk free on current directory, you have mem+swap
The demo
$ free
total used free shared buffers cached
Mem: 2064396 2004320 60076 0 90740 945964
-/+ buffers/cache: 967616 1096780
Swap: 3145720 38812 3106908
$ tot=0
$ while read -a line;do
[[ "${line%:}" =~ ^(Swap|Mem)Total$ ]] && ((tot+=2*${line[1]}))
done </proc/meminfo
$ echo $tot
10420232
$ dd if=/dev/zero of=veryBigFile count=$tot
10420232+0 records in
10420232+0 records out
5335158784 bytes (5.3 GB) copied, 109.526 s, 48.7 MB/s
$ cat >/dev/null veryBigFile
$ free
total used free shared buffers cached
Mem: 2064396 2010160 54236 0 41568 1039636
-/+ buffers/cache: 928956 1135440
Swap: 3145720 39132 3106588
$ rm veryBigFile
$ free
total used free shared buffers cached
Mem: 2064396 1005104 1059292 0 41840 48124
-/+ buffers/cache: 915140 1149256
Swap: 3145720 39132 3106588
Nota, the host on wich I've done this is strongly used. This will be more significant on a really quiet machine.