Trunk -- flush used memory

Is there ane way to flush used memory without reboot?

Please note that uptime is only 3 days!

1 Like

Thanks but I cannot see significant difference:

What exactly did you expect to see?

Something like that:

That is state just after reboot, uptime 3 minutes.

And which services are running on OpenWrt?

At this moment it looks like some memory leaks.

Here is ps output:

root@router:~# ps -w
  PID USER       VSZ STAT COMMAND
    1 root      1624 S    /sbin/procd
    2 root         0 SW   [kthreadd]
    3 root         0 IW<  [rcu_gp]
    4 root         0 IW<  [rcu_par_gp]
    5 root         0 IW   [kworker/0:0-rcu]
    6 root         0 IW<  [kworker/0:0H-ev]
    7 root         0 IW   [kworker/u8:0-ev]
    8 root         0 IW<  [mm_percpu_wq]
    9 root         0 SW   [ksoftirqd/0]
   10 root         0 IW   [rcu_sched]
   11 root         0 SW   [migration/0]
   12 root         0 SW   [cpuhp/0]
   13 root         0 SW   [cpuhp/1]
   14 root         0 SW   [migration/1]
   15 root         0 SW   [ksoftirqd/1]
   17 root         0 IW<  [kworker/1:0H-kb]
   18 root         0 SW   [cpuhp/2]
   19 root         0 SW   [migration/2]
   20 root         0 SW   [ksoftirqd/2]
   22 root         0 IW<  [kworker/2:0H-ev]
   23 root         0 SW   [cpuhp/3]
   24 root         0 SW   [migration/3]
   25 root         0 SW   [ksoftirqd/3]
   27 root         0 IW<  [kworker/3:0H-kb]
   28 root         0 IW<  [netns]
   29 root         0 IW   [kworker/u8:1-ev]
  123 root         0 IW   [kworker/2:1-rcu]
  159 root         0 SW   [oom_reaper]
  160 root         0 IW<  [writeback]
  161 root         0 SW   [kcompactd0]
  167 root         0 IW<  [pencrypt_serial]
  169 root         0 IW<  [pdecrypt_serial]
  170 root         0 IW   [kworker/1:1-eve]
  181 root         0 IW<  [kblockd]
  182 root         0 IW<  [blkcg_punt_bio]
  194 root         0 IW<  [kworker/u9:0]
  198 root         0 SW   [watchdogd]
  220 root         0 SW   [kswapd0]
  302 root         0 IW<  [kthrotld]
  330 root         0 IW   [kworker/3:1-eve]
  337 root         0 SW   [spi0]
  411 root         0 IW<  [ipv6_addrconf]
  412 root         0 IW<  [dsa_ordered]
  418 root         0 IW   [kworker/3:2-rcu]
  473 root         0 IW   [kworker/0:2-eve]
  501 root         0 SW   [jfsIO]
  502 root         0 SW   [jfsCommit]
  503 root         0 SW   [jfsCommit]
  504 root         0 SW   [jfsCommit]
  505 root         0 SW   [jfsCommit]
  506 root         0 SW   [jfsSync]
  508 root         0 SW   [irq/28-keys]
  520 root         0 IW<  [ata_sff]
  532 root         0 SW   [scsi_eh_0]
  533 root         0 IW<  [scsi_tmf_0]
  537 root         0 SW   [scsi_eh_1]
  538 root         0 IW<  [scsi_tmf_1]
  582 root         0 IW   [kworker/1:3-eve]
  590 root         0 IW<  [kworker/2:2H]
  593 root         0 IW<  [kworker/1:2H]
  594 root         0 SW   [scsi_eh_2]
  595 root         0 IW<  [scsi_tmf_2]
  596 root         0 SW   [usb-storage]
  697 root         0 SWN  [jffs2_gcd_mtd6]
  777 ubus      1276 S    /sbin/ubusd
  780 root       940 S    /sbin/askfirst /usr/libexec/login.sh
  827 root      1044 S    /sbin/urngd
  883 root         0 IW   [kworker/2:2-eve]
  965 root         0 IW<  [cfg80211]
 1405 logd      9400 S    /sbin/logd -S 8192
 1406 root      1400 S    /sbin/logread -f -F /mnt/sdb1/log/messages.log -p /var/run/logread.1.pid -S 8192
 1458 root      2216 S    /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30
 1512 root         0 IW<  [kworker/3:2H]
 1616 root      1148 S    /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 -K 300 -T 3
 1717 root      2240 S    /usr/sbin/hostapd -s -g /var/run/hostapd/global
 1777 root      1768 S    /sbin/netifd
 1834 root      1480 S    /usr/sbin/odhcpd
 1888 root      1264 S    /usr/sbin/crond -f -c /etc/crontabs -l 5
 1950 root      4560 S    /usr/sbin/uhttpd -f -h /www -r router -x /cgi-bin -u /ubus -t 60 -T 30 -k 20 -A 1 -n 3 -N 100 -R -p 0.0.0
 2002 root      1488 S    /sbin/blockd
 2109 root         0 IW<  [kworker/0:2H]
 2638 root      1264 S<   /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.o
 3084 dnsmasq   1408 S    /usr/sbin/dnsmasq -C /var/etc/dnsmasq.conf.cfg01411c -k -x /var/run/dnsmasq/dnsmasq.cfg01411c.pid
 3253 root      1260 S    udhcpc -p /var/run/udhcpc-wan.pid -s /lib/netifd/dhcp.script -f -t 0 -i wan -x hostname:router -C -R -O 1
 3321 root      1208 R    /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 -K 300 -T 3
 3322 root      1280 S    -ash
 3400 root         0 IW   [kworker/u8:2-ev]
 3406 root      1260 R    ps -w

I could argue on why you have allocated 8MB for logging.
Anyway, do a du -sh /tmp before and after. I suspect it is just temporary files.

1 Like

This morning:

root@router:~# du -sh /tmp
256.0K  /tmp
root@router:~# sync; echo 1 > /proc/sys/vm/drop_caches
root@router:~# du -sh /tmp
256.0K  /tmp

p.s. cashed memory remains the same:

Dropping caches will not release memory which is used by other programs.
Let the memory grow a bit and then run the du command to see if the /tmp has grown too.

1 Like

Dropping caches should never be done by the user, it's a debugging knob. If you actually believe you know how to manage memory better than the kernel, you're wrong.

1 Like

OK, I understand, but now it looks like some memory leaks.

Try restarting services one by one and see if there's a change.

Could you post the output of "cat /proc/meminfo"? Might reveal something.

At this moment situation quite well

root@router:~# cat /proc/meminfo
MemTotal:         511276 kB
MemFree:          459172 kB
MemAvailable:     423000 kB
Buffers:            1588 kB
Cached:             6536 kB
SwapCached:            0 kB
Active:             6560 kB
Inactive:           4048 kB
Active(anon):       2672 kB
Inactive(anon):       68 kB
Active(file):       3888 kB
Inactive(file):     3980 kB
Unevictable:           0 kB
Mlocked:               0 kB
HighTotal:        262144 kB
HighFree:         247204 kB
LowTotal:         249132 kB
LowFree:          211968 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          2484 kB
Mapped:             5204 kB
Shmem:               256 kB
KReclaimable:       3064 kB
Slab:              16288 kB
SReclaimable:       3064 kB
SUnreclaim:        13224 kB
KernelStack:         720 kB
PageTables:          332 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      255636 kB
Committed_AS:      13356 kB
VmallocTotal:    1040376 kB
VmallocUsed:        4664 kB
VmallocChunk:          0 kB
Percpu:              416 kB

Pure guess, but as you have a crontab file, you might be running some heavy updating task by cron, e.g. downloading and processing some huge adblock blocklists. That kind of activity might reserve memory that could then stay cached.

cron's tasks are very simple:

root@router:~# cat /etc/crontabs/root
0 0 * * * /usr/sbin/logrotate -v -f /etc/logrotate.conf
15 0 * * * opkg update
0 1 * * * fstrim -v /mnt/sda1/ | logger -t fstrim

What's the filesystem on /dev/sda1? If it's a regular Linux FS like ext4, xfs, etc it's probably cool. If it's something like NTFS (using ntfs-3g), you could give unmounting the drive a shot to see if it's causing the memory allocation.

fs is f2fs