LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-26-2020, 11:34 AM   #1
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Rep: Reputation: Disabled
[Call for testing] Swap in zram


Hello,

swapinzram allows you to set up a swap space in RAM instead of or in addition to swap partitions and/or swap files. Expected benefits:
1. Way faster than swapping on any mass storage device.
2. Do not contribute to wear out devices like USB sticks, SD cards or MMC drives.
3. Increases your usable RAM size, as the files are compressed.

These benefits should be more important if you have a small RAM and/or the swap file or partition is on a flash drive like those mentioned above, and when you run something using a lot of RAM. Raspberry Pi users are welcome! The cost is just a small overhead for compression/decompression, with a ratio benefit/cost in terms of performances way greater than 1.

The swap space can be created or removed at any time, just running as root "swapinzram start" or "swapinzram stop" and configured editing the file /etc/swapinzram.conf. To know more, read after installation: /usr/doc/swapinzram-1/README

Caveats:
1. Tested on Slackware current, not on Slackware 14.2 (but should work there, let me know any issue).
2. If you use a huge kernel, set in /etc/swapinzram.conf COMPRESSION_ALGORITHM to anything other than zstd, like e.g. lzo-rle, cf. this request for -current.
3. Don't hibernate the machine while swap in zram is active.

Don't be afraid to test (and this is just a shell script so it's easy to check what it does), the most important issue that you could come across, I think, is a deadlock needing a hard reboot (I have not seen one reported using zram, though).

Feedback is more than welcome, of course!

Last edited by Didier Spaier; 11-26-2020 at 11:39 AM.
 
Old 11-27-2020, 08:02 AM   #2
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
@Didier would you explain why such idea? Reason for?
 
Old 11-27-2020, 11:15 AM   #3
franzen
Member
 
Registered: Nov 2012
Distribution: slackware
Posts: 535

Rep: Reputation: 379Reputation: 379Reputation: 379Reputation: 379
Quote:
Originally Posted by igadoter View Post
@Didier would you explain why such idea? Reason for?
I do have a similar zram script active on a 10 years old Thinkpad since some days, so far no issues.
I do hibernate to ram without problems, maybe it was luck ;-)
The overall performance feels better, i now have generel less IO, i think because some swapping also takes place even if not all ram is in use.
When on load(e.g. compiling something), the destop is not slowed down much anymore.
Compiling is also faster when it comes to swapping.
Maybe it's even beneficial for the battery, since IO is more expensive than compress to ram.
I use swapfiles(no partition) since years, and like the idea of swap in Ram even more.

Btw, Fedora 33 uses Zram per default.

@Didier: Why do you want to replace zramctl in your script? Since it's in util-linux it's almost always available.
Maybe lzo-rle is just good enough, and no change needed for the kernel?
https://www.phoronix.com/scan.php?pa...Better-Perform
 
1 members found this post helpful.
Old 11-27-2020, 11:44 AM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by igadoter View Post
@Didier would you explain why such idea? Reason for?
I brief, the purpose its to allow Linux users to get the best of their hardware: speed up the execution of programs and maximize the life span of some kinds of drives (mostly cheap flash drives) subject to wearing out.

Here are a few links that helped me get a very basic understanding on the matter then write the script:
The Swap Faq (Ubuntu help)
In defence of swap: common misconceptions (Chris Down)
Do we really need swap on modern systems? (Christian Horn, Red Hat blog)
Why You Should Almost Always Add Swap Space (Hayden James)
Linux Performance: Almost Always Add Swap. Part 2: ZRAM (Hayden James)
Raspberry Pi Performance: Add ZRAM and these Kernel Parameters (Hayden James)

PS. I didn't read franzen's answer before posting, he stated the benefits very clearly.

Last edited by Didier Spaier; 11-27-2020 at 11:56 AM. Reason: PSadded.
 
2 members found this post helpful.
Old 11-27-2020, 12:14 PM   #5
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by franzen View Post
@Didier: Why do you want to replace zramctl in your script? Since it's in util-linux it's almost always available.
Maybe lzo-rle is just good enough, and no change needed for the kernel?
https://www.phoronix.com/scan.php?pa...Better-Perform
Yes zramctl is almost always available, but it's not really needed just to provide information that can be get directly reading /sys. Also if the driver is updated (which happened recently adding the backend storage and also zstd) we won't need to wait zramct to be updated to draw benefit of the new features (man zramctl mentions neither at time of writing).
I have read the article on Phoronix, but when Michael Larbel wrote it zstd was not yet available for zram. For what I have read zlo-rle could be a little faster than zstd for compression/decompression but zstd offers a better compression ratio. This can interesting esp. if you have few RAM. Anyway, this can be set in the config file. And the change in the kernel wouldn't cost much time to Pat, I think - until he gets rid of the huge kernel

I did install Fedora 33 in a VM to check. IIRC they just provide a swap space in zram, not even a swap file in addition, which I find a little weird and they are not very aggressive wrt the default size of the zram block device, cf.: https://fedoraproject.org/wiki/Chang...M#swap_on_zram and https://src.fedoraproject.org/rpms/zram/tree/master.

Last edited by Didier Spaier; 11-27-2020 at 01:46 PM. Reason: Typo fix.
 
1 members found this post helpful.
Old 11-27-2020, 12:50 PM   #6
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
I am not convinced to use only ZRAM as swap - perhaps two swap devices - the second one on hd - with priority set to use ZRAM in first place. I am not quite sure it is possible.
 
Old 11-27-2020, 01:03 PM   #7
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Original Poster
Rep: Reputation: Disabled
It is indeed possible. Just give the swap space on zram a higher priority than to the one on hard disk.

Last edited by Didier Spaier; 11-27-2020 at 01:06 PM.
 
1 members found this post helpful.
Old 11-27-2020, 01:25 PM   #8
franzen
Member
 
Registered: Nov 2012
Distribution: slackware
Posts: 535

Rep: Reputation: 379Reputation: 379Reputation: 379Reputation: 379
Quote:
Originally Posted by igadoter View Post
I am not convinced to use only ZRAM as swap - perhaps two swap devices - the second one on hd - with priority set to use ZRAM in first place. I am not quite sure it is possible.
Even with a higher priority on zram, it may happen that zram get's full with later unused data, and the slow swap comes in use again.
Didier did also for that case request a kernelconfig change, for me it seems a bit weird to configure.
So for me it's simpler to just have "fast" swap.

As long it's a matter of "chmod +/-x /etc/rc.d/rc.zramswap", and have swap in /etc/fstab or not, everyone may decide as one wish.
 
Old 11-28-2020, 01:55 PM   #9
zhl
Member
 
Registered: Oct 2020
Location: Kwangchow
Distribution: Slackware
Posts: 65

Rep: Reputation: Disabled
I've been using zram for a long time. The only once zram exhaused because of running aMule compiled with wxGTK3, as linux would not like to kill process if no other choices. Since then I've been using earlyoom and zram both.
 
1 members found this post helpful.
Old 11-29-2020, 02:32 AM   #10
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
@zhl thanks for earlyoom reference. For low spec computer seems to be a must.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: ZRAM Finally Promoted Out Of Staging In Linux Kernel LXer Syndicated Linux News 0 12-19-2013 06:50 AM
LXer: zRAM Is Still Hoping For A Promotion LXer Syndicated Linux News 0 11-26-2013 02:41 AM
LXer: ZRAM Might Finally Be Moved Out Of Linux Staging LXer Syndicated Linux News 0 08-15-2013 08:10 AM
LXer: Ubuntu Linux Considers Greater Usage Of zRAM LXer Syndicated Linux News 0 12-08-2012 03:30 PM
LXer: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM) LXer Syndicated Linux News 8 10-04-2011 12:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration