Why is OH using that much memory?

You can’t right now. There is a java API to force garbage collection.
You can write an service (not a binding) and drop that into the openHAB addons directory. That service could offer a REST endpoint or just perform garbage collection every 12 hours or so.

1 Like

Dear Colleagues,

I’m facing almost the same issue, but SWAP file is 100% used and RAM still have almost 25% available. I’m using a raspberry pi 3 with the following:

Openhabian OS
openHAB 2.5.5.

I’m not sure if it maybe a problem or not, however I have some questions:

-Does SWAP are totally used since of boot or not?
-Does SWAP are heavly used due to influxdb?
-Should I considered to increase SWAP file?
-Is it possible to know which services are consuming to much SWAP?

P.S. Does openhabian work on raspberry pi4?

[21:47:59] openhabian@openhabian:~$ swapon -s
Filename Type Size Used Priority
/var/swap file 102396 102396 -2
[21:49:39] openhabian@openhabian:~$ free -h
total used free shared buff/cache available
Mem: 975M 682M 39M 596K 254M 242M
Swap: 99M 99M 0B

Release = Raspbian GNU/Linux 9 (stretch)

Kernel = Linux 4.19.66-v7+

Platform = Raspberry Pi 3 Model B Rev 1.2

Uptime = 1 day(s). 10:52:29

CPU Usage = 5.67 % avg over 4 cpu(s) (4 core(s) x 1 socket(s))

CPU Load = 1m: 2.44, 5m: 2.29, 15m: 2.29

Memory = Free: 0.02GB (3%), Used: 0.92GB (97%), Total: 0.95GB

Swap = Free: 0.00GB (0%), Used: 0.09GB (100%), Total: 0.09GB

Root = Free: 21.68GB (79%), Used: 5.45GB (21%), Total: 28.31GB

Updates = 2 apt updates available.

Sessions = 1 sessions

Processes = 124 running processes of 32768 maximum processes

My understanding is openHABian does not yet support RPi4 as a SD card image but you should be able to clone the repo and run openhabian-config on a stock RaspberryOS Lite image. I could be behind in my knowledge though.

I’m not certain as I almost always disable swap but my understanding is it is the total currently in use.

Swap gets used when you have too much in RAM than you physically have RAM to hold. So it writes out stuff in RAM that hasn’t been used in awhile to the disk in the swap file. Disk is way slower than RAM so in general one should try to avoid stuff going to swap when possible.

Swap is owned and controlled by the operating system. No individual process uses swap directly.

This would probably at most just make it take longer for what ever the root problem is to start causing problems and likely slow down the machine significantly, not to mention increasing the writes to the SD card which will eventually wear it out.

1 Like

Afaik it does support RPi4:

1 Like

As of today, it does (except for the 8GB version). But OP has a RPi 3.

Swap is used ahead of time (read up on “paging”). I’d say there’s nothing wrong with mem use on your box.

But you have no ZRAM swap and just 100MB on SD card. That’s a pretty old setup.

Update openHABian and enable ZRAM.

You could also extend the swapfile but with ZRAM OH will no longer use much of it.

[16:47:38] root@openhabianpi:/srv/openhab2-addons# swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            707580  880     -2
/dev/zram0                              partition       614396  45456   75

PS: check if your real issue is with a memleak like that of amazonechobinding


Thanks so much for your answer guys, that’s why I love OH community! I will setup the ZRAM and let you guys know the result.

I would recommend setting your swap size to zero, reboot and double check. You do NOT want to be swapping to disk, ever. Especially when you’re using an SD card as your swap space.

That’s what ZRAM takes care of. It is used before the swapfile, but that should exist for safety reasons, it doesn’t really do harm to the SD card when it’s used once in ages.
BTW @mvo the proper way to change swapfile size is in /etc/dphys-swapfile.

Yes, ZRAM has been installed and it’s working. Please find the result now:

RAM decrease average from 75% to 70
SWAP decrease average from 100% to 2% only,.

Looks like that my system has better performance now! Thanks for your information and support so far!

This made me look at my own system. Running Linux on a PC hardware.

17062 openhab   20   0    8.1g   0.7g   0.0g S  16.7  3.4   1:29.34 java

100 things, 562 items, a bunch of jython rules.