Verify Cache Memory with "cp" Command

This section provides a tutorial example to verify the cache memory usage in the RAM free space using a single 'cp' command.

To verify my understanding of the cache memory in the RAM free space, I tried the following test:

1. Create a 100000 KiB file using the "dd" command on a large file.

herong$ dd count=200000 if=large.bin of=100000KiB.bin  

herong$ ls -l 100000KiB.bin
-rw-r--r--. 1 herong herong 102400000 Aug 14 09:16  100000KiB.bin

2. Free cache memory as much as possible using the "drop_caches" system parameter.

herong$ sudo sysctl -w vm.drop_caches=3

vm.drop_caches = 3

3. Check the cache memory with the "free" command.

herong$ free -w

          total     used     free  shared  buffers   cache  available
Mem:   15731448  9702632  5472488  149684     6284  550044    5570860
Swap:   8019964  3478492  4541472

4. Copy the 100000 KiB file to /dev/null. It took about 0.4 seconds.

herong$ time -p command cp 100000KiB.bin /dev/null

real 0.40
...

5. Check the cache memory again. I see the cache memory size increased about 100000 KiB (649892 - 550044 = 99848 KiB), matching well with 100000KiB.bin file size.

herong$ free -w

          total     used     free  shared  buffers   cache  available
Mem:   15731448  9703108  5372164  149684     6284  649892    5536464
Swap:   8019964  3478492  4541472

6. Copy the 100000 KiB file to /dev/null again. It took only 0.01 seconds this time, because the entire file is in the cache memory.

herong$ time -p command cp 100000KiB.bin /dev/null

real 0.01
...

7. Check the cache memory again. It had a small change.

herong$ free -w

          total     used     free  shared  buffers   cache  available
Mem:   15731448  9702812  5371988  149684     6284  650364    5536800
Swap:   8019964  3478492  4541472

This test confirms that the cache memory is used to cache disk files in RAM to provide faster access for subsequent uses.

By the way, there is no easy way to verify the buffer memory usage.

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