How to clear RAM without rebooting?

David Beroff

Well-known member
Registered
Joined
Jun 14, 2016
Messages
1,501
Points
63
I want to free up memory by clear RAM on my VPS Linux but seem this needs a reboot. Can I clear RAM without rebooting?
 

Malware.Expert

Member
Registered
Joined
Jun 18, 2018
Messages
55
Points
18
With root account:
Code:
sync; echo 3 > /proc/sys/vm/drop_caches
Clear PageCache, dentries and inodes

But not recommend production server's, just Clear PageCache:
Code:
sync; echo 1 > /proc/sys/vm/drop_caches
 

AlbaHost

Well-known member
Moderator
Hosting Provider
Joined
Jan 18, 2017
Messages
809
Points
43
I want to free up memory by clear RAM on my VPS Linux but seem this needs a reboot. Can I clear RAM without rebooting?
Just add to crontab:

*/10 * * * * sync && echo 3 > /proc/sys/vm/drop_caches

Let the cron do the job for you, you can change time, mentined is in every 10 minutes.
 

David Beroff

Well-known member
Registered
Joined
Jun 14, 2016
Messages
1,501
Points
63
With root account:
Code:
sync; echo 3 > /proc/sys/vm/drop_caches
Clear PageCache, dentries and inodes
But not recommend production server's, just Clear PageCache:
Code:
sync; echo 1 > /proc/sys/vm/drop_caches
I tried to run this command on a small VPS and seem it worked

Before purge RAM

Code:
[root@server1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           971        794        177          0        237        432
-/+ buffers/cache:        124        847
Swap:            0          0          0
Code:
[root@server1 ~]# sync; echo 3 > /proc/sys/vm/drop_caches
After purged RAM

Code:
[root@server1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           971         96        875          0          0         14
-/+ buffers/cache:         80        891
Swap:            0          0          0
and this command deleted cached of VPS, right?
cached 432 -> cached 14
 

mobin

Well-known member
Registered
Joined
Jun 22, 2017
Messages
234
Points
28
I am just wondering what advantage do you see after clearing the cached contents from RAM? Seeing a lot of Free memory is not really shows its all good, especially when its showing after clearing the cache. Clearing cache will free RAM, but it causes the kernel to look for files on the disk rather than in the cache which can cause performance issues. So its not recommended to do it regularly. When there is an increased demand for memory kernel will automatically clear cache and allocate RAM for the requested process.
 

David Beroff

Well-known member
Registered
Joined
Jun 14, 2016
Messages
1,501
Points
63
I am just wondering what advantage do you see after clearing the cached contents from RAM?
Sometime server high load then it is time to clear RAM?
So its not recommended to do it regularly.
So when should we clear RAM?
Clearing cache will free RAM, but it causes the kernel to look for files on the disk rather than in the cache which can cause performance issues.
I am caring about this and I should ignore purging RAM and caches on servers?
 

mobin

Well-known member
Registered
Joined
Jun 22, 2017
Messages
234
Points
28
mobin
1. Server load cannot be related to the cache memory but can be because your system is running out of memory because of increased demand due to some processing. The cached memory should be freed up and served to such processes by kernel on demand. Have you ever noticed the load goes down after clearing cache memory?

2. You shouldn't do it normally. Normally people do it to benchmark disk IO

3. That is what recommended unless you have some exceptional requirements. For the normal system running, no need to do it.
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
VirtuBox
Linux always use almost all RAM available as cache, but it's not an issue.
You shouldn't need to purge cache, but you can improve performances by adding some rules about memory management in your kernel configuration

For example, you can add the following lines in /etc/sysctl.conf :
Code:
# Do less swapping
vm.swappiness = 30
vm.dirty_ratio = 30
vm.dirty_background_ratio = 5

# specifies the minimum virtual address that a process is allowed to mmap
vm.mmap_min_addr = 4096

# 50% overcommitment of available memory
vm.overcommit_ratio = 50
vm.overcommit_memory = 0

# Set maximum amount of memory allocated to shm to 256MB
kernel.shmmax = 268435456
kernel.shmall = 268435456

# Keep at least 64MB of free RAM space available
vm.min_free_kbytes = 65535
Source : https://klaver.it/linux/sysctl.conf
 

panamaserver

Member
Registered
Joined
Jun 3, 2018
Messages
35
Points
8
if your server is getting low RAM you need to find the reason, clearing ram is not the solution
if you have added more websites to your server
or if you have added some plugins to a site
or any modification you have made that cause the server to use all the RAM need to be considered.

Once you find the reason you probably can fix it or optimize it, or BUY more ram maybe that's what your server need because you have added more sites or your sites grow in traffic considerably.
 

Daniel204

Active member
Registered
Joined
Jun 19, 2018
Messages
67
Points
8
Hi,

If you have a suitable motherboard and an OS that supports hotpluggable RAM (such as Linux), yes.

If you're not running a motherboard and OS that supports such RAM (ie: most people), the answer is no.

HTH!

Regards,
Daniel
 

Nixtree

Well-known member
Registered
Joined
Jul 16, 2016
Messages
133
Points
28
In your case I will say if possible please try adding a 2 G swap which will help in load times. Normally there is no actual use in clearing the RAM as those which are showed as cached is also available for processes. So it will get cached again after some minutes or hours.
 
Latest Threads
Replies
1
Views
26
Replies
0
Views
188
Replies
1
Views
40
Replies
2
Views
83

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top