Why You Should Use ZRAM on Your Raspberry Pi

Поділитися
Вставка
  • Опубліковано 2 жов 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
  • Наука та технологія

КОМЕНТАРІ • 85

  • @Nik.leonard
    @Nik.leonard 10 місяців тому +57

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

    • @GaryExplains
      @GaryExplains  10 місяців тому +7

      🤣😜

    • @AndersHass
      @AndersHass 10 місяців тому +5

      Swap memory pages to cloud storage, lol

    • @ottomanherox
      @ottomanherox 8 місяців тому

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

  • @satysin630
    @satysin630 10 місяців тому +20

    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.

  • @middleclasspoor
    @middleclasspoor 10 місяців тому +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!

    • @GaryExplains
      @GaryExplains  10 місяців тому +1

      Good to hear that it helped 👍

    • @ramkumar-vn4qq
      @ramkumar-vn4qq 18 днів тому

      and your sd card / Disk will last longer

  • @Henfredemars
    @Henfredemars 10 місяців тому +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 10 місяців тому

      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 10 місяців тому

      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 10 місяців тому

      @@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 10 місяців тому +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 10 місяців тому +1

      @@Henfredemars Will look into it, thanks.

  • @rastamouse7861
    @rastamouse7861 5 місяців тому

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

  • @AmyGrrl78
    @AmyGrrl78 10 місяців тому +1

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

  • @Ludecan
    @Ludecan 10 місяців тому

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

  • @zk_6312
    @zk_6312 10 місяців тому +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.

  • @EngineerLewis
    @EngineerLewis 10 місяців тому +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  10 місяців тому

      Great to hear! 👍

    • @DoubtingThomas333
      @DoubtingThomas333 6 місяців тому

      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.

  • @dezmondwhitney1208
    @dezmondwhitney1208 10 місяців тому

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

  • @chromerims
    @chromerims 9 місяців тому

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

  • @joegee2815
    @joegee2815 10 місяців тому

    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.

  • @henrysu2566
    @henrysu2566 10 місяців тому

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

  • @dishcleaner2
    @dishcleaner2 3 місяці тому +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.

  • @cwegescheide1
    @cwegescheide1 10 місяців тому +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

    • @GaryExplains
      @GaryExplains  10 місяців тому +1

      I am glad it was useful 👍

  • @BillyNoMates1974
    @BillyNoMates1974 10 місяців тому

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

    • @GaryExplains
      @GaryExplains  10 місяців тому

      Glad it helped!

    • @BillyNoMates1974
      @BillyNoMates1974 10 місяців тому +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

  • @muddyexport5639
    @muddyexport5639 10 місяців тому

    Good info, thanks!

  • @tonysheerness2427
    @tonysheerness2427 10 місяців тому +4

    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.

  • @disdroid
    @disdroid 7 місяців тому

    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!

  • @lamkhatinh8344
    @lamkhatinh8344 10 місяців тому

    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?

  • @OmidAtaollahi
    @OmidAtaollahi 9 місяців тому +1

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

  • @PaulSpades
    @PaulSpades 10 місяців тому +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.

  • @SprocketN
    @SprocketN 10 місяців тому +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  10 місяців тому +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 10 місяців тому +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.

  • @ThatEntityGirl
    @ThatEntityGirl 3 місяці тому

    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

  • @namangupta86
    @namangupta86 10 місяців тому +3

    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.

  • @ag.cousins
    @ag.cousins 10 місяців тому +5

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

    • @GaryExplains
      @GaryExplains  10 місяців тому +6

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

    • @WatsitTooyah
      @WatsitTooyah 4 місяці тому

      @@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.

  • @clementroyc
    @clementroyc 10 місяців тому

    I'm waiting for your tensor g3 explanation video

  • @srinivasprasad837
    @srinivasprasad837 7 місяців тому

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

  • @stephenjohnstone9940
    @stephenjohnstone9940 10 місяців тому

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

  • @DaveJones-Waveform
    @DaveJones-Waveform 10 місяців тому +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.

  • @breevwhyman2985
    @breevwhyman2985 9 місяців тому

    Sir, is there an MSOFT equivalent?

  • @lohikarhu734
    @lohikarhu734 9 місяців тому

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

  • @cpuuk
    @cpuuk 10 місяців тому +2

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

  • @gavinskurrie
    @gavinskurrie 10 місяців тому

    👌👌👌👏👏👏

  • @willgilliam9053
    @willgilliam9053 10 місяців тому +2

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

  • @felipelorenzon2450
    @felipelorenzon2450 10 місяців тому

    Do this on windows 10!!

  • @SensSword
    @SensSword 10 місяців тому

    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.

  • @loc4725
    @loc4725 10 місяців тому +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 10 місяців тому

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

    • @loc4725
      @loc4725 10 місяців тому +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 10 місяців тому

      @@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 10 місяців тому +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 10 місяців тому

      ​@@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!

  • @PaulSpades
    @PaulSpades 10 місяців тому

    Sooo... We can download RAM.

  • @lohikarhu734
    @lohikarhu734 9 місяців тому

    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...

  • @devjock
    @devjock 10 місяців тому +1

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

  • @whothefoxcares
    @whothefoxcares 10 місяців тому +5

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

  • @Juttutin
    @Juttutin 10 місяців тому

    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  10 місяців тому

      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 10 місяців тому

      @@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  10 місяців тому +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 10 місяців тому

      @@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  10 місяців тому +1

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