I just discovered this one...
Sometimes, your RAM fills while you are working and it is not a good time to reboot.
With three commands, you can clear out some RAM:
sudo sync
sudo sysctl -w vm.drop_caches=3
IMPORTANT!:
You must run the following command again, or information currently in RAM that you are using and need could be lost
sudo sync
After running all three of the above, you should see a marked increase in Available RAM.
Hello everyone,
I have a question about the second sudo sync:
According to Leo (KI Brave), this is unnecessary.
Yes or no?
First sudo sync : This is correct and necessary . It forces the writing of pending data ("dirty" buffers) to the disk before clearing the cache, preventing potential data loss of unsaved changes.
The sysctl command : This is correct for clearing the cache (PageCache, dentries, and inodes).
Second sudo sync : This is unnecessary . Once the cache is cleared by vm.drop_caches=3 , there are no longer any "dirty" buffers in memory to write to disk. Running sync immediately after serves no purpose because the clearing operation has already been completed.
I had, as I said, discovered that as a guide (in bits and pieces) about four years ago, and relayed that here.
Now, four years later... I do have a bit better understanding of it and that warning, in hindsight, makes less sense. It may be a warning I read; or it may be an assumption of better safe than sorry - I do not remember, now.
If running the second time is unnecessary, it is still harmless.
What the above Helps With is avoiding kernel Direct Reclaim.
This allows a user to have a cold start on Processing using RAM.
However, if you are actively running a process that relies on cached data, then clearing out unused data can include removing the cached data which can lower system performance.
If you are working and need to avoid the kernel needing to perform a direct reclaim - the above is helpful.
If you are playing MineCraft and your RAM looks full, trust the systems own cache checks and don't run the command - it may hurt performance in that case.