What are the commands necessary to clear the L1, L2 and L3 cache in ubuntu?
Can this be done utilising the shell or do I need a higher level language?
What are the commands necessary to clear the L1, L2 and L3 cache in ubuntu?
Can this be done utilising the shell or do I need a higher level language?
L1, L2 and L3 cache are terms used to describe caches used internally by the CPU and chipset. They are transparent to the system, that is, the existence or not of data in the caches shall never have any observable side effects on program execution or the data returned by any operation. There is therefore also no way to clear them and if there were, doing so would have no observable effect.
These caches are integral to the functioning of the CPU. Their contents are refreshed possibly millions of times per second, depending on the operations in progress.
From: Way to flush/ clear the RAM and cache memories
It is not possible to do this with complete effectiveness at user level. Performance counters in the uncore can be used to derive the mapping of physical addresses to L3 slices (CBos) for any address range that the user can allocate and test, but that only tells you which CBo is being used, not which congruence class within that slice is being used. The size of the L3 slices suggests a straightforward mapping, but I don't know of any demonstrations that confirm the internal mapping.
At the gross level, on Xeon E5 v3 systems, reading an array that is 4x larger than the L3 cache size will clear nearly 100% of the prior data from the L1, L2, and L3 caches. This only requires process binding (e.g., "taskset" or "numactl --physcpubind" on Linux systems).