Skip to content
Welcome To Charanjit Cheema Blog

Welcome To Charanjit Cheema Blog

An Open Source and Cloud Blog

Menu
  • Home
  • About Me!
  • Way to my Technical Blog
  • Contact me
  • Privacy Policy
Menu

How to clear memory cache and buffer in Linux

Posted on January 5, 2024January 5, 2024 by Charanjit Singh

Linux, like other operating systems, has an efficient and affective memory management for managing memory hungry Application or database. RAM as you know is a vital part for Operating systems for storing code and data, in Linux it uses memory cache and buffer for improving the system performance.

If I talk bit more about memory cache and buffer, although memory cache is used by the operating system kernel for keeping regular accessed data in memory for improving the system performance, but an overloaded cache of obsolete data can also impact adverse of system performance as well. Whereas memory buffer is used for improving communication between CPU and Hard Disks or other storage media by storing data temporarily till then data is processed between the CPU and Hard Disks, or other storage media.

Although application or database running on Linux use memory page cache management algorithm such as LRU (Least Recent Used) or LFU (Least Frequent Used) for optimizing memory automatically, but sometime high memory intensive application or database can cause performance issue in operating system by creating memory bottleneck.

In this Article I will show you the steps on how to clear memory cache and buffer by using Linux commands without worrying about killing or stopping the memory hogging Application or database processes.

 

Clearing memory Page Cache and buffer through Linux command

There are three ways for clearing the buffer and cache from system memory:

 

  1. To clear only page cache:

# sync; echo 1 > /proc/sys/vm/drop_caches

 

  1. To clear dentries (directory entries) and inodes:

# sync; echo 2 > /proc/sys/vm/drop_caches

 

  1. Third option is to use below command for clearing dentries, inodes and page cache as well:

# sync; echo 3 > /proc/sys/vm/drop_caches

 

In the above three command options you can see multiple commands are used with semicolon “;” as first command sync will clear the filesystem buffer then after semicolon other commands run for clearing the cache.

 

An example of one of above command usage:

You can see by using one of the above command how much memory cache and buffer are dropped.

 

Wrap up!

In this article you have read about how to clear the memory buffer and Page Cache in Linux with three simple commands without worrying about killing or stopping the memory intensive Application or Database processes. But in case if memory bottleneck issue is persisted consider to check with Application or database vendors for getting kernel memory tunable parameters or you can also consider to increase the server memory or RAM as well.

Loading

  • Author
  • Recent Posts
Charanjit Singh
Follow him
Charanjit Singh
Charanjit is currently working as a Cloud Architect at Mphasis, with 18 years of experience in IT infrastructure projects, implementation, and support. While his main role is as a DevOps engineer, he holds a Cloud Architect position and has strong skills in cloud technologies and automation. His expertise includes Terraform, AWS, Azure DevOps, Azure Cloud, VMware, and Linux systems.

Charanjit is passionate about automating tasks and improving processes. He uses tools like Terraform and Azure DevOps to build and manage cloud infrastructure and streamline deployment. He also enjoys using Shell scripts and Ansible playbooks to make systems run more efficiently.

In his free time, Charanjit enjoys learning about new technologies and sharing his knowledge through his blog. When he’s not working, he likes listening to music, having a cup of coffee, and relaxing in nature.

You can connect with Charanjit on Twitter, Facebook, LinkedIn, or email him at charanjit.cheema@cjcheema.com.
Charanjit Singh
Follow him
Latest posts by Charanjit Singh (see all)
  • How to Deploy Docker Containers with NGINX on AWS EC2 Using Ansible and GitHub Actions - April 26, 2025
  • No More DynamoDB! Use Native S3 locking for Terraform State - February 7, 2025
  • How to Bring and Manage Manually Created AWS Resources Under Terraform Management - January 31, 2025

Like this:

Like Loading...

Related

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tags

AWS Cloud Computing Dockers Networking Open Networking OpenSource RHEL-CentOS SDN Server Hardware SLES tcpdump Ubuntu WSL

Follow me @

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2 other subscribers

Recent Posts

  • How to Deploy Docker Containers with NGINX on AWS EC2 Using Ansible and GitHub Actions
  • No More DynamoDB! Use Native S3 locking for Terraform State
  • How to Bring and Manage Manually Created AWS Resources Under Terraform Management
  • Iterating Cloud Resource Provisioning Using Terraform Count and For_Each Meta-Arguments
  • Terraform and Ansible Collaboration for AWS Cloud Deployment

Recent Comments

  1. Charanjit Singh on Terraform and Ansible Collaboration for AWS Cloud Deployment
  2. christinatodd2020aeaa798563 on Terraform and Ansible Collaboration for AWS Cloud Deployment
  3. Charanjit Singh on How to Set password policy in CentOS or RHEL system
  4. SAURABH on How to recover or rebuild initramfs in CentOS 7 Linux
  5. Sangita on How to Set password policy in CentOS or RHEL system

Archives

  • April 2025
  • February 2025
  • January 2025
  • August 2024
  • July 2024
  • June 2024
  • January 2024
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • September 2022
  • August 2022
  • July 2020
  • May 2020
  • February 2020
  • November 2019
  • June 2019
  • May 2019
  • March 2019
  • February 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • June 2018
  • May 2018
  • April 2018

Categories

  • Automation
  • Cloud Computing
  • Coding
  • CyberSecurity
  • Networking
  • OpenSource
  • RHEL-CentOS
  • Server Hardware
  • SLES
  • Technical Blog
  • Ubuntu
  • WSL

Blog Stats

  • 18,353 hits
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Home
  • About Me!
  • Way to my Technical Blog
  • Contact me
  • Privacy Policy
© 2025 Welcome To Charanjit Cheema Blog | Powered by Superbs Personal Blog theme
 

Loading Comments...
 

    %d