Community discussions

MikroTik App
 
User avatar
ErfanDL
Member
Member
Topic Author
Posts: 366
Joined: Thu Sep 29, 2016 9:13 am

Simple script to clear memory space

Wed Jan 25, 2023 12:36 pm

Hi guys. Due to the problem of memory leakage after updating to version 7.7 of the router OS, you can free up the device's memory without rebooting the router board with a simple trick. Just run the following script every 24 hours to free up memory space.
tool/bandwidth-test address=127.0.0.1 protocol=udp duration=10
Good luck
 
leonardogyn
just joined
Posts: 18
Joined: Wed Dec 04, 2019 4:47 pm

Re: Simple script to clear memory space

Wed Jan 25, 2023 1:46 pm

Made no difference to me, tried on 4 boxes showing the memory 'leak' from v7.7
 
User avatar
ErfanDL
Member
Member
Topic Author
Posts: 366
Joined: Thu Sep 29, 2016 9:13 am

Re: Simple script to clear memory space

Wed Jan 25, 2023 2:22 pm

Made no difference to me, tried on 4 boxes showing the memory 'leak' from v7.7
It might work on some architectures. I tested on RB2011 and 45 MB of the occupied space was freed
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11439
Joined: Thu Mar 03, 2016 10:23 pm

Re: Simple script to clear memory space

Wed Jan 25, 2023 7:02 pm

If memory is consumed for various kernel buffers and cache, running bandwidth test may "free" it ... because kernel would give it to any process wanting some memory. If memory is "lost" due to memory leak, then it's used up as private memory by a running process as far as kernel is concerned and will not "free" it. The only way of freeing leaked memory (apart from rebooting device) is killing the process with leaked memory - in that case kernel would free also memory not freed explicitly by that process. But killing a particular process is not possible in ROS (at least not easily).

Here's memory stats from a "normal" linux machine:
user@host:~$ free
              total        used        free      shared  buff/cache   available
Mem:        8112488      661356      129056       86436     7322076     7054776

Out of 8GB only around 650MB is declared as free memory. However 7GB+ is used as buffers and cache by kernel and most of it (cache portion which is usually the bulk of it) can be freed if some application requires it. So for applications there's almost 7GB memory free (the last column: available).
If machine has a RAM disk (type tmpfs which is used when creating RAMdisk with basic ROS v7.8beta installation, no rose package), then space for files residing on that file system is included in figure in "shared" column.

I don't know which of these numbers (free or available) is actually reported by ROS.
 
leonardogyn
just joined
Posts: 18
Joined: Wed Dec 04, 2019 4:47 pm

Re: Simple script to clear memory space

Wed Jan 25, 2023 7:52 pm


I don't know which of these numbers (free or available) is actually reported by ROS.
.
I tried decoding supout file from 2 RB2011 boxes, found the "meminfo" section, but really couldn't figure out what number is shown at "System/Resources" on the Free Memory value. It doesn't seem to directly correlate to any information on the meminfo, specially not the MemFree value from there

That being said, comparing 2 RB2011 boxes, and knowing one is showing 42Mb of free RAM (of total 128Mb) and the other is presenting 56Mb as free, some hints can be taken from the decoded files:

1) both "free" and "available" numbers are indeed lower on the the 1st box (that shows 42Mb of free RAM on the ROS); 2) cached and buffers, which are heavily used on "regular" linux boxes, are almost identical on both boxes, as they are NOT "regular" linux boxes, and basically don't use I/O after booting, so caches and buffers remains almost intact; 3) heap memory usage, on the resolver process, is higher on 1st box, on a number almost "enough" to match the "free" memory difference among them

box 1:
MemTotal:         125700 kB
MemFree:           21820 kB
MemAvailable:      61752 kB
Buffers:            7764 kB
Cached:            36124 kB
.......
resolver heap memory
0042a000-01f3d000 rwxp 00000000 00:00 0          [heap]
Size:              28724 kB
.
box 2:
MemTotal:         125700 kB
MemFree:           35772 kB
MemAvailable:      75764 kB
Buffers:            7764 kB
Cached:            36200 kB
..........
resolver heap memory
0042a000-012e0000 rwxp 00000000 00:00 0          [heap]
Size:              15064 kB
Last edited by leonardogyn on Wed Jan 25, 2023 8:01 pm, edited 4 times in total.
 
leonardogyn
just joined
Posts: 18
Joined: Wed Dec 04, 2019 4:47 pm

Re: Simple script to clear memory space

Wed Jan 25, 2023 7:54 pm

and while I agree that some process might force freeing of some kind of memory, specially "available" but not "free" memory, it doesn't seem to be affecting, at all, this high memory usage me (and others) are experiencing, as it really seem to be "leaked" (aka lost) memory, and not memory that can be claimed if needed anymore
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19104
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Simple script to clear memory space

Wed Jan 25, 2023 8:40 pm

Hi guys. Due to the problem of memory leakage after updating to version 7.7 of the router OS, you can free up the device's memory without rebooting the router board with a simple trick. Just run the following script every 24 hours to free up memory space.
tool/bandwidth-test address=127.0.0.1 protocol=udp duration=10
Good luck
Unless MT is recommending such ideas, I would not recommend doing it....
 
holvoetn
Forum Guru
Forum Guru
Posts: 5404
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Simple script to clear memory space

Wed Jan 25, 2023 8:53 pm

The script on itself is rather harmless. Just a bandwidth test on the local loopback port.
You should try it once. Very enlightening results come out of it ;)
 
leonardogyn
just joined
Posts: 18
Joined: Wed Dec 04, 2019 4:47 pm

Re: Simple script to clear memory space

Wed Jan 25, 2023 9:15 pm

The script on itself is rather harmless. Just a bandwidth test on the local loopback port.
You should try it once. Very enlightening results come out of it ;)
.
Yeah ... it's just calling an internal tool from the RouterOS, it's not a "script" actually, just a single command. It can't do any harm at all. Nor any difference to my boxes, but it's harmless for sure!
 
User avatar
ErfanDL
Member
Member
Topic Author
Posts: 366
Joined: Thu Sep 29, 2016 9:13 am

Re: Simple script to clear memory space

Thu Jan 26, 2023 9:59 am

Test result after 21 hours. 75 MB of memory is still available.
Screenshot 2023-01-26 112650.jpg
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: eworm, raiod and 82 guests