How to clear RAM without rebooting?

David Beroff

Well-known member
Joined
Jun 14, 2016
Messages
884
Best answers
0
Ratings
64 1
Points
28
#1
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

Corporate Member
Corporate Member
Premium Member
Joined
Jun 18, 2018
Messages
22
Best answers
0
Ratings
12 4
Points
3
#2
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
Joined
Jan 18, 2017
Messages
279
Best answers
1
Ratings
63 3
Points
28
#3
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
Joined
Jun 14, 2016
Messages
884
Best answers
0
Ratings
64 1
Points
28
#4
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:
[[email protected] ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           971        794        177          0        237        432
-/+ buffers/cache:        124        847
Swap:            0          0          0
Code:
[[email protected] ~]# sync; echo 3 > /proc/sys/vm/drop_caches
After purged RAM

Code:
[[email protected] ~]# 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
Joined
Jun 22, 2017
Messages
169
Best answers
1
Ratings
52 1
Points
28
#9
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
Joined
Jun 14, 2016
Messages
884
Best answers
0
Ratings
64 1
Points
28
#10
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
Joined
Jun 22, 2017
Messages
169
Best answers
1
Ratings
52 1
Points
28
#11
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

Global Mod
Staff Member
Joined
May 3, 2016
Messages
1,489
Best answers
4
Ratings
371 8
Points
83
#14
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
 
Joined
Jun 3, 2018
Messages
25
Best answers
0
Ratings
5 1
Points
3
#12
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

New member
Joined
Jun 19, 2018
Messages
10
Best answers
0
Ratings
3
Points
3
#13
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
 
Latest Threads
Replies
0
Views
10
Replies
0
Views
22
Replies
5
Views
28

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads