zram swap any info about how it is configured in Puppy? exactly what it does?

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

Post Reply
User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

ZRAM SWAP in Puppy Linux.

What is it?

Does it have a configuration file someplace?

Can size be changed or is it set in stone?

Do you need a normal swap partition or swap file anymore, if the Puppy version now has ZRAM SWAP?

Any reason it seems to be configured to use the full amount of memory?

Anyone out there that can teach us about it?

Please all information needs to be specifically about Puppy Linux!

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

User avatar
wiak
Posts: 4079
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1206 times
Contact:

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by wiak »

My understanding is that the Debian scripts @dancytron long time ago first introduced to the forum for use with DebianDogs has since been found to work for Puppy Linux systems too: https://www.forum.puppylinux.com/viewto ... 549#p78549
More generally, I read they work both with distros that use systemd or distros such as Puppy Linux that don't use systemd as their main init system. See also @Jasper post immediately below the linked one of dancytron.
Whether @dimkr has produced any alternative zram control mechanisms in his Puppy releases I wouldn't know.

As for what zram swap is. Well, as most of us know normal swap is usually reserved space on your hard disk that is used when actual RAM memory is becoming over-loaded. The combination of RAM plus swap provides what we refer to as Virtual Memory. The problem with that kind of conventional swap is that hard disk access (read and write) is traditionally slow (or with modern SSD drives it remains problematic, in terms of wearing them out, to write data to SSD swap too frequently).
zram is a clever trick in which a portion of normal RAM is set aside as swap space. That seems daft. However, the trick is that the zram swap space is compressed and also, being in RAM it is still fast to access, so overall Virtual Memory now becomes:

The proportion of total system RAM not used as zram swap space + the proportion of total system RAM used as zram swap space.

For example, say you have 8GB total system RAM and reserve 3 GB of that for zram swap (leaving 5GB for normal RAM use). Say the zram compression used is such that compression is x3 so the reserved zram swap can thus store 3GB x 3 = 9GB of swap data. The overall Virtual Memory is then equal to:

5 GB normal RAM + 9GB of zram compressed swap space = 14GB total (i.e. 6GB larger than the total actual system RAM so you can, for example, open more browser tabs without running out of 'memory').

The advantage is that zram is also in normal RAM and compression/decompression delays are relatively small on modern systems so you don't get the SLOW to a crawl effect that normal swap to a hard drive tends to give. It tends to be a win-win situation and specially beneficial on low total system RAM systems, but pretty good always I'd say from using it for years - can't say I've noticed any major drawbacks at all. Browser pages are good candidates for compression - and so zram swap really tends to make your system less crash-prone - able to open far more browser tabs - without slowing it down the way conventional hard disk swapping would.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 4079
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1206 times
Contact:

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by wiak »

So zram is generally good to have, but once you have it more interesting perhaps is how to best configure it for optimum performance on different resourced machines. Interestingly, a lot of people on here have suggested setting vm.swappiness to as low as possible (i.e. 0), but whilst that was probably true for normal hard drive swap it is NOT what most experts seem to recommend if you are using zram swap. Here is a link to such information (look at the ZRAM-related section for details):

https://haydenjames.io/linux-performanc ... art2-zram/

Doesn't matter what the init system (or distro) is (sysVinit, runit, or systemd), except that they generally use their own/different zram configuration files and mechanismas, but zram works the same once it is running.

A reddit discussion about zram compression and the likes of vm.swappiness and more:

Code: Select all

https://www.reddit.com/r/Fedora/comments/mzun99/new_zram_tuning_benchmarks/

So whilst this may not be what you thought was appropriate, quite often:

Code: Select all

https://fosspost.org/enable-zram-on-linux-better-system-performance/

We actually desire more than that; we want data to be filled always on the zRAM disk before any data is written to the uncompressed RAM area. So, we should use a swapiness value of 150 (it doesn’t mean 150% of RAM, it means encouraging the kernel to swap more often).

In other words, with zram you WANT to swap (i.e. increase vm.swappiness) because it is when normal RAM runs out that your system crashes, so use zram swap FIRST and finally normal RAM (once that normal uncompressed RAM finally runs out a crash would occur though...). The reason it would crash once normal RAM used up is that some normal RAM needs to be left for zram swap to operate correctly... (compression/decompression is involved and needs to be done, which needs normal RAM memory availability).

See also Arch Wiki "2.2 Optimizing swap on zram" (near foot of page): https://wiki.archlinux.org/title/Zram

Also:

Code: Select all

https://www.reddit.com/r/pop_os/comments/znh9n6/help_test_a_zram_optimization_for_pop_os/ 

emphasises "most people that were tuning their systems settled upon zstd [zram compression algorithm]...The improvement is more pronounced on systems with less RAM. On a system with 4GB RAM, up to 4GB RAM would be compressed by zram into approximately 1 GB of RAM, freeing room for an additional 3 GB of memory. This would allow you to address up to 75% additional memory in RAM before needing to resort to a swapfile...the main goal is to use it before you get to the point where you are out of memory. The Linux kernel documentation has a formula for calculating the ideal swappiness value, and for zram that's around 180-200."

EDIT: had trouble with normal links providing mini-webpage that obscured the actual link... so just put in code tags as workaround for now.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 4079
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1206 times
Contact:

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by wiak »

For example, from above:

https://haydenjames.io/linux-performanc ... art2-zram/

Adjusting Kernel parameters for ZRAM instead of SWAP
On a server with low memory, after adding ZRAM, you can add...

vm.vfs_cache_pressure=500
vm.swappiness=100
vm.dirty_background_ratio=1
vm.dirty_ratio=50

With the settings above, you will delay the inevitable (running out of memory), but start preparing for that sooner, rather than leaving it until the inevitable happens all at once – heavy swapping.

vm.vfs_cache_pressure=500 – increase cache pressure, which increases the tendency of the kernel to reclaim memory used for caching of directory and inode objects. You will use less memory over a longer period. The downside of swapping sooner negates the performance hit.

vm.swappiness=100 – Increasing how aggressively the kernel will swap memory pages since we use ZRAM first.

vm.dirty_background_ratio=1 – background processes will start writing right away when it hits the 1% limit

vm.dirty_ratio=50 – the system won’t force synchronous I/O until it gets to 50% dirty_ratio.

These four lines – when used with ZRAM – will help performance in cases where you will eventually end up requiring more than the installed amount of memory. Knowing that you will swap, that ZRAM makes swapping less expensive and stores the same data compressed 2x to 3x smaller, you should begin this swap exchange sooner.

The cache pressure helps because we are in effect telling the kernel: “hey, look man, I don’t have any extra memory lying around to use for cache, so please get rid of it sooner and only store the most frequently used.”

Even with reduced caching, if we use most of the installed memory over time, the kernel will start opportunistic swapping to ZRAM much sooner so that CPU (used for compression) and swap I/O aren’t delayed until all at once.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

dancytron
Posts: 722
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 520 times
Been thanked: 217 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dancytron »

I've found that the most dramatic effect is on machines with less than 4 Gb of ram and it can prevent or at least delay the low ram/thrashing to a slow hard drive swap partition browser freeze.

Last edited by dancytron on Wed Jun 28, 2023 2:07 pm, edited 1 time in total.
Feek
Posts: 398
Joined: Sun Oct 18, 2020 8:48 am
Location: cze
Has thanked: 54 times
Been thanked: 90 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by Feek »

wiak, thanks for the very useful information.

bigpup, if anyone wants to know in a real situation what zram swap is and how it works, just run vanilladpup on a system with less ram (e.g 4gb).
Zram swap is preset.
Then just run more heavy applications (multi-window browser, play youtube, ..) and monitor the swap usage in top/htop.

I think how powerful the CPU is plays a big role as well.
When my dual-core i3 compresses a smaller amount of data in ram (ie puts it to zram swap), I hardly notice it.
But if it is a large amount of data at once, everything will slow down during the compression, because the processor is quite busy at that moment.
But it's temporary, it settles down after a while.

dancytron
Posts: 722
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 520 times
Been thanked: 217 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dancytron »

The other variable on how useful it is going to be is how slow is your hard drive. If you've got a super fast modern SSD of some kind (I wouldn't' know personally), then having it swap to disk a little probably isn't a deal killer.

But waiting for a pre i-series dual core era hard drive to swap chrome or firefox from disk may not actually be crashed, but it's going to feel like it is.

edit: These are the links I have in my notes.

https://web.archive.org/web/20170826234 ... n.org/ZRam (where script came from, new version is very different)

https://www.systutorials.com/docs/linux/man/8-zramctl/

https://wiki.archlinux.org/title/Zram

Last edited by dancytron on Mon Jun 26, 2023 9:10 pm, edited 3 times in total.
User avatar
gychang
Posts: 591
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 206 times
Been thanked: 64 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by gychang »

bigpup wrote: Mon Jun 26, 2023 9:49 am

ZRAM SWAP in Puppy Linux.

What is it?

Please all information needs to be specifically about Puppy Linux!

Just a messenger, smart folks here know what/how it works.

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

Thanks to all that have posted! :thumbup:

I think we have all the info on what ZRAM SWAP is and how it works.

Now we need some specific info, on how it woks in Puppy versions, that have it.

Does it have a configuration file someplace?

Can size be changed or is it set in stone?

Do you need a normal swap partition or swap file anymore, if the Puppy version now has ZRAM SWAP?

Any reason it seems to be configured to use the full amount of memory?

I am hoping to turn this into a very good information topic to place in the forum section Getting Started and System Requirements.
Maybe also a how to about ZRAM Swap.

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

Enhanced use of zram (& my lack of understanding of it) is what was behind my 'missing ram issue' on my chromebook.
The article below explains that zram use case, which may be helpful as a 'real world' example.

https://www.howtogeek.com/413556/how-mu ... ally-need/

dimkr
Posts: 2420
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1202 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dimkr »

User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

@dimkr

OK, Thanks for the link.

Could you please give a little simpler answers to these questions?
Most of us do not read code or fully understand it.

This part is easy to understand:
Puppy's init script hasn't changed a lot throughout the years.
The init script, now used in newest Puppy versions, works like this with swap.

It activates swap on the swap partition it finds, otherwise tries to use /mnt/home/pupswap.swp or /pupswap.swp, a swap file (if you created it using the "boot manager" thing).
Otherwise it creates a zram block device and puts swap on it.

Does it have a configuration file someplace?

Can size be changed or is it set in stone?
If can change, how?

Do you need a normal swap partition or swap file anymore, if the Puppy version now has ZRAM SWAP?

Any reason it seems to be configured to use the full amount of memory?

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

dancytron
Posts: 722
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 520 times
Been thanked: 217 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dancytron »

I'm pretty sure you could just unload the default and redo it however you want with a little script in /root/startup.

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

In s15pup64 (at least) zram is set up in /etc/rc.d/rc.sysinit, about line 61. I modified mine to use half ram instead of all, as an experiment. Is this safe/usable/useful? No idea - try at own risk. (correction inserted). See pics below.

before_zram_chg.jpg
before_zram_chg.jpg (22.71 KiB) Viewed 797 times
after_zram_chg.jpg
after_zram_chg.jpg (24.34 KiB) Viewed 797 times
Last edited by ozsouth on Wed Jun 28, 2023 6:28 am, edited 2 times in total.
User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

Are you sure about that file location?

I am finding it in /etc/rc.d/rc.sysinit

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

Oops - correction inserted - is /etc/rc.d/rc.sysinit

User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

@ozsouth

Well, I guess you answered these questions with your post.

Does it have a configuration file someplace?
Yes.
/etc/rc.d/rc.sysinit

Can size be changed or is it set in stone?
If can change, how?
Yes, it can be changed.
See ozsouth's above post.

But not totally sure, change it to what or why change it?

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

Any ideas on the need for a swap partition or a swap file, if the Puppy version has the latest changes to now make a ZRAM SWAP?

My thinking is no need to make a swap partition or swap file, anymore.

Now only have the ZRAM SWAP.

It will be automatically made and now used for swap.

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

dimkr
Posts: 2420
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1202 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dimkr »

bigpup wrote: Wed Jun 28, 2023 6:37 am

But not totally sure, change it to what or why change it?

What problem are you trying to solve?

User avatar
bigpup
Moderator
Posts: 6985
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 906 times
Been thanked: 1522 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by bigpup »

Not really a problem.

But what size to have the ZRAM SWAP?

Make it the size of the RAM in the computer?

Half the size of RAM?

No bigger than 8GB?

What affect would changing it have on normal operation?

-------------------------------------------------------------------------------------------------------------------------------

I am seeing articles talking about ZRAM SWAP and latest info.
It seems now, ZRAM SWAP setup should now be set, so that the stuff going into RAM, should go into ZRAM SWAP first, and be used by RAM as needed.

But I wonder, if this is because the new or newest CPU's, can handle the compression/decompression operation very fast.

With Puppy already having everything loaded in RAM (except the save and it's contents), I wonder if this would really help Puppy operation.

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

dancytron
Posts: 722
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 520 times
Been thanked: 217 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dancytron »

When I had a 3 Gb of Ram dual core, I tuned the size by trial and error to keep my browser from using the swap partition I always have. I played around with the swappiness, etc. but the defaults seems to be fine.

On my 4 Gb machines, I set the variable in the debian.org script to 25, which is a small zram swap in addition to the swap partition. TBH, I'm not sure it does much.

On machines with more than 4 Gb, I don't use it.

User avatar
wiak
Posts: 4079
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1206 times
Contact:

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by wiak »

Well, as far as I've understood it, and pointed out what I read, the suggestions for using zram continuing to be touted here is not correct. The whole point of using zram would appear to be to avoid non-compressed RAM being used up for as long as possible. The suggested strategy for how it should be used is to make vm.swappiness a high value like 180 (rather than accept the default, which is for cases of using normal swap). The idea is that the system should start using zram swap quickly rather than delaying that as long as possible. Only when zram swap is totally used up does the uncompressed (non-zram) RAM start getting used up (if that ever gets used up the system will crash of course).

This is the opposite strategy to that of using normal swap. For normal swap, it is generally best to avoid swap as much as possible because it is not in RAM and instead on slow devices so normal swap is SLOW... zram in not slow since it is in RAM and compression/decompression isn't usually anything like as slow as hard disks. So with normal swap the strategy is to use uncompressed RAM and only use normal swap as a last resort. But use zram swap straight away!

I can't say I know for sure myself though. Perhaps the zram algorithm has changed or perhaps the information is wrong in https://haydenjames.io/linux-performanc ... art2-zram/ section "Adjusting Kernel parameters for ZRAM instead of SWAP". I haven't used zram on my current 32 GB RAM system so would have to experiment.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
gychang
Posts: 591
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 206 times
Been thanked: 64 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by gychang »

ozsouth wrote: Wed Jun 28, 2023 12:46 am

In s15pup64 (at least) zram is set up in /etc/rc.d/rc.sysinit, about line 61. I modified mine to use half ram instead of all, as an experiment. Is this safe/usable/useful? No idea - try at own risk. (correction inserted). See pics below.before_zram_chg.jpgafter_zram_chg.jpg

I have 4G of RAM with a swap partition. I plan to delete the swap partition, and want maximal zram setup. How do I edit the rc.sysinit file exactly?

Attachments
Screenshot(1).png
Screenshot(1).png (249.71 KiB) Viewed 815 times

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

@gychang - the setup in your picture will give you max zram as default, in s15pup64. If for fossapup64, I think you'd need a new initrd.gz too - not sure how to do it.

User avatar
gychang
Posts: 591
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 206 times
Been thanked: 64 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by gychang »

@ozsouth can u clarify why I may need initrd.gz?, I am using F96-CE4 iso and on frugal HD install already has initrd.gz...

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

@gychang - older pups were not set for zram & may need both initrd.gz & /etc/rc.d/rc.sysinit modifications to enable it.
Good news is that F96-CE4 is set to use maximum zram.

dancytron
Posts: 722
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 520 times
Been thanked: 217 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by dancytron »

ozsouth wrote: Thu Jul 06, 2023 9:11 am

@gychang - older pups were not set for zram & may need both initrd.gz & /etc/rc.d/rc.sysinit modifications to enable it.
Good news is that F96-CE4 is set to use maximum zram.

Are you sure? I've used the debian script to set up Zram in Radky's Stretch puppy and iirc Tahr. You can put the script in /root/Startup or run it manually. You do have to unload any already existing zram though. viewtopic.php?p=78549#p78549

ozsouth
Posts: 1565
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 241 times
Been thanked: 701 times

Re: zram swap any info about how it is configured in Puppy? exactly what it does?

Post by ozsouth »

@dancytron - Older Ubuntu & Slackware clones, being the most-used Puppies, was what I meant. I haven't looked outside those in great detail, so took their original offerings on face value. That is why I wrote 'may'. Nice to hear there are more options than I knew.

Post Reply

Return to “Users”