How to release memory in Linux without the need to rest…
In Linux systems, there are several methods available to free up memory without needing to restart.
- To clear the page cache: Page cache is a part of memory that the kernel uses to cache filesystem data. You can use the following command to clear the page cache:
- Execute the command “sudo sync” followed by “sudo echo 1 > /proc/sys/vm/drop_caches” in the terminal.
- This command will release some memory back to the system.
- Clearing buffer cache: Buffer cache is a portion of memory used to cache block device data. You can use the following command to clear the buffer cache:
- Refresh the system’s memory cache by executing the commands “sync” and “echo 2 > /proc/sys/vm/drop_caches” with sudo privileges.
- This command will free up more memory, but it may result in some disk IO delays.
- Free up occupied pages: Sometimes, certain processes in the system can occupy a large amount of memory. You can use the following command to release the occupied pages:
- Execute the command “echo 1 > /proc/sys/vm/compact_memory” with superuser privileges.
- This command will attempt to free up occupied pages to provide more available memory.
- Terminate unnecessary processes: Use the kill command to end any unnecessary processes that are taking up a significant amount of memory in the system, in order to free up memory.
- Terminate the process with the specified process ID using sudo.
- By replacing
with the actual process ID, you can kill a specific process.
Please be aware that before releasing memory, make sure that no important tasks or processes are relying on this memory. Additionally, these methods will only free up a portion of the memory, so if the memory usage on the system is still high, it may be necessary to consider increasing the system’s physical memory.