Skip the following long introduction if you already know what zram is and just want to know how to get it working...

Many of us, may have occasionally or often run into problems with web-browsers freezing and becoming unresponsive. The problem occurs most often with large memory hungry browsers such as recent Firefox or google Chrome, and especially, of course, on computers that only have relatively low amounts of RAM, such as 2GB or less. Opening a new browser tab on a heavy web page such as Facebook or Gmail can require over 100MB of RAM use per tab, so it is not surprising that opening five such tabs can cause a 512MB RAM machine to freeze, and so on (you can test/measure this effect by watching free/available memory space with top utility running whilst opening multiple gmail tabs...).

Traditionally, the way to avoid the computer thus crashing due to RAM running out is to use a separate swap partition or swap file, such that the overall 'memory' (called virtual memory) available becomes "RAM + swap space" (active RAM memory pages get swapped in and out of RAM to swap space as and when required). Unfortunately, swap space is generally much slower to read and write than actual RAM (being often on slow hard-drive or flash media), so though the computer no longer crashes once actual RAM is exhausted, it typically starts running very slowly.

zram is a technique which uses a portion of actual RAM as if it is a normal block device (such as a hard-drive), but being in RAM it remains fast. Furthermore it uses compression such that for every 1GB RAM used as zram the storage space it provides is typically 2 to 3 times that amount. zram can thus be configured as swap space in memory, with most of the advantages, but much faster than conventional swap. Disadvantage is that is does use some CPU cycles to continually compress and decompress data and it does use some of the actual RAM; nevertheless, in my own measurements (on a 2GB RAM machine), using zram greatly increases the number of heavy browser tabs that can be opened before virtual memory runs out and browser freezes/crashes and performance remains good even during zram swapping.

Note that zram doesn't even start getting used until swapping becomes required, so there appears to be little or no reason not to use it. On a larger RAM machine, no swapping will generally occur so zram is not so necessary, however, it depends on what kind of processing you are doing. For example, if you are doing large compiling jobs, or processing video files, you may well require large amounts of RAM such that swapping remains likely to occur. Hence, even on my 4GB RAM machine (largest I have), I still enable zram since I find no reason (performance-wise) not to.

Furthermore, if you are using flash-based media, such as SSD, an SD card, or usb-flashstick, using zram for swap does not require continual data writes to the flash device, which helps it last longer. Even modern flash devices can only stand a finite number of write cycles and if, like me, you use ten year old computers (or want your computer to last at least that long) minimising flash-writes is definitely a good thing... Note that there is nothing to stop you also using conventional swap in addition to zram; the zram swap can be prioritized such that it will be used first such that any slower conventional swap is only ever used in particularly critical situations.

The zram module creates RAM based block devices named /dev/zram<id>
(<id> = 0, 1, ...). Pages written to these disks are compressed and stored
in memory itself. These disks allow very fast I/O and compression provides
good amounts of memory savings. Some of the usecases include /tmp storage,
use as swap disks, various caches under /var and maybe many more

Most of the following was tested on a XenialDog 64bit system, so file locations may or may not be different on other distribution variants. EDIT: The installation method will also vary for different Linux distributions, such as tradition Pups.

With thanks to backi, dancytron and fredx181 for much of the useful information.

Note that you need to be root user or use 'sudo' to do most of the following:

By default to created /dev/zram* block filesystems are automatically prepared for use as (compressed) swap filesystems using compression type lzo; one such filesystem per system CPU core. For example, on a dual-core CPU system you will have /dev/zram0 and /dev/zram1 prepared and activated as compressed swap filesystems.

3. You can check you have zram compressed swapspace available using either top, free or zramctrl command. For example:

Code:

free (or free -h)

or, for more detail, use:

Code:

zramctl

Note that the zramctl program (provided by zram-config deb) can also be used for changing swapsize, compression type and so on. For usage help, you should refer to it's online man page or for usage summary:

Code:

zramctl --help

4. If you want to use lz4 compression in preference to that lzo default, edit /usr/bin/init-zram-swapping to contain the extra line shown as "#wiak added" below:

You can then re-activate zram swap either by re-booting your system or re-starting the zram-config.service with command:

Code:

systemctl restart zram-config.service

5. When using the systemd service method of using zram you can disable it simply using command:

Code:

systemctl stop zram-config.service

or by directly executing bash script:

Code:

/usr/bin/end-zram-swapping

6. You can start it up again using either:

Code:

systemctl start zram-config.service

or by directly running bash script:

Code:

/usr/bin/init-zram-swapping

7. Assuming you have disabled zram being used solely for swap, you can use the /dev/zram* block devices like any other block device. For example, you can create a compressed ramdisk (i.e. in RAM memory) with a command such as:

Code:

mkfs -t ext4 /dev/zram1

and use it for anything you like (such as mounting /tmp on it).

Alternatively (or in addition) you can manually create a swap partition on another pre-created zram block device using, for example:

A simpler way of doing the above, however, is simply to make a re-named copy of the script /usr/bin/init-zram-swapping and modify that for the purpose your desire. One example would be to simply modify that script for a different swap size calculation as follows (refer to #wiak added):

Hi wiak !
So you have been quite busy lately !You are a real Working-Horse .
Maybe you should mention in your Introduction Zram/Zwap can be used for machines with low Ram....... . Not Everyone is familiar with the Concept of Zram .
Nevertheless great Compilation for Starters ..... Work in Progress .

Wiak, thanks for the explanation. (I took the liberty of changing your title a bit. I hope you don't mind. If you do, please feel free to change it back. )

For what it's worth, according to Hardinfo, Quirky Werewolf 64-bit, running entirely from DVD without a hard disk drive, uses nearly all of the 4 GB of RAM in my computer, so there wouldn't be any left in which to put some swap.

I noted something changed re 'ze Dogs' in my main post content text also, but have no time or desire to add to zram/zswap info at present - busy on other things. Got rid of the for 'ze Dogs' additions though since not my own personal intention at all.

grammar editsLast edited by wiak on Mon 26 Mar 2018, 05:46; edited 5 times in total

zram and zswap definitely not just potentially useful for the Dogs, despite my statement in first post that I did my tests using XenialDog system - only the install method via apt-get applies only to Debian apt-based systems, everything else also applies to Puppies and Linux more generally. With all due respect, I would be grateful if consent was requested before modifying technical document published by author - my name is on the post so any inaccuracy introduced appears mine... Also, even simple puppy forum technical posts inherently contain Intellectual Property rights (whether worthwhile, worthless, valuable or valueless in content) and these rights should be respected. By all means ask me if something is offensive or wrong in such a way that I can amend or delete according to my own choice (or then delete if I refuse). That would be much preferred, thanks. Personally I wouldn't contribute otherwise (not that I'm saying that matters... and I doubt anyone has time to make anything 'perfectly' correct or 'complete' anyway, though I already did add quite a bit extra, at backi's request, regarding what I feel are zram particular benefits for low-ram machines).

that's the 32 bit version. apart from zramctl having been compiled (click the "compile.sh" in zramctl-master (see zramctll for link) in a 64bit tahr spin (underneath it's tahr64 605) rather than a 32 bit xenial spin (a modded 704 that has always been a bit buggy for me, but the pet failed similarly on xenial 7.5 32 and tahr 605 32 bit), the 64 bit below is the same, albeit a bit more succussful (mounted zram as expected via dancytron's script, but zram-stop failed to stop it. zramctll (

)
gives a snapshot of the activity (or non-existence, in the case of my 32 bit attempts) of the zram disk you may or may not have created. in the xenial 704 pup, the activate zram scripts included in the pet just close the terminal (slam it shut), but in my old gateway desktop (1.8 gig of ram, 2 Ghz), things worked so well that i made a 32 bit pet for my even slower machine (asus netbook with 2 gig of ram clocked at 1.6 Ghz), which i'm hoping you can help me get to work.

subjective review and what i remember from the (maybe more objective) snapshots:

the main browser on the machine is palemoon, and that's what's most readily available to anyone who wants to use it. my wife, having discovered yahoo no longer displays properly in it for her, has taken to booting firefox on top of an already running and loaded palemoon instance (mostly ad heavy and other parasitic sites). i notice the swap activity via zramctll was more active than my 7gb swap partition, despite being relatively less nice (priority is 5 for the zram versus -1 for the partition).(though i may have that whole thing ass backwards. assuming i don't--)

less priority but it's just a more active aspect in general?

seeing that things weren't looking too good for speed and comfort, i opened a tab to a site that recently slowed my asus down, the ergodox ez keyboard site--the gateway handled it after a little bit of a delay--i saw the zram swap increase via the leafpad window that opens, felt that it was helping and would help considerably on the other machine. so,

what am i doing wrong? why won't it work for me at all in 32 bit? (i'd take the inability to swap off the zram in exchange for being able to enable/create it).

to give a rundown on what i did and why:

1. ran the scripts linked to above--no results.
2. installed/compiled (/"compiled"--clicked ./zramctl-master/compile.sh with the devx loaded) zramctl, ran the scripts again. --still no results.
3. installed the zram-config_0.5_all.deb pet (actually .1, but i don't think it matters--found the newer package later--none helped with the 32 bit pups i mentioned). ran the scripts again. the output from swapon -s and zramctl (just a maybe for this one) were what they should have been.
4. made pets that fail for select 32 bit pups.

in short, i notice an performance improvement in a 2gb ram, 64 bit machine, and i'd like to get it working in a machine that i think would benefit even more from it (32 bit, 2gb asus 1000ha netbook).

thanks, wiak (and backi and dancytron)--this seems to be a really key find for underpowered pups (even if implemented imperfectly--i see no reason to disable the zram, and so the fact that bit doesn't work doesn't bother me).

...after a day or so, the htop reading changed to add the zram to the total swap figure...64 bit machine still seems better for having it….

thanks again.

___

here's a shot of off, on, and info, which has a weak icon even among some pretty terrible company. anyway, apart from the not working in 32bit bit, i'm happy enough with this as the interface (or just dragging the start script to start up (which i haven't tried but should work in one form or another (sometimes dragging a desktop file works, sometimes you have to put a mini script to call something, sometimes that won't work either...)) and skipping a proper interface altogether).

You have obviously put in a lot of work there. Sorry, I can't help right now because I'm also in the middle of something that's taking me days and a lot of energy. Hopefully, you will manage to sort out the issues you are having with zram on 32bit Pup.

May be a while before I finish what I'm doing just now, but I will check back on this thread after that to see if you have everything you want sorted out. But to be honest, that may be a week or more till I get round to that, so hopefully someone else in Pup community will take a look and help you out meantime.

Yes, I agree, zram should certainly improve swap performance for that 32bit machine you describe, and won't do any harm anyway.

I've no idea why you are claiming zram is 'useless' zagreb999. I know very well that it is in fact measurably useful, though additional real RAM addition would be even better of course, if available.

Anyway, personally I am thankful to the developers of zram - this 2GB RAM old computer, running XenialDog, used to crash regularly but now rarely does (and only usually now when I open a few too many browser tabs). Of course I can add some traditional swap too - but once the system starts using that it slows down to a crawl...

All of the 'Swap' shown via free command below is zram-provided swap. The 'free' RAM value can be added to the 'buffer/cache' amount (which can be freed up too - in fact Linux will dynamically free it up as required...) and in addition to that you can add the zram-based swap. The total virtual memory from all that is significantly in excess of the total real 2GB RAM of the machine - hence the machine can, for example, open more browser tabs without crashing...

Puppy Linux teachers no longer will write the lessons on the blackboard. They teach what is ZRAM by screencast, with SimpleScreenRecorder (or Wex, perhaps). Well class is done in magyar , but i understand however that zram is a compressed swap, isn'it ?
I never use Swap..
New ! tuto just realeased for next exam (june)
ZRAM lesson Better you download it.

ZRAM.jpg

Description

For Learners (high level)

Filesize

29.43 KB

Viewed

171 Time(s)

Last edited by hamoudoudou on Thu 03 May 2018, 23:20; edited 1 time in total

Furthermore, if you are using such as a usb-flashstick, using zram for swap does not require continual data writes to the flash device, which helps it last longer

.
Is this working the same as the ram disk that Puppy uses when running from a USB flash drive?
Does this conflict with proper operation of the Puppy ram disk?
How Puppy works:
http://bkhome.org/archive/puppylinux/development/howpuppyworks.html_________________I have found, in trying to help people, that the things they do not tell you, are usually the clue to solving the problem.
When I was a kid I wanted to be older.... This is not what I expected

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum