Recently, it was found at the customer site that the physical memory usage of the arm linux embedded device was close to 100% after running for a period of time. The analysis found that it was related to the long-term cycle of several shell commands in the script program.
1. cp
Copying the command and using the cp command will increase the physical memory usage and cache usage of Linux. You can view the memory usage in the top command.
2. mv
Moving or renaming a file command, similar to cp, using the mv command will also increase the system's physical memory usage and cache usage. You can view the memory usage in the top command.
3. New file
Whether you create a new file through the command line or an application, and write data to the file, it will also lead to an increase in the system's physical internal memory and cache usage.
Because of the equipment on the customer's site, these situations are encountered, so other commands have not been analyzed.
In addition, the increase in physical memory usage and cache usage caused by the above three situations can be reduced by deleting file copies after cp, moving files, or newly created files but no longer accessed.
Here's how to manually free memory:
echo 1 > /proc/sys/vm/drop_caches
The value of drop_caches can be a number between 0-3, representing different meanings:
0: Do not release (system default value)
1: Release page cache
2: Release dentries and inodes
3: Release all caches
Note:
1. Release the memory Then change it back and let the system re-allocate memory automatically.
echo 0 >/proc/sys/vm/drop_caches
2. Be sure to run the sync command before using this command to avoid file loss.