Why You Should Use ZRAM on Your Raspberry Pi

Sdílet
Vložit
  • čas přidán 2. 10. 2023
  • One way to improve the performance of a Raspberry Pi, especially those models with less memory, is to add ZRAM. This will cause Linux to swap to compressed memory rather than to the SD card. In this video I look at the concepts of swapping and show you how to setup ZRAM on your Pi board.
    ---
    github.com/garyexplains/examp...
    Let Me Explain T-shirt: teespring.com/gary-explains-l...
    Twitter: / garyexplains
    Instagram: / garyexplains
    #garyexplains
  • Věda a technologie

Komentáře • 85

  • @Nik.leonard
    @Nik.leonard Před 9 měsíci +56

    Enabling Zram on a linux system is the nearest thing to actually downloading more ram.

    • @GaryExplains
      @GaryExplains  Před 9 měsíci +7

      🤣😜

    • @AndersHass
      @AndersHass Před 8 měsíci +5

      Swap memory pages to cloud storage, lol

    • @ottomanherox
      @ottomanherox Před 6 měsíci

      @@GaryExplains amazing video mate, every video tutorial I've found enable Zram but don't tweak swap parameters, great documentation!

  • @middleclasspoor
    @middleclasspoor Před 9 měsíci +17

    I have a RPI 3b w/ 1GB that has been running BOINC for years now, the swap was always %100 full and even leaving 1 cpu free from BOINC still not as responsive as I would like.....installed zram-tools and the system now has over 200MB free swap and is now noticeably more responsive!...Thank you Gary for the great info (as usual!).....now on to my other Linux boxes to do the same!

  • @satysin630
    @satysin630 Před 9 měsíci +18

    I always found it strange zram wasn't the default in Raspberry Pi OS over a swap file (perhaps with a swap file/partition as fall back) as it not only makes memory go further it also reduces SSD wear from swap. Fedora has used zram rather than swap for a while now and it is how I setup all Linux desktops now.

  • @Henfredemars
    @Henfredemars Před 9 měsíci +16

    If a person cares about squeezing memory performance on the Pi, combine ZRAM or ZSWAP with mg-lru which provides massive improvements in memory system performance. Picking which pages to swap (the greatly improved MG-LRU over simple least recently used page) matters as much as what happens during the swapping operation (ZRAM and ZSWAP). New Androids ship MG-LRU which focuses on reducing memory pressure far more effectively than the default algorithm.
    I would argue switching to MG-LRU is even easier than configuring ZRAM, and the effects stack.

    • @juanmondragon
      @juanmondragon Před 9 měsíci

      If that's the case then I wouldn't recommend a raspberry pi for a person that is trying to do all of that. I would recommend a slightly better hardware

    • @photoniccannon2117
      @photoniccannon2117 Před 9 měsíci

      You’re generally better off just using ZSWAP rather than combining them. If you try to combine them, a page might get kicked out of the ZRAM pool only to be recompressed and stored in RAM again for ZSWAP.

    • @Henfredemars
      @Henfredemars Před 9 měsíci

      @@juanmondragon You're probably right, but where is the fun in that? I do numerical computing on them because I can, not because it's a good idea.

    • @Henfredemars
      @Henfredemars Před 9 měsíci +2

      @@photoniccannon2117 I don't recommend combining ZRAM and ZSWAP, but I do recommend using MG-LRU with one of those solutions so you get better page selection.

    • @photoniccannon2117
      @photoniccannon2117 Před 9 měsíci +1

      @@Henfredemars Will look into it, thanks.

  • @dishcleaner2
    @dishcleaner2 Před 2 měsíci +1

    Zram is absolutely brilliant. I'm surprised I had never heard about in college when I was studying IT or in my career. My Pi Zero 2W is actually a useful system for web browsing now.

  • @rastamouse7861
    @rastamouse7861 Před 4 měsíci

    I've tried this on the RPi 3A+ and can confirm that it helped tremendously!

  • @Ludecan
    @Ludecan Před 8 měsíci

    This explanation was amazing. Thanks for sharing, finally got the point of why and when this is useful

  • @zk_6312
    @zk_6312 Před 8 měsíci +1

    This was really interesting. I had never heard of zram before. I might have to try this on one of my slow raspberry pi zeros.

  • @dezmondwhitney1208
    @dezmondwhitney1208 Před 8 měsíci

    Very helpful video. I, for one , learnt something useful to me. Thank You.

  • @AmyGrrl78
    @AmyGrrl78 Před 8 měsíci +1

    I pre-ordered a Raspberry Pi 5 8GB. Looking forward to giving this a try on it when it arrives.

  • @chromerims
    @chromerims Před 8 měsíci

    Very cool info on ZRAM for rPi's . . . Thank you! 👍

  • @joegee2815
    @joegee2815 Před 9 měsíci

    This was very interesting. I will try that next time I'm playing with the Rpi. Waiting for the version 5 to come available retail.

  • @EngineerLewis
    @EngineerLewis Před 9 měsíci +3

    Just used this on my Orange Pi Zero 3 with 4GB memory and also on a Raspberry Pi3 B+ with 1GB memory and saw a good improvement for the RPi. Thanks for this video Gary - excellent help as usual.😅

    • @GaryExplains
      @GaryExplains  Před 9 měsíci

      Great to hear! 👍

    • @DoubtingThomas333
      @DoubtingThomas333 Před 5 měsíci

      Under 8gb you should use 2.5X memory as swap. You need space for hibernation (if you want to use it, so need a minimum 1:1 of system ram), normal swap and zram.
      Above 8gb, 1.5X ram is fine.

  • @DaveJones-Waveform
    @DaveJones-Waveform Před 9 měsíci +2

    Also worth having a look at zswap (bearing in mind it requires a persistent swap file to back it, unlike zram which can operate without anything on disk). IIRC, zswap is preferable in those cases where a swap file already exists, which is why I made it the default on the Ubuntu Pi desktop images where we ensure there's always a swapfile, but not on the server images (where there's a lot more variation in configuration, including those circumstances where people want read-only media).
    I'm not sure there's any benefit (and there may well be downsides, including the obvious "more code == more overhead") to having both systems active at once. I would recommend selecting one based on circumstance, and (following Gary's excellent example!) testing it actually improves your experience.

  • @henrysu2566
    @henrysu2566 Před 9 měsíci

    Really useful for low memory devices. Ths for you Gray.

  • @BillyNoMates1974
    @BillyNoMates1974 Před 9 měsíci

    thanks for the tip.
    this has been really helpful on my Raspberry Pi Zero 2W running OpenWebSDR Plus server.

    • @GaryExplains
      @GaryExplains  Před 9 měsíci

      Glad it helped!

    • @BillyNoMates1974
      @BillyNoMates1974 Před 9 měsíci +1

      @@GaryExplains I am still impressed that a £17 computer can run as a software defined radio. thats quite a tall task to do and quite a bit of CPU grunt needed, especially to decode signals on the fly all through a web server

  • @disdroid
    @disdroid Před 6 měsíci

    it took me a while to work out what was going on with my htop - i'd been watching the terminal in the video instead of the one on my desktop!

  • @cwegescheide1
    @cwegescheide1 Před 9 měsíci +1

    Awesome! I love my RP Zero 2w. I have Ubuntu and MariaDB on it. I run it like a little server downloading various feeds and loading to the database. Its amazing what you can do with such limited resources and this gives it even better performance! Ive got a few RP 4's in the box with dust on em waiting until I bring the zero to its knees.. Now the 4's are gonna have to wait even longer 😂 Thanks Gary!! You da man

  • @tonysheerness2427
    @tonysheerness2427 Před 9 měsíci +3

    ZRAM should be installed with the operating system. Thanks Garry I installed it on my I5 with 16gb memory and it has made it more responsive.

  • @muddyexport5639
    @muddyexport5639 Před 8 měsíci

    Good info, thanks!

  • @OmidAtaollahi
    @OmidAtaollahi Před 8 měsíci +1

    I never understood zram correctly. But this time it was different.😍

  • @PaulSpades
    @PaulSpades Před 8 měsíci +1

    This reminds me of the windows feature that used usb flash memory as swap space. USB2 was faster than hard drives for a few years, at least the 5200rpm laptop drives.
    Yes, it's not the same thing. This thing maps a compressed swap space in ram, as far as I understood it.

  • @ThatEntityGirl
    @ThatEntityGirl Před 2 měsíci

    I tried to run a modern java mincraft server on a raspberry pi 3b+ and it did not have nearly enough ram by itself. 1GB is the minimum memory allocation for the server to make it playable, and that takes up the entire RAM and then some.
    To solve it I essentially downloaded more ram by installing zram-tools and making my ENTIRE memory zram, along with bumping my swapfile up to 3 gigs. This setup works way better than it has any right to and I now have an inexpensive 24/7 minecraft server, lol

  • @SprocketN
    @SprocketN Před 9 měsíci +5

    It’s funny that 512Mb of RAM is too small to provide a practical machine. My Pi Zero 2W runs a mosquito server and Node-Red, but can’t run the web-browser to allow editing of the Node-Red flows or even display the dashboard.
    My first computer was a ZX81 with only 16k of memory and that could play chess against me and win! My Amiga 500 had 1Mb of RAM and a 10Mb hard-disc, at the time I thought was massive, I never filled the HDD.
    It seems that as memory has grown cheaper and therefore bigger our use of it has become less efficient, so we need programs to help us use it more efficiently.

    • @GaryExplains
      @GaryExplains  Před 9 měsíci +3

      Yes, but also what we do has increased in size and complexity. The average smartphone takes photos that wouldn't even fit into the RAM of an Amiga.

    • @SprocketN
      @SprocketN Před 9 měsíci +2

      @@GaryExplains True, but the programs I wrote back in the 80’s had the functions that were needed. Yet programs with the same functionality now are much bigger, probably to provide the graphical interface we’ve become accustomed to.
      My comment wasn’t a criticism, just an observation.

  • @ag.cousins
    @ag.cousins Před 9 měsíci +5

    What kind of psychopath uses Vi when you have nano right there

    • @GaryExplains
      @GaryExplains  Před 9 měsíci +5

      LOL, when I use nano in my videos people complain that I should use vi. I just can't win. 🤷‍♂️

    • @WatsitTooyah
      @WatsitTooyah Před 3 měsíci

      @@GaryExplains vi is pre-installed so I get it, but ugh it is a pain compared to vim lol. Simply because of not having confidence of what "mode" I'm in.

  • @namangupta86
    @namangupta86 Před 8 měsíci +2

    The reason I use zram is because I want to save my sd card. It will die much sooner if consistent writes and reads are done on that. Zram avoids that and keep everything in the ram itself.

  • @clementroyc
    @clementroyc Před 8 měsíci

    I'm waiting for your tensor g3 explanation video

  • @cpuuk
    @cpuuk Před 9 měsíci +2

    It worked for Johnny Mnemonic, so it should work for a Pi ;-)

  • @stephenjohnstone9940
    @stephenjohnstone9940 Před 9 měsíci

    Had 8gb Pi running at 64gb swap ram, running various emulators comfortably

  • @lamkhatinh8344
    @lamkhatinh8344 Před 9 měsíci

    Hello Gary, I have a question. If we use zram, we need some cpu resource to compress/decompress our data, right? Is it effect more about cpu resource?

  • @willgilliam9053
    @willgilliam9053 Před 9 měsíci +2

    Raspberry pi's, Linux desktops, Proxmox VM's..... ZRAMswap should be part of the kernel instead of a module thats installed

  • @srinivasprasad837
    @srinivasprasad837 Před 6 měsíci

    @Gary please do add information on rpi 4 2gb aswell in the GitHub file. Many of use are on the lower tier😅

  • @lohikarhu734
    @lohikarhu734 Před 8 měsíci

    Using an SD card for swapping must beat the heck out of available write cycles in then eerom?

  • @gavinskurrie
    @gavinskurrie Před 9 měsíci

    👌👌👌👏👏👏

  • @breevwhyman2985
    @breevwhyman2985 Před 8 měsíci

    Sir, is there an MSOFT equivalent?

  • @felipelorenzon2450
    @felipelorenzon2450 Před 9 měsíci

    Do this on windows 10!!

  • @SensSword
    @SensSword Před 8 měsíci

    5:00 should've opened Chome straight away. 2 tabs should be all you need to OOM for any system under 768GB of RAM. Double that if you'd like to open the dev tools tab.

  • @CanadianBakin42O
    @CanadianBakin42O Před 9 měsíci

    First 🥇😊

  • @lohikarhu734
    @lohikarhu734 Před 8 měsíci

    Funny that US Americans (there are more "Americans" than the USA!) insist that all the other English speakers say "zee", instead of " zed", when there are many more speakers of "proper" English...

  • @loc4725
    @loc4725 Před 9 měsíci +2

    "Zed" from Greek " Zet'a ", so you're correct. 😊 Where the American "zee" comes from I'm not sure.
    *Edit:*
    Nit'ch.
    Eye-raqh.
    Caché.
    Lincoln-Shire etc. 😊

    • @spinav8r
      @spinav8r Před 9 měsíci

      Yes, but Brits pronounce "Zeta" as Zee-ta. So, congratulations on your whingeing confusion. But hey, cheers mate!

    • @loc4725
      @loc4725 Před 9 měsíci +2

      @@spinav8r You sound like someone who needs a bit of help understanding how this works.
      The Greek Zet'a character (ζ) doesn't exist in English, but the _root derivation_ is pronounced "Zed" (Zet'a -> Zet' -> Zed). Where the hell "zee" comes from is unclear, but I always associate it with very young children as it tends to be easier for them to pronounce. Actually perhaps that is why some people prefer that pronunciation; they suffer from either cognitive or motor impairment in which case it's a kind of universal social adjustment which allows everyone to feel included or at least allows them to try to hide their unresolved speech problems?

    • @spinav8r
      @spinav8r Před 9 měsíci

      @@loc4725 - Then why do Brits pronounce Zeta as "Zee-ta?" I hear a "Zee" buried in there. I love your little arrows by the way. By responding to your comment, I'm giving you another chance to attempt to boost your self-asteem with more rambling rubbish about how (in some imaginary way) your lineage gives you intellectual superiority. Have at it, mate! I know you need this to get through the day. I wouldn't want to deprive you of that.

    • @loc4725
      @loc4725 Před 9 měsíci +2

      @@spinav8r *"Then why do Brits pronounce Zeta as "Zee-ta?"*
      I've *never* known any Brit to call Zet'a "zee-ta", but if you have a link to any examples I'd be willing to take a look.
      *" I love your little arrows by the way."*
      Err...thanks?
      *"By responding to your comment, I'm giving you another chance to attempt to boost your self-asteem with more rambling rubbish about how (in some imaginary way) your lineage gives you intellectual superiority."*
      That's interesting. Would you mind quoting the part where I try to "boost your self-asteem" by "rambling rubbish about" whatever?
      Also it's _esteem_ not "asteem". You're welcome.

    • @spinav8r
      @spinav8r Před 8 měsíci

      ​@@loc4725 - You said "You're welcome" before I had a chance to say "Thank you." I'll give you points for being proactive. I'm so glad to give you something to scour for you very apparent pedantic, sophomoric, juvenile personality. Perhaps we could arrange to have meetings with the rest of the English speaking world to make sure everyone pronounces words exactly as you. And yes, I can predict what you'll have to say about who qualifies as "English speaking" in your evaluation. If I don't qualify, I don't think I'll be able sleep at nights. Cheers Mate!

  • @devjock
    @devjock Před 8 měsíci +1

    Everyone in favor of calling ZRAM a "cramdisk"? ;)

  • @PaulSpades
    @PaulSpades Před 8 měsíci

    Sooo... We can download RAM.

  • @whothefoxcares
    @whothefoxcares Před 9 měsíci +5

    ZRAM abuse causes s-t-r-e-t-c-h marks in memory

  • @Juttutin
    @Juttutin Před 8 měsíci

    Ugh. No. Swapping in the modern era is a last resort to avoid crashing. Your environment should never be swapping when running normally. 20 years ago this might have made sense. Today it is idiotic to design for efficient swapping in virtually every context

    • @GaryExplains
      @GaryExplains  Před 8 měsíci

      Eh? So a Pi Zero has 512MB of RAM and you are saying that swapping is idiotic? Also it is generally accepted that swapping out dormant memory is better for a system as it frees memory for live processors, even when the system RAM is large.

    • @Juttutin
      @Juttutin Před 8 měsíci

      @@GaryExplains Yes. You're just wrong. Actually doubly wrong in this reply, where you seem to be suggesting swapping for swappings sake?! Or swapping rather than just getting hardware that is sized to your requirements. If I'm deploying a pi zero, I'm making sure everything is tight enough to nominally run inside that 512MB

    • @GaryExplains
      @GaryExplains  Před 8 měsíci +1

      Well I strongly disagree, in fact you even disagree with yourself. The way to stop crashing is to add swapping. Crashing is NEVER desirable. So swapping is essential, even today. Second swapping even when you gave enough RAM is still recommended, there are many articles about why, here is one haydenjames.io/linux-performance-almost-always-add-swap-space/

    • @Juttutin
      @Juttutin Před 8 měsíci

      @@GaryExplains I never said swap space wasn't necessary. I said swappING is a last resort. In modern systems, swap should always go on the lowest cost always-available media. Sacrificing actual RAM for swap is, yes, virtually always idiotic. About the only context it might make sense is when using e.g. a Pi Zero as your desktop; see prior sentence.

    • @GaryExplains
      @GaryExplains  Před 8 měsíci +1

      @@Juttutin Well most Android devices use ZRAM now and so do some Linux distros. But I guess you know better.