Why You Should Use ZRAM on Your Raspberry Pi

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 92

  • @Nik.leonard
    @Nik.leonard ปีที่แล้ว +60

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

    • @GaryExplains
      @GaryExplains  ปีที่แล้ว +7

      🤣😜

    • @AndersHass
      @AndersHass ปีที่แล้ว +6

      Swap memory pages to cloud storage, lol

    • @ottomanherox
      @ottomanherox ปีที่แล้ว

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

    • @martaostrowska6373
      @martaostrowska6373 6 วันที่ผ่านมา

      On windows : downloading free ram 101% hahaha this is a virus

  • @Henfredemars
    @Henfredemars ปีที่แล้ว +18

    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 ปีที่แล้ว

      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 ปีที่แล้ว

      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 ปีที่แล้ว

      @@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 ปีที่แล้ว +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 ปีที่แล้ว +2

      @@Henfredemars Will look into it, thanks.

  • @middleclasspoor
    @middleclasspoor ปีที่แล้ว +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  ปีที่แล้ว +1

      Good to hear that it helped 👍

    • @ramkumar-vn4qq
      @ramkumar-vn4qq 5 หลายเดือนก่อน

      and your sd card / Disk will last longer

  • @dishcleaner2
    @dishcleaner2 8 หลายเดือนก่อน +2

    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.

  • @AmyGrrl78
    @AmyGrrl78 ปีที่แล้ว +2

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

  • @WR3ND
    @WR3ND หลายเดือนก่อน

    Testing now on my Pi 5 8GB while stress testing the CPU and GPU and RAM and it seems to be working splendidly. 7.12GB RAM in use out of 7.86GB and 0K out of 456M in swap. Fantastic! Normally swap is almost full in this test load.

    • @GaryExplains
      @GaryExplains  หลายเดือนก่อน +1

      That's great to hear! ZRAM is a very useful tool for Raspberry Pis.

  • @EngineerLewis
    @EngineerLewis ปีที่แล้ว +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  ปีที่แล้ว

      Great to hear! 👍

    • @DoubtingThomas333
      @DoubtingThomas333 11 หลายเดือนก่อน

      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.

  • @rastamouse7861
    @rastamouse7861 10 หลายเดือนก่อน

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

  • @zk_6312
    @zk_6312 ปีที่แล้ว +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.

  • @AHumanBeingbeing
    @AHumanBeingbeing ปีที่แล้ว +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  ปีที่แล้ว +1

      I am glad it was useful 👍

  • @tonysheerness2427
    @tonysheerness2427 ปีที่แล้ว +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.

  • @DaveJones-Waveform
    @DaveJones-Waveform ปีที่แล้ว +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.

  • @Ludecan
    @Ludecan ปีที่แล้ว

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

  • @BillyNoMates1974
    @BillyNoMates1974 ปีที่แล้ว

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

    • @GaryExplains
      @GaryExplains  ปีที่แล้ว

      Glad it helped!

    • @BillyNoMates1974
      @BillyNoMates1974 ปีที่แล้ว +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

  • @henrysu2566
    @henrysu2566 ปีที่แล้ว

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

  • @SprocketN
    @SprocketN ปีที่แล้ว +6

    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  ปีที่แล้ว +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 ปีที่แล้ว +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.

  • @PaulSpades
    @PaulSpades ปีที่แล้ว +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.

  • @joegee2815
    @joegee2815 ปีที่แล้ว

    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.

  • @ThatEntityGirl
    @ThatEntityGirl 8 หลายเดือนก่อน

    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

  • @dezmondwhitney1208
    @dezmondwhitney1208 ปีที่แล้ว

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

  • @srinivasprasad837
    @srinivasprasad837 ปีที่แล้ว

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

  • @chromerims
    @chromerims ปีที่แล้ว

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

  • @namangupta86
    @namangupta86 ปีที่แล้ว +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.

  • @disdroid
    @disdroid ปีที่แล้ว

    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 ปีที่แล้ว

    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?

  • @lohikarhu734
    @lohikarhu734 ปีที่แล้ว

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

  • @OmidAtaollahi
    @OmidAtaollahi ปีที่แล้ว +1

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

  • @breevwhyman2985
    @breevwhyman2985 ปีที่แล้ว

    Sir, is there an MSOFT equivalent?

  • @ag.cousins
    @ag.cousins ปีที่แล้ว +5

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

    • @GaryExplains
      @GaryExplains  ปีที่แล้ว +6

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

    • @WatsitTooyah
      @WatsitTooyah 10 หลายเดือนก่อน

      @@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 ปีที่แล้ว

    I'm waiting for your tensor g3 explanation video

  • @SensSword
    @SensSword ปีที่แล้ว

    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.

  • @willgilliam9053
    @willgilliam9053 ปีที่แล้ว +2

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

  • @muddyexport5639
    @muddyexport5639 ปีที่แล้ว

    Good info, thanks!

  • @LuisWOLF-tz5th
    @LuisWOLF-tz5th 3 หลายเดือนก่อน

    I have to tell you amazing for real fast it is am using a raspberry pi 3 A+

  • @G-Vecom
    @G-Vecom 3 หลายเดือนก่อน

    how you edit those file

    • @GaryExplains
      @GaryExplains  3 หลายเดือนก่อน

      Which files? With a text editor, unless I am misunderstanding you.

  • @cpuuk
    @cpuuk ปีที่แล้ว +2

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

  • @gavskuzz
    @gavskuzz ปีที่แล้ว

    👌👌👌👏👏👏

  • @bertvantol9669
    @bertvantol9669 2 หลายเดือนก่อน

    Maybe some stupid questions .... ;-)
    1. Does the ZRAM installation works the same on different Linux Desktop Environments ??
    2. Does the ZRAM installation works the same on a PC ??

    • @GaryExplains
      @GaryExplains  2 หลายเดือนก่อน +1

      This is a basic kernel feature and should be the same across CPU types and Linux distros.

  • @lohikarhu734
    @lohikarhu734 ปีที่แล้ว

    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 ปีที่แล้ว +2

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

  • @felipelorenzon2450
    @felipelorenzon2450 ปีที่แล้ว

    Do this on windows 10!!

  • @PaulSpades
    @PaulSpades ปีที่แล้ว

    Sooo... We can download RAM.

  • @whothefoxcares
    @whothefoxcares ปีที่แล้ว +5

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

  • @loc4725
    @loc4725 ปีที่แล้ว +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 ปีที่แล้ว

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

    • @loc4725
      @loc4725 ปีที่แล้ว +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 ปีที่แล้ว

      @@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 ปีที่แล้ว +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 ปีที่แล้ว

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

  • @Juttutin
    @Juttutin ปีที่แล้ว

    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  ปีที่แล้ว

      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 ปีที่แล้ว

      @@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  ปีที่แล้ว +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 ปีที่แล้ว

      @@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  ปีที่แล้ว +1

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