anybody else using zswap?

Kernels & Hardware, configuring network, installing services

anybody else using zswap?

Postby wizard10000 » 2020-04-27 12:13

Decided to experiment with zswap a little and now have no swap file/partition on my machine :)

Had to combine stuff from the Arch wiki and systemd-swap's GIT repository to get the thing going but now have up to 12% of my RAM earmarked for compressed memory pages. The service uses about zero ram until the machine starts paging and then will use up to 12% of my 8GB for compressed memory pages.

About the only time my machine uses swap is when I'm running a Win7 machine under KVM/QEMU - I can see a slight increase in performance and the VM boots to a working desktop in 15 seconds.

Anyway, references -

https://wiki.archlinux.org/index.php/Zswap

https://github.com/Nefelim4ag/systemd-swap

Second link is systemd-swap's GIT repository. If you grab the code and run the shell script included it'll create a .deb for you - no compiling required.

I also installed lzo and lz4 - not sure whether either were dependencies as I installed them before I installed the .deb

Was kinda fun - was able to disable and remove my swap partition and resize my root partition while booted into that root partition :)

cheers -

edit: Even after I removed swap partition from fstab the machine complained about not finding resume location. Fixed that by removing /etc/initramfs-tools/conf.d/resume and then running update-initramfs -u
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 155
Joined: 2019-04-16 23:15
Location: southeastern us

Re: anybody else using zswap?

Postby Head_on_a_Stick » 2020-04-27 12:19

wizard10000 wrote:now have no swap file/partition on my machine

I thought zswap was designed to work in conjunction with a swap partition? :?

What happens now when you start running out of RAM? The system has nowhere to page to if the physical swap space isn't there.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12744
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: anybody else using zswap?

Postby wizard10000 » 2020-04-27 12:37

Head_on_a_Stick wrote:
wizard10000 wrote:now have no swap file/partition on my machine

I thought zswap was designed to work in conjunction with a swap partition? :?

What happens now when you start running out of RAM? The system has nowhere to page to if the physical swap space isn't there.


It *can* work in conjunction with a swap partition (by default it does), it can also do standalone. The 12% of RAM I have reserved for zswap takes the place of physical swap space.
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 155
Joined: 2019-04-16 23:15
Location: southeastern us

Re: anybody else using zswap?

Postby CwF » 2020-04-27 13:22

I've mentioned zram-tools a few times.
I have a few examples, it should be tuned to use.
Swappiness should be a tad higher, it works with or without swap partitions or files.
It helps low and high memory configs.
Highly recommended with modern cpu's.
Default for my systems.

https://packages.debian.org/search?keyw ... lla-search
CwF
 
Posts: 800
Joined: 2018-06-20 15:16

Re: anybody else using zswap?

Postby pylkko » 2020-04-27 19:19

So did I get the idea? ...which appears to be tat most of the time most people's CPU's are idle. So, if you can use them for anything that you need = awesome. If you need more RAM, then compressing stuff to RAM makes sense (as, I suppose, that means sacrificing CPU cycles in the compression to lower space). So them if you toss the entire swap and move everything to RAM, you can even get performance benefits (because swap is slow). But what indeed if you run out of RAM and OOM kicks in, will your lock up be even worse than normal because stuff is compressed also now?

Also what if you game, transcode video or compile stuff a lot, would you suffer and want to turn it off at times?
User avatar
pylkko
 
Posts: 1793
Joined: 2014-11-06 19:02

Re: anybody else using zswap?

Postby wizard10000 » 2020-04-27 19:52

pylkko wrote:would you suffer and want to turn it off at times?


I'm still playing Skyrim on a PS3 so definitely not a gamer :)

I played with zram for a bit and ended up abandoning it for systemd-swap because it seemed to be just the thing for managing swap :)

Posting /etc/systemd/swap.conf so you can get an idea what can be done - the only thing I changed was lowered the zswap default 25% max RAM allocation to 12% since I have 8GB of RAM
Code: Select all
################################################################################
# Defaults are optimized for general usage
################################################################################

################################################################################
# You can override any settings with files in:
# /etc/systemd/swap.conf.d/*.conf
################################################################################

################################################################################
# Zswap
#
# Kernel >= 3.11
# Zswap create compress cache between swap and memory to reduce IO
# https://www.kernel.org/doc/Documentation/vm/zswap.txt

zswap_enabled=1
zswap_compressor=lz4      # lzo lz4
# zswap_max_pool_percent=25 # 1-99
zswap_max_pool_percent=12 # 1-99
zswap_zpool=zbud          # zbud z3fold

################################################################################
# ZRam
#
# Kernel >= 3.15
# Zram compression streams count for additional information see:
# https://www.kernel.org/doc/Documentation/blockdev/zram.txt

zram_enabled=0
zram_size=$(( ${RAM_SIZE} / 4 )) # This is 1/4 of ram size by default.
zram_streams=${NCPU}
zram_alg=lz4                     # lzo lz4 deflate lz4hc 842 - for Linux 4.8.4
zram_prio=32767                  # 1 - 32767

################################################################################
# Swap File Chunked
# Allocate swap files dynamically
# For btrfs fallback to swapfile + loop will be used
# ex. Min swap size 512M, Max 8*512M
swapfc_enabled=0
swapfc_force_use_loop=0     # Force usage of swapfile + loop
swapfc_frequency=1s         # How often to check free swap space
swapfc_chunk_size=512M      # Allocate size of swap chunk
swapfc_max_count=8          # note: 32 is a kernel maximum
swapfc_free_swap_perc=15    # Add new chunk if free < 15%
                            # Remove chunk if free > 15+40% & chunk count > 2
swapfc_path=/var/lib/systemd-swap/swapfc/
# Only for swapfile + loop
swapfc_nocow=1              # Disable CoW on swapfile
swapfc_directio=1           # Use directio for loop dev
swapfc_force_preallocated=0 # Will preallocate created files

################################################################################
# Swap devices
# Find and auto swapon all available swap devices
swapd_auto_swapon=1
swapd_prio=1024
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 155
Joined: 2019-04-16 23:15
Location: southeastern us

Re: anybody else using zswap?

Postby pylkko » 2020-04-28 04:27

how much does the cpu usage increase? would it affect batter life?
User avatar
pylkko
 
Posts: 1793
Joined: 2014-11-06 19:02

Re: anybody else using zswap?

Postby wizard10000 » 2020-04-28 11:00

pylkko wrote:how much does the cpu usage increase? would it affect batter life?


Couldn't tell you yet as my machine almost never swaps. I did notice that my QEMU/KVM Win7 VM boots a little faster than it used to.

The cool thing about zswap vs. zram is that zswap only allocates memory if needed - if you're not paging I really don't see any impact.

Battery life shouldn't really be impacted as storing pages in memory requires less power than storing them on a physical disk.
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 155
Joined: 2019-04-16 23:15
Location: southeastern us

Re: anybody else using zswap?

Postby CwF » 2020-04-28 16:54

wizard10000 wrote:The cool thing about zswap vs. zram is that zswap only allocates memory if needed - if you're not paging I really don't see any impact.


That's not my experience. zram-tools is a simple install with no required configuration or even a reboot. You don't need to change any swap config. It doesn't suck up memory when not needed.

In addition to running out of memory, another use case is long term uptime. Things are swapped due to lack of use long before a memory shortage. Duplication of many vm's can swap out gig's of redundant code, leaving a multiple of that free.

Firefox uses it very well to swap out tabs not in use. On a fast computer that is transparent and can easily save a gig. With many redundant VM's I see up to a few gigs in zram saving 3-4 GB while less than half memory load.

Simple install and go! You can change the size to suit and increase swappiness to use it more effectively.

One machine now shows 4MB! ..of 25GB in use and 36GB free. Another is at 892MB and has been up to 1.5GB during it's 200+ days of uptime. Neither has touched the swap partition.

Testing VM's with browsers and balloonable memory, ones with zram give notice of memory confinement just by maxing the allotted zram while being perfectly responsive. The same load without would freeze the vm to useful input and require a few hundred MB of memory ballooning to become responsive. It clearly works.

It does use modern cpu extensions, so not for older old machines. (Westmere and up I'd guess)
CwF
 
Posts: 800
Joined: 2018-06-20 15:16

Re: anybody else using zswap?

Postby pylkko » 2020-04-28 19:29

wizard10000 wrote:
pylkko wrote:how much does the cpu usage increase? would it affect batter life?


Battery life shouldn't really be impacted as storing pages in memory requires less power than storing them on a physical disk.


No, but if you swap, and therefore compress stuff, your cpu load is gonna be up all the time decompressing and compressing stuff... that will eat a battery. But this is of course in the event that you swawp to begin wth
User avatar
pylkko
 
Posts: 1793
Joined: 2014-11-06 19:02


Return to System configuration

Who is online

Users browsing this forum: No registered users and 11 guests

fashionable