![禁用特定程序的 RAM 内存缓存](https://linux22.com/image/1053356/%E7%A6%81%E7%94%A8%E7%89%B9%E5%AE%9A%E7%A8%8B%E5%BA%8F%E7%9A%84%20RAM%20%E5%86%85%E5%AD%98%E7%BC%93%E5%AD%98.png)
我正在使用由 C 语言编写的二进制文件运行一些基准测试。有什么方法可以让内核不要缓存这些二进制程序的任何部分吗?
答案1
查看有关“drop_caches”的内核文档。
https://www.kernel.org/doc/Documentation/sysctl/vm.txt
以下是一小部分:-
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.