How to drop memory cache periodically in Linux?

Working on a system measurement project and it requires me to drop a cache periodically to get an accurate number (since having cache there would alter the results). Currently I can manually drop the cache by using:

echo 3 > /proc/sys/vm/drop_caches

However, I want it to automatically drop every microsecond. What command should I use?

Answers


You could create you own command to do that, i.e. write a program to do that. For example, you could do something like:

while (1) {
    if ((fp = fopen("/proc/sys/vm/drop_caches", "r")) == NULL) {
        /* error handler */
    }
    fprintf(fp, "3\n");
    fclose(fp);

    nanosleep(...); /* See nanosleep(2) */
}

in your program, and made it a daemon.


Need Your Help

How to show one by one nodes in Vis JS directed graph

javascript graph directed-graph vis.js

Need to show one by one sorted order nodes with directed graph in vis js like a video on a play button event.

Saving memory by hiding non-visible views?

objective-c performance uiview hide

I've got just a short question, I'm using ARC and have multiple views in a horizontal scrollview. Does hiding non visible views save me some memory ? Or is there any other way to keep the performan...