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” Наука
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.
Hello. Which zswap.max_pool_percent has better performance in this configuration?
Super good and helpful video, Thanks!
Great quality and efforts brother…
Definitely subscribed!
Thank you.
Thank you!
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!
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.
Great video
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.
I use artix linux , which has runit as init system , will this work ?
Can you show like runit service script for that ?
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.
why the udev rule though?
i have-
physical ram: 4G
/swapfile size: 4G
zram size: 512M
zswap: enable
what can i change to impove performance.
remove your swap partition, and remove zram
Will Zram be better for an eMMC laptop with 4GB ram?
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.
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?
@@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...
i got 32gb ram but my manjaro only use ~3gb , can Zswap help me to get better performance ?.
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.
@@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
@@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.
thank you, you are amazing!
I have 64GB of RAM and ramdisk (tmpfs at /tmp) is the only thing I bought this much of RAM
can you please tell me how to change compression algorithm in zram?
Edit the zram dot conf file.
@@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
Fedora uses zram by default, out of the box.
WHAT! I was looking this up b4 installing fedora
Thanks
Would you marry me?
actually priority in linux goes this way -20 highest priority to 19 lowest priority
Is it only me or do you kinda sound like Stitch?
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).
No. Higher is higher priority: "priority is a value
between -1 and 32767. Higher numbers indicate higher
priority."
So this can be used to hide messages or apps to hide from gf
@@BenderdickCumbersnatch What am I thinking of then? Niceness (or Nice value)? How does Niceness and priority interact?
💀
sudo apt install zram-tools
sudo nano /etc/default/zramswap -->
--------------------------------------------------------------------------------
ALGO=lz4
PERCENT=25
--------------------------------------------------------------------------------
Done. Nothing more to change.