Buffer Memory and Cache Memory

This section describes buffer memory and cache memory, which are temporary memory allocations in the free RAM area to improve data input and output performance on hard disk.

What Is Buffer Memory? - Buffer Memory is a temporary memory allocation in the free RAM area to hold input or output data from or to hard disks or other external channels. In other words, buffer memory buffers input or output data between CPU and hard disk. When the input or output process is ended, the buffered data will be released.

What Is Cache Memory? - Cache Memory is a temporary memory allocation in the free RAM area to hold frequently used data from hard disk for for subsequent repeating uses. In other words, cache memory caches disk data in RAM for subsequent uses. Cached data will not be released until free memory is low.

"free" - Display Buffer and Cache Memory - "free" command displays usage of the physical memory, including buffer and cache memory. The default output shows the total size of the buffer and cache memory in a single column:

herong$ free

          total     used     free  shared  buff/cache  available
Mem:    7745404  2390776   537928  302640     4816700    4740408
Swap:   8085500   957800  7127700

You can add the "-w" option to show buffer memory and cache memory in separate columns:

herong$ free -w 

         total     used     free  shared  buffers    cache  available
Mem:   7745404  2390668   538036  302640   121964  4694736    4740524
Swap:  8085500   957800  7127700

"/proc/meminfo" - Buffer and Cache Memory Information - /proc/meminfo is a pseudo file that contains memory usage information including buffer memory and cache memory. You can use the "cat" command to display information from /proc/meminfo:

herong$ cat /proc/meminfo

MemTotal:        7745404 kB
MemFree:          506952 kB
MemAvailable:    4712476 kB

Buffers:          122500 kB
Cached:          4111696 kB

SwapTotal:       8085500 kB
SwapFree:        7127700 kB

Shmem:            302640 kB
...

Note that:

Also note that the "free" actually read memory usage information from the "/proc/meminfo" pseudo file.

"sysctl vm.drop_caches" - Drop Cache Parameter - "sysctl vm.drop_caches" command displays the "drop cache" kernel parameter. You can also use the -w option to modify it:

 
herong$ sysctl vm.drop_caches
vm.drop_caches = 0

herong$ sudo sysctl -w vm.drop_caches=1
vm.drop_caches = 1

herong$ sudo sysctl -w vm.drop_caches=0
vm.drop_caches = 0

# where:
  vm.drop_caches = 0 - No dropping
  vm.drop_caches = 1 - Drop pagecache 
  vm.drop_caches = 2 - Drop reclaimable slab objects 
  vm.drop_caches = 3 - Drop pagecache and reclaimable slab objects

Note that the "drop cache" parameter can also be interfaced through the system pseudo file /proc/sys/vm/drop_caches:

herong$ cat /proc/sys/vm/drop_caches

0

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

Memory Management

 Layers of Memory and Access Speed

 List CPU Caches and Their Sizes

 Virtual Memory vs. Physical Memory

Buffer Memory and Cache Memory

 Verify Cache Memory with "cp" Command

 What Is Swap Space

 Virtual Memory Mapping and Page Table

 "ps -o rss,drs,trs,vsz,sz" - Process Status Options

 smem - Process Memory Usage Report

 pmap - Process Memory Map

 /proc/{id}/maps - Process Memory Map

 /proc/{id}/smaps - Process Memory Map Details

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB