在进行一些基准测试工作之前,如何释放 Linux 内核为其缓冲区和缓存消耗的内存 (RAM)?
请注意,这主要用于基准测试。清空缓冲区和缓存会降低性能!如果你在这里是因为你认为释放缓冲区和缓存是一件好事,那就去读一读Linux 吃了我的 RAM!. 简短的故事:空闲内存是未使用的内存是浪费的内存。
作为进行一些冷缓存计时的一部分,我正在尝试释放操作系统缓存。该内核文档(检索2019日)说:
drop_caches
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 …
Run Code Online (Sandbox Code Playgroud) 是否有任何命令可以通过使用我可以清除 RHEL 中的缓存?
我使用了这个命令:
sync; echo 3 > /proc/sys/vm/drop_caches
Run Code Online (Sandbox Code Playgroud)
但它没有用。