Drop Linux Cache

Drop Linux Cache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

/bin/sync

# Free pagecache
# echo 1 > /proc/sys/vm/drop_caches
# sysctl vm.drop_caches=1

# Free reclaimable slab objects (includes dentries and inodes)
# echo 2 > /proc/sys/vm/drop_caches
# sysctl vm.drop_caches=2

# Free both page cache and slab objects
echo 3 > /proc/sys/vm/drop_caches
sysctl vm.drop_caches=3

# Disable drop cache logs, you will not be able to enable the logs again unless the system is restarted.
# https://github.com/torvalds/linux/blob/master/fs/drop_caches.c
# stfu |= sysctl_drop_caches & 4;

# echo 4 > /proc/sys/vm/drop_caches
# sysctl vm.drop_caches=4

/bin/sync