Page 1 of 1

free some RAM

Posted: Mon Sep 16, 2019 8:45 am
by david_1234
hello ,
I have notice that my PI is sometime unavailable to reach by ssh , and the screen is freeze

this is what I get when I use "free -h " command

Code: Select all

free -h
              total        used        free      shared  buff/cache   available
Mem:           926M        657M         24M        216M        244M         14M
Swap:           99M         99M          0B

I can see I have a probelm
is there anything I can do ?

mayeb to up the swap to 1G?
the SD card is 16GB , and I only use ~7

Thanks ,

Re: free some RAM

Posted: Mon Sep 16, 2019 8:50 am
by jamesh
So, what is using up all the memory? And which Pi?

Adding swap will probably help a bit depending on the use case.

Re: free some RAM

Posted: Mon Sep 16, 2019 8:55 am
by david_1234
a java\node-JS application that run on the browser ?
this is what I have running on my PI3

Re: free some RAM

Posted: Mon Sep 16, 2019 9:03 am
by jamesh
david_1234 wrote:
Mon Sep 16, 2019 8:55 am
a java\node-JS application that run on the browser ?
this is what I have running on my PI3
Browser + Java == large memory demand. Swap would probably be the a good bet, or using a small SSD, or best would be upgrading to Pi4 with more RAM.

Re: free some RAM

Posted: Mon Sep 16, 2019 9:14 am
by david_1234
I'm waitng for PI4 to arrive - it will be next week ~

just to be sure
this is how I increase the SWAP ?

Code: Select all

sudo nano /etc/dphys-swapfile
change it to 1024?

Re: free some RAM

Posted: Mon Sep 16, 2019 9:32 am
by jahboater
david_1234 wrote:
Mon Sep 16, 2019 9:14 am
I'm waitng for PI4 to arrive - it will be next week ~

just to be sure
this is how I increase the SWAP ?

Code: Select all

sudo nano /etc/dphys-swapfile
change it to 1024?
Yes

Code: Select all

sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile restart

Re: free some RAM

Posted: Mon Sep 16, 2019 9:47 am
by david_1234
I did it the old way
but
Thank you!

Re: free some RAM

Posted: Mon Sep 16, 2019 9:54 am
by Fidelius
zram usually helps, too, in particular for machines with not-so-much RAM.

If I remember right, it's been part of previous versions of Raspbian, and it's still in Debian-based Ubuntu, so depending on which Raspbian version you use, you could activate it via:

Code: Select all

sudo apt install zram-config
To see what it is doing you can use:

Code: Select all

swapon --show
The new Debian-10 based Raspbian-10 unfortunately misses this package (does anybody know why?), so there we would have to download Ubuntu's package from kernel.org first…

Code: Select all

wget https://mirrors.kernel.org/ubuntu/pool/universe/z/zram-config/zram-config_0.5_all.deb
…and then install it:

Code: Select all

dpkg --install zram-config_0.5_all.deb

Re: free some RAM

Posted: Mon Sep 16, 2019 10:01 am
by david_1234
OK
and what does this do?
after download I need to change some setting ?

Thanks,

Re: free some RAM

Posted: Mon Sep 16, 2019 12:38 pm
by Fidelius
My linked Wikipedia page writes:
When used for swap, zram … allows Linux to make more efficient use of RAM, since the operating system can then hold more pages of memory in the compressed swap than if the same amount of RAM had been used as application memory or disk cache. This is particularly effective on machines that do not have much memory.
--
david_1234 wrote:
Mon Sep 16, 2019 10:01 am
after download I need to change some setting ?
No, by installing the package zram-config (with "dpkg --install" in the case of download, or with "apt" in case of being already in the apt-repository), a zram device is set up with a size up to half of your RAM size and used as swap device. I find this 50% setting to work well on my 1 GByte Pi3 and 4 GByte Pi4.

You can see the zram swap usuage with either the mentioned command:

Code: Select all

swapon --show
…or by using:

Code: Select all

zramctl
Both commands also show that zram distributes its swap RAM to all CPU cores in order to maximize the speed of de-/compression in the swap RAM.

With the latter command you can furthermore fine-tune its usage. Please see its man-page: man zramctl.

Re: free some RAM

Posted: Mon Sep 16, 2019 1:26 pm
by david_1234
OK ,
I have download like you told me

and this is what I get

Code: Select all

pi@raspberrypi:~ $ swapon --show
NAME      TYPE  SIZE   USED PRIO
/var/swap file 1024M 101.5M   -2

what does -2 mean?

when I try to run

Code: Select all

zramctl
I get nothing

Re: free some RAM

Posted: Mon Sep 16, 2019 1:52 pm
by Fidelius
Have you installed the downloaded ".deb" file?
Like:

Code: Select all

dpkg --install zram-config_0.5_all.deb
Maybe a re-boot is neccessary afterwards.

Re: free some RAM

Posted: Wed Sep 18, 2019 7:12 am
by david_1234
Yes , a reboot did the trick
now I get this :

Code: Select all

free -h
              total        used        free      shared  buff/cache   available
Mem:           926M        582M         79M         80M        264M        211M
Swap:          1.5G        590M        896M

zramctl
NAME       ALGORITHM DISKSIZE   DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo         115.8M 112.4M 23.6M 25.6M       4 [SWAP]
/dev/zram1 lzo         115.8M 112.3M 23.7M 25.6M       4 [SWAP]
/dev/zram2 lzo         115.8M 112.3M 23.4M 25.3M       4 [SWAP]
/dev/zram3 lzo         115.8M 112.7M 23.7M 25.6M       4 [SWAP]


can you expalin if what I see is good?
and does it mean?

Thanks ,

Re: free some RAM

Posted: Wed Sep 18, 2019 7:30 am
by Fidelius
That looks fine.

To see why zram helps, in particular users of slow SD-cards, please see my above Wikiepedia article or various other Linux articles, like for example Aarch-Linux's short explanation here. I couldn't explain it any better: Improving performance
The zram kernel module (previously called compcache) provides a compressed block device in RAM. If you use it as swap device, the RAM can hold much more information but uses more CPU. Still, it is much quicker than swapping to a hard drive. If a system often falls back to swap, this could improve responsiveness. Using zram is also a good way to reduce disk read/write cycles due to swap on SSDs.

Re: free some RAM

Posted: Wed Sep 18, 2019 7:35 am
by david_1234
Thanks .
I hope it will do the job until I start to woel with the PI4