Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands for memory cleanup and release in the Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the command of memory cleaning and release in the Linux system". In the daily operation, I believe that many people have doubts about the command of memory cleaning and release in the Linux system. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what are the commands for cleaning and releasing memory in the Linux system?" Next, please follow the editor to study!

# cleanup steps

# memory usage before cleaning

The code is as follows:

Free-m

# start cleaning

The code is as follows:

Echo 1 > / proc/sys/vm/drop_caches

# memory usage after cleanup

The code is as follows:

Free-m

Done!

# command to view the number of memory entries:

The code is as follows:

Dmidecode | grep-A16 "Memory Device$"

To free pagecache:

Echo 1 > / proc/sys/vm/drop_caches

To free dentries and inodes:

Echo 2 > / proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

Echo 3 > / proc/sys/vm/drop_caches

Sync

# it is best to sync before release to prevent data loss. Because of the kernel mechanism of LINUX, there is generally no need to specifically release cache that is already in use. The contents of these cache can increase the speed of reading and writing files as well.

# Let's talk about how the free command looks at memory.

The code is as follows:

$free

Total used free shared buffers cached

Mem: 1535052 918928 616124 0 2512 82964

-/ + buffers/cache: 833452 701600

Swap: 0 0 0

# the first line describes the memory used by the system from a global point of view:

Total physical memory of total--

Used-- has used memory, which is generally larger because it includes the memory used by cache+ applications

Free-- completely unused memory

Shared-- application shared memory

Buffers-- cache, mainly used for directories, inode value, etc. (this value can be seen in the ls directory)

Cached-- cache for open files

Total = used + free

Used = buffers+cached (maybe add shared also)

The second line describes the memory usage of the application:

The first value represents-the amount of memory used by the buffers/cache-- application, used minus the cache value

The latter value represents + buffers/cache-- all the memory available to the application, free plus cache value

-buffers/cache=used-buffers-cached

+ buffers/cache=free+buffers+cached

The third line represents the use of swap:

Used-- has been used

Free-- is not in use

Execute the sync command manually (description: the sync command runs the sync subroutine. If the system must be stopped, run the sync command to ensure the integrity of the file system. The sync command writes all unwritten system buffers to disk, including the modified i-node, deferred block Imax O, and read-write mapping file)

Echo 3 > / proc/sys/vm/drop_caches

Cat / proc/sys/vm/drop_caches

three

! Set the / proc/sys/vm/drop_caches value to 3

# the usage of / proc/sys/vm/drop_caches is explained below

The code is as follows:

/ proc/sys/vm/drop_caches (since Linux 2.6.16)

Writing to this file causes the kernel to drop clean caches

Dentries and inodes from memory, causing that memory to become

Free.

To free pagecache, use echo 1 > / proc/sys/vm/drop_caches; to

Free dentries and inodes, use echo 2 > / proc/sys/vm/drop_caches

To free pagecache, dentries and inodes, use echo 3 >

/ proc/sys/vm/drop_caches.

Because this is a non-destructive operation and dirty objects

At this point, the study on "what is the command to clean and free memory in the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report