Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

To speed up operations and reduce disk I/O, the kernel typically caches as much memory as possible, which is known as Cache Memory. By design, pages containing cached data can be repurposed as needed (for example, by applications).

Cache memory is not automatically released after a program finishes running. This can lead to a situation where the available physical memory becomes very limited after frequent file read/write operations, necessitating the manual release of cache memory when required (for example, when memory is truly insufficient).

Note: Generally, it is not recommended to manually release cache memory unless you have a very clear need, such as testing the program’s cache memory usage, because cached memory is available for the same application.

Releasing Cache Content

You can release cache memory by modifying the system control file /proc/sys/vm/drop_caches.

1. Release pagecache

echo 1 > /proc/sys/vm/drop_caches

2. Release reclaimable slab objects (includes dentries and inodes)

echo 2 > /proc/sys/vm/drop_caches

3. Release slab objects and pagecache

echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation that will not release any dirty objects. If you want to increase the number of objects released by this operation, you can run sync before writing to /proc/sys/vm/drop_caches. This will minimize the number of dirty objects on the system and create more candidates for deletion.

It is important to note that /proc/sys/vm/drop_caches is not used to control the growth of various kernel caches (inodes, dentries, pagecache, etc.). When memory is needed elsewhere in the system, the Linux kernel will automatically reclaim these objects.

Using this file may lead to performance issues. Because it deletes cached objects, it may require a significant amount of I/O and CPU to recreate the deleted objects, especially if these objects are heavily used. Therefore, it is not recommended to use this outside of testing or debugging environments.

Practical Testing

# free -m
              total        used        free      shared  buff/cache   available
Mem:           7794        2373        1478         431        3942        4691
Swap:          3967           0        3967
# echo 1 > /proc/sys/vm/drop_caches
# free -m
              total        used        free      shared  buff/cache   available
Mem:           7794        2373        2600         431        2821        4705
Swap:          3967           0        3967
# echo 2 > /proc/sys/vm/drop_caches
# free -m
              total        used        free      shared  buff/cache   available
Mem:           7794        1635        5527         431         631        5495
Swap:          3967           0        3967
# echo 3 > /proc/sys/vm/drop_caches
# free -m
              total        used        free      shared  buff/cache   available
Mem:           7794        1635        5529         431         630        5496
Swap:          3967           0        3967

Link: https://www.cnblogs.com/shouke/p/16156335.html

(Copyright belongs to the original author, please delete if infringed)

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%End of Article BenefitsLinux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

As we approach 2025, many are considering their career direction for the coming year.

Currently, the transformation direction for traditional operations to earn an annual salary of over 300,000 is SRE & DevOps positions.

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

To help everyone get rid of tedious grassroots operations work as soon as possible, I have compiled a set of 【2024 Latest Operations MaterialsEssential Skills Package for Senior Operations Engineers (one-click to receive at the end), see the chart below for the rich content!
There are 20 modules in total
Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%
1.38 Most Comprehensive Engineer Skills Map
Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%
2.Interview Gift Package
Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%
3.Linux Books
Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%
4.Go Books

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

······

6.Automation Operations Tools

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

18.Message Queue Collection

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

All materials can be obtained by scanning the QR code

Linux Server Lag Savior: Release Cache Memory to Boost Performance by 30%

Recognize the QR code above

Note:2024 Latest Operations Materials

100% free to receive

(It is scan to receive, not to reply in the public account backend, don’t get it wrong)

Leave a Comment