Using zram and zswap in Linux

Поделиться
HTML-код
  • Опубликовано: 25 июл 2024
  • In this video I describe the differences between zram and zswap, their use cases, and how to set them up.
    Support the channel:
    BTC - 3NzWDDH3n5PsBKqWJyAb7rvsGvJKxcAPFv
    ETH - 0xB09212235c648a448F0E7eEB416ce5652362c772
    Follow me:
    SecureRandom on RUclips -
    / @securerandom5420
    SecureRandom on LBRY / Odysee -
    odysee.com/@SecureRandom:1
    ----------------------------------------------------
    zram commands:
    sudo vim /etc/modules-load.d/zram.conf
    zram
    sudo vim /etc/modprobe.d/zram.conf
    options zram num_devices=1
    sudo vim /etc/udev/rules.d/99-zram.rules
    KERNEL=="zram0", ATTR{disksize}="512M",TAG+="systemd"
    sudo vim /etc/systemd/system/zram.service
    [Unit]
    Description=Swap with zram
    After=multi-user.target
    [Service]
    Type=oneshot
    RemainAfterExit=true
    ExecStartPre=/sbin/mkswap /dev/zram0
    ExecStart=/sbin/swapon -p 5 /dev/zram0
    ExecStop=/sbin/swapoff /dev/zram0
    [Install]
    WantedBy=multi-user.target
    sudo systemctl enable zram
    ----------------------------------------------------
    zswap commands:
    Check if zswap is enabled / supported
    cat /sys/module/zswap/parameters/enabled
    sudo vim /etc/default/grub
    Add “zswap.enabled=1” to the line that starts with “GRUB_CMDLINE_LINUX”
  • НаукаНаука

Комментарии • 41

  • @LeeZhenYong
    @LeeZhenYong 2 года назад +7

    6:33 zswap is such a great feature! It seems to work similarly to how macOS compresses idle RAM. I have 16GB RAM and 10GB of swap, but decided to enable zswap anyway because it's just a much better use of resources.

    • @ivanrasierer3257
      @ivanrasierer3257 2 года назад +1

      Hello. Which zswap.max_pool_percent has better performance in this configuration?

  • @AmidMajd
    @AmidMajd 3 года назад

    Super good and helpful video, Thanks!

  • @crazyaccess
    @crazyaccess 2 года назад

    Great quality and efforts brother…

  • @thebibleproof
    @thebibleproof Год назад

    Definitely subscribed!
    Thank you.

  • @smalinux
    @smalinux 3 года назад +1

    Thank you!

  • @jarroddeskins9161
    @jarroddeskins9161 3 месяца назад +1

    Hey thanks! Even two years later its relevant. I want to use zram for temporary. Because it will increase lifespan of SSD because they can only do so many overwrites. Browsing the internet pretty much chews up my SSD. It hasn't gone bad yet, but it will one day. I just hope it doesn't require SystemD because I prefer other init. Anyway thanks!

    • @jarroddeskins9161
      @jarroddeskins9161 3 месяца назад

      Oh yes! It's running perfectly in OpenRC. I suppose I should have known, being that zram runs at kernel level. Now when I surf the net, all temporary internet files go to a RAM drive which is A) Not eating up overwrites on my SSD B) very secure because if I turn off my PC all internet data is PURGED. My PC never swaps unless I use chat4all or stable diffusion, because my GPU is only 12 gig. And swapping slows down the last 20% or so of image generation. But I put the part of the drive that is used during generation of image/chat onto a zram RAM drive and now it is much faster and won't be overwriting my SSD every time. It's my GPU that swaps when 12 gigabytes video ram isn't enough, not the CPU, so having my PC swap to system RAM DRAMATICALLY sped up image and chat generation. (I have 32 gigs RAM)
      This zram is quite useful for conserving overwrites on SSDs. And zswap allowed me to use system RAM as a swap for the GPU. I could hug you right now.
      Thanks for helping improve the security and performance of my shit.

  • @pawanyadav9854
    @pawanyadav9854 3 года назад

    Great video

  • @cosmicusstardust3300
    @cosmicusstardust3300 7 месяцев назад

    I had to disable zram swap because I experienced a strange issue where Firefox would load directly into it, even though I have 128 GB of RAM. Also, whenever the 4 GB swap got filled by Firefox, it would result in a hard crash.

  • @linuxinside6188
    @linuxinside6188 3 года назад +1

    I use artix linux , which has runit as init system , will this work ?
    Can you show like runit service script for that ?

    • @securerandom5420
      @securerandom5420  3 года назад

      Hey LI, I'm not accustom to the runit init system. However, these are supported in the kernel itself so it should work regardless of which you use. Essentially what you're doing here with systemd is making a startup script for the swap file. So you don't "have" to use systemd as long as you can execute those commands in the unit file at startup.

  • @0xssff
    @0xssff 2 года назад

    why the udev rule though?

  • @cosmo_4785
    @cosmo_4785 2 года назад +3

    i have-
    physical ram: 4G
    /swapfile size: 4G
    zram size: 512M
    zswap: enable
    what can i change to impove performance.

    • @NickDyers
      @NickDyers Год назад +1

      remove your swap partition, and remove zram

  • @linusman6826
    @linusman6826 3 года назад +1

    Will Zram be better for an eMMC laptop with 4GB ram?

    • @securerandom5420
      @securerandom5420  3 года назад +3

      Yes if you actually start filling up that 4GB of RAM because it will help keep writes off the eMMC. There will be no difference if the RAM is never filled and it doesn't swap.

  • @chrisdanger-godlike3048
    @chrisdanger-godlike3048 Год назад

    what is your hint?
    i am using 4gb swap partition an 32gb ram.
    now, i need more swap. can i create 10gb swap file and add with zswap the 4gb partition?

    • @chrisdanger-godlike3048
      @chrisdanger-godlike3048 Год назад

      @@mikewright9210 hi, i have create a 10GB swap file and deactivated swap partition (4GB), in terminal with top i see:
      RAM: MiB Spch: 27935,4 total, 2533,3 free, 6656,2 used, 18745,9 buff/cache
      swap: MiB Swap: 10240,0 total, 10216,0 free, 24,0 used. 20434,9 avail Spch
      i do not really understand the RAM buffer, but in my eyes, my computer do not need swap!\o/ mostly the swap use just some MB.
      So the meanings of 4GB swap is not very much...

  • @juanluucas
    @juanluucas 3 года назад +1

    i got 32gb ram but my manjaro only use ~3gb , can Zswap help me to get better performance ?.

    • @securerandom5420
      @securerandom5420  3 года назад +3

      Juan, zswap wont help you at all until your computer actually uses enough memory to take advantage of it. If you have 32G of RAM and you consistently only use 3 there is probably no need to turn it on. Unless of course you're just interested in learning how to do it.

    • @juanluucas
      @juanluucas 3 года назад +2

      @@securerandom5420 ooh i see. what can i do with the extra ram? sorry im new in linux. i hear about preload, but that program looks old

    • @securerandom5420
      @securerandom5420  3 года назад +4

      @@juanluucas Preload is actually pretty awesome and will make your applications quite a bit snappier. But if you're *trying* to use more RAM, you could always mount /tmp and /usr/tmp on tmpfs for a slight performance boost to the applications that write there.

    • @juanluucas
      @juanluucas 3 года назад

      thank you, you are amazing!

    • @gnupph
      @gnupph 3 года назад

      I have 64GB of RAM and ramdisk (tmpfs at /tmp) is the only thing I bought this much of RAM

  • @rustydust8648
    @rustydust8648 Год назад

    can you please tell me how to change compression algorithm in zram?

    • @prashanthb6521
      @prashanthb6521 Год назад

      Edit the zram dot conf file.

    • @rustydust8648
      @rustydust8648 Год назад

      @@prashanthb6521 never mind
      you should disable it, it is a not the right way to go about setting up zram
      it doesnt allocate/reserve the space for zram
      imagine you have 16gb ram, and 8 gb is zram
      you will use 14gb ram without going to zram
      when full 16gb is filled up, it will try to store in zram, but zram will have to clean up some space in ram to exist as all 16 gb is filled, this creates a deadlock situation, it will make your pc freeze
      and for the record, yes i tested

  • @BenderdickCumbersnatch
    @BenderdickCumbersnatch 2 года назад +6

    Fedora uses zram by default, out of the box.

    • @ariel_chess
      @ariel_chess 16 дней назад

      WHAT! I was looking this up b4 installing fedora

    • @ariel_chess
      @ariel_chess 16 дней назад

      Thanks

    • @ariel_chess
      @ariel_chess 16 дней назад

      Would you marry me?

  • @RohithGolle
    @RohithGolle Год назад

    actually priority in linux goes this way -20 highest priority to 19 lowest priority

  • @ariel_chess
    @ariel_chess 16 дней назад +1

    Is it only me or do you kinda sound like Stitch?

  • @lordofthemound3890
    @lordofthemound3890 2 года назад

    I thought lower numbers -3 vs -2 or, say 0 actually have a HIGHER priority (i.e. -20 is highest priority and 19 is lowest priority).

    • @BenderdickCumbersnatch
      @BenderdickCumbersnatch 2 года назад +3

      No. Higher is higher priority: "priority is a value
      between -1 and 32767. Higher numbers indicate higher
      priority."

    • @jeffreymorgan5808
      @jeffreymorgan5808 2 года назад

      So this can be used to hide messages or apps to hide from gf

    • @lordofthemound3890
      @lordofthemound3890 2 года назад

      @@BenderdickCumbersnatch What am I thinking of then? Niceness (or Nice value)? How does Niceness and priority interact?

  • @6srer
    @6srer 2 года назад

    💀

  • @fatpanda1597
    @fatpanda1597 5 месяцев назад

    sudo apt install zram-tools
    sudo nano /etc/default/zramswap -->
    --------------------------------------------------------------------------------
    ALGO=lz4
    PERCENT=25
    --------------------------------------------------------------------------------
    Done. Nothing more to change.