> It is just that the kernel cannot take initiatives that require
application-level knowledge (such as the fact that a function will often be
called with the same arguments). The programmer has to do the work in that
case.
No, it is perfectly within the kernel's initiative. Kernel does not have to
have application-level knowledge for this. Please note that the very purpose
of caching is prioritizing resource allocation between "consumers" competing
for the same resource. Any consumer (process) doing this by itself undermines
the whole logic behind system-level data caching. A process has to *compete*
for the resources, not *arbitrate* them. Arbitration is the kernel's job.
Following your example, if some data will be repeatedly accessed by a
program, than that chunk of data will get ahead of competition and will
always be in-cache. A user space program doesn't have to do anything special
for this to happen. The kernel will ensure that most frequently referenced
data will be cached. OTOH, if another competing program happens to access its
data more frequently than yours, then it will win the competition. You
*forcing* your data to be cached breaks the fair-share algorithm of the
kernel. So, a program force-caching its own data for *tactical* purposes is
both inefficient and selfish.
The only exception to this is when you have a higher (strategic) reason for
application level caching.