Is there a way to flush used ram? without rebooting?

a reboot schedule is already scheduled every 4:30am but sometimes (like once every week) the device runs out of memory an i am unable to access it.
i can still use the wifi and lan but is very slow (maybe because of the full memory).
i need to physically unplug the device ang replug it before i can access it.

is there a way to schedule a "memory flush"? so i can recover some memory so the device won't run out of memory.

the device is uses a switch and mesh gateway.

OpenWRT 19.07.4 - Archer C50v4 - Memory available decreasing

2 Likes

i only recovered 2mb? :frowning:

You should probably figure out which service is using the most of your RAM and restart it on schedule.

2 Likes

Note that

  • You can't recover memory in actual use (by kernel or applications)
  • You can mainly recover memory reserved for buffers and caches.

"3" might free a bit more than "1".

sync; echo 3 > /proc/sys/vm/drop_caches

You might read e.g.
https://www.kernel.org/doc/Documentation/sysctl/vm.txt

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab objects like dentries and inodes. Once dropped, their memory becomes free.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects. To increase the number of objects freed by this operation, the user may run `sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the number of dirty objects on the system and create more candidates to be dropped.

This file is not a means to control the growth of the various kernel caches (inodes, dentries, pagecache, etc...) These objects are automatically reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems. Since it discards cached objects, it may cost a significant amount of I/O and CPU to recreate the dropped objects, especially if they were under heavy use. Because of this, use outside of a testing or debugging environment is not recommended.

4 Likes