LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-30-2024, 06:16 PM   #16
Aeterna
Senior Member
 
Registered: Aug 2017
Location: Terra Mater
Distribution: VM Host: Slackware-current, VM Guests: Artix, Venom, antiX, Gentoo, FreeBSD, OpenBSD, OpenIndiana
Posts: 1,022

Rep: Reputation: Disabled

well zram can't be used for hibernation. What Slackware has is ZRAM and swap. because hibernation is not allowed in zram, system uses next available device: swap partition/file
If one wants to see if this is true, disable old-fashioned swap and try to hibernate

The negative pri number means nothing and it is ignored by swap, I have -2 without setting pri in fstab. This is just kernel thing. The only thing that matters is that pri for default device must be higher that for second swap device
/dev/sda1 pri 1
/dev/sda2 pri 2
so sda2 is now default swap device

ZRAM is really not very flexible as one needs another device for hibernation and because RAM can't be encrypted then obviously ZRAm is nogo for anyone encrypting SWAP.

So ZRAM on laptop needs another swap device and it needs to be disabled if someone is encrypting swap.

ZSWAP does not have any of this limitations.

I don't think that enabling ZRAM by default is good idea.
 
Old 05-30-2024, 09:29 PM   #17
chrisretusn
Senior Member
 
Registered: Dec 2005
Location: Philippines
Distribution: Slackware64-current
Posts: 2,994

Rep: Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565
Quote:
Originally Posted by Petri Kaukasoina View Post
Another command: 'zramctl' or 'zramctl --output-all'.
Thanks!

Code:
# zramctl /dev/zram0 
NAME       ALGORITHM DISKSIZE  DATA  COMPR  TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd          7.8G  1.2G 320.5M 332.2M       4 [SWAP]
# zramctl --output-all
NAME       DISKSIZE  DATA  COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0     7.8G  1.2G 320.5M zstd            4      29770 332.2M        0B   381.5M    10.3K [SWAP]
 
Old 05-30-2024, 10:15 PM   #18
garpu
Senior Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 1,617

Original Poster
Rep: Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935
I'd say the change was overall positive on my end. It doesn't make much difference for the music stuff I do (cpu-bound), but it sure does for gaming. (of course, in the interest of testing.)
 
Old 05-31-2024, 01:04 AM   #19
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by Aeterna View Post
ZRAM is really not very flexible as one needs another device for hibernation and because RAM can't be encrypted then obviously ZRAm is nogo for anyone encrypting SWAP.

So ZRAM on laptop needs another swap device and it needs to be disabled if someone is encrypting swap.

ZSWAP does not have any of this limitations.
You don't encrypt process memory in RAM, so why would you encrypt memory pages swapped to RAM? I can understand the need to encrypt data written to a disk drive because the drive could be taken away and read afterwards. If a spy can read your swapped memory pages in RAM, they could also read them before being swapped.
 
Old 05-31-2024, 01:24 AM   #20
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
"ZRAM_WRITEBACK n -> y" was changed for kernel 6.9.3. After swap moved to ZRAM, I happened to have an extra partition /dev/sda1 which was used for swap before but I removed it from /etc/fstab now. I added command 'echo /dev/sda1 > /sys/block/zram0/backing_dev' just before the zramctl command in /etc/rc.d/rc.S to use the backing device.
Code:
# grep zram /var/log/dmesg 
[   12.471901] zram: Added device: zram0
[   12.472523] zram: setup backing device /dev/sda1
[   12.494300] zram0: detected capacity change from 0 to 32514472
[   12.520913] Adding 16257232k swap on /dev/zram0.  Priority:100 extents:1 across:16257232k SS
And to force the writebacks, I added this in /etc/cron.hourly/swap_writeback (made executable):
Code:
#!/bin/sh
echo idle > /sys/block/zram0/writeback
echo all > /sys/block/zram0/idle
echo huge > /sys/block/zram0/writeback
'echo all > /sys/block/zram0/idle' will mark all pages in zram "idle". If a page is read from swap, it's not idle any more. After an hour the script is run again, and then 'echo idle > /sys/block/zram0/writeback' will force all pages still idle to be written to the backing device. And 'echo huge > /sys/block/zram0/writeback' will force all uncompressible pages be written to the backing device.

Now I wait for the swap to get used so that I can see what happens... So far no swap is used but still one page has been written to the disk drive:
Code:
$ cat /sys/block/zram0/bd_stat 
       1        0        1
 
Old 05-31-2024, 01:33 AM   #21
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,109

Rep: Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367
And what is the goal to use the ram as swap? Is it now faster or better? Does it have any benefit?
 
Old 05-31-2024, 02:00 AM   #22
PurpleSquirrel
LQ Newbie
 
Registered: Aug 2021
Location: Here
Distribution: Slackware 2.3 to post-15.0 current
Posts: 29

Rep: Reputation: 19
Quote:
Originally Posted by Petri Kaukasoina View Post
That's a lot. Have you noticed that the hibernation image is now compressed?
No, I didn't. I was in a hurry to get the machine up and running while leaving some room for more RAM later.

Quote:

Code:
[...]
I did not change its value but read the default value by 'cat /sys/power/image_size' and created a swapfile of that size, and hibernation has succeeded with that.
I checked the value at /sys/power/image_size and saw some 5.9 GiB (plus a bit). The laptop has 16 GiB of RAM now, but I want to install 64 GiB later. I don't know what that value will be with the machine full of RAM but I do know how much RAM will be in it.
 
Old 05-31-2024, 02:28 AM   #23
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by PurpleSquirrel View Post
I checked the value at /sys/power/image_size and saw some 5.9 GiB (plus a bit). The laptop has 16 GiB of RAM now, but I want to install 64 GiB later. I don't know what that value will be with the machine full of RAM but I do know how much RAM will be in it.
The default value is 40% of the usable ram.
 
Old 05-31-2024, 06:12 AM   #24
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by Petri Kaukasoina View Post
echo /dev/sda1 > /sys/block/zram0/backing_dev

/etc/cron.hourly/swap_writeback (made executable):
Code:
#!/bin/sh
echo idle > /sys/block/zram0/writeback
echo all > /sys/block/zram0/idle
echo huge > /sys/block/zram0/writeback
...
Now I wait for the swap to get used so that I can see what happens...
I used sysctl vm.swappiness=200 and I ran thunderbird, teams, chromium, edge, firefox (with lots of tabs), builds of gcc and kernel in tmpfs. Finally it started to swap. Firefox browsing feels very smooth, quite unlike before zram.

This is after running like this for a couple of hours, so my hourly cron script has moved stuff to the backing device.
Code:
$ free
               total        used        free      shared  buff/cache   available
Mem:        16257236    12587544     1851504     7322528     9495116     3669692
Swap:       16257232     2359296    13897936
$ swapon
NAME       TYPE       SIZE USED PRIO
/dev/zram0 partition 15.5G 2.3G  100
$ zramctl --output-all
NAME       DISKSIZE  DATA  COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0    15.5G  2.2G 213.9M zstd            4      18322 300.5M        0B   639.7M    24.3K [SWAP]
$ cat /sys/block/zram0/bd_stat
  260660     4259   269639
The last command gives statistics for the backing device. The fields are the number of memory pages (of 4K) count, reads, and writes. Multiplied with 4K gives sizes of 1018M (count), 16.6M (reads), and 1053M (writes). The maximum number for count gave 1023M which seems ok, as the size of the partition /dev/sda1 is only 1024M.

cron sent me mail (write error: No space left on device) of the lines which asked for writing to the backing device when usage went to 1023M, so it would have written more if the partition were larger.

After stopping the gcc and kernel builds etc, it settles to this:
Code:
$ free
               total        used        free      shared  buff/cache   available
Mem:        16257236     2032844    12441848      368864     2508480    14224392
Swap:       16257232      423680    15833552
$ swapon
NAME       TYPE       SIZE   USED PRIO
/dev/zram0 partition 15.5G 413.8M  100
$ zramctl --output-all
NAME       DISKSIZE   DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0    15.5G 413.2M 49.3M zstd            4       9793  103M        0B   639.7M    24.3K [SWAP]
$ cat /sys/block/zram0/bd_stat
   42567    45276   269639
bd_count=42567 means 166M left in the backing device now.

Edit: After some idle time and a run of my cron script again now that the size of /dev/sda1 is enough to contain everything:
Code:
$ free
               total        used        free      shared  buff/cache   available
Mem:        16257236      820960    12044668       30044     3778724    15436276
Swap:       16257232      173824    16083408
$ swapon
NAME       TYPE       SIZE   USED PRIO
/dev/zram0 partition 15.5G 169.8M  100
$ zramctl
NAME       ALGORITHM DISKSIZE   DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd         15.5G 169.2M    0B    0B       4 [SWAP]
$ cat /sys/block/zram0/bd_stat 
   39082    60514   314603
Now all zram pages have been written to the backing device.

I don't think it's necessarily a good idea to write pages from zram to the backing device hourly. I only used it for test. Maybe daily would be better.

Or only move those uncompressible pages that have been idle since the last cron run:
/etc/cron.hourly/swap_writeback (made executable):
Code:
#!/bin/sh
echo huge_idle > /sys/block/zram0/writeback
echo all > /sys/block/zram0/idle

Last edited by Petri Kaukasoina; 05-31-2024 at 10:38 AM.
 
Old 05-31-2024, 07:22 AM   #25
Aeterna
Senior Member
 
Registered: Aug 2017
Location: Terra Mater
Distribution: VM Host: Slackware-current, VM Guests: Artix, Venom, antiX, Gentoo, FreeBSD, OpenBSD, OpenIndiana
Posts: 1,022

Rep: Reputation: Disabled
Quote:
Originally Posted by Petri Kaukasoina View Post
You don't encrypt process memory in RAM, so why would you encrypt memory pages swapped to RAM? I can understand the need to encrypt data written to a disk drive because the drive could be taken away and read afterwards. If a spy can read your swapped memory pages in RAM, they could also read them before being swapped.
If ZRAM works as swap, then it will leave files in swap unencrypted. Reason whay disk swap is encrypted if one is concerned about privacy.
I never bothered with whole system encryption, but this is a weakness.

Also is zramctl aware of zram_writeback because it wasn't.

Finally, it looks like one has to work really hard to make system swap even with 16GB RAM. On the laptop with 32GB RAM I never witnessed Slackware swapping. I have seen Gentoo swapping though with system update.

I doubt that swapping while working on audio is good idea at all. Does not matter how system swaps. Not to mention that CPU is used too. For audio that is really bad scenario.

Why force swapping if system is happy with RAM (way faster than any type of swap). I would make sure that system does not swap at all.

Swapping is server problem shouldn't be desktop.

Nowadays, only old hardware doen not have 16GB or more. In such case of old systems with not capable CPU, slow disk and inadequate RAM it will cause slowdowns anyway.

Last edited by Aeterna; 05-31-2024 at 07:23 AM.
 
Old 05-31-2024, 07:52 AM   #26
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by Aeterna View Post
If ZRAM works as swap, then it will leave files in swap unencrypted. Reason whay disk swap is encrypted if one is concerned about privacy.
I never bothered with whole system encryption, but this is a weakness.
What do you mean by files in swap? Processes have memory pages in RAM and after swapping to ZRAM, the memory pages are still in RAM, only compressed.
 
Old 05-31-2024, 08:16 AM   #27
rizitis
Member
 
Registered: Mar 2009
Location: Greece,Crete
Distribution: Slackware64-current, Slint
Posts: 722
Blog Entries: 2

Rep: Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533
Well after 24 hours of using zram in my main laptop i have to say that for my needs zram is not what i need.
I have 64Gi ddr5 and nothing else no swap etc.
My cpu is 12700h , very good cpu for needs. I can compile very fast huge programms , and load ai models locally on cpu (llama.cpp).
Load models with zram make crazy cpu 498% of use...
Note this cpu is locked from factory.
Also fans work like helicopters because of cpu madness....

So my point is that its good we have zram in Slackware, for some people it might be very useful, for others like me it will not be... But in any case it needs correctly setup in every system according to hardware and according to software which running.
 
Old 05-31-2024, 08:27 AM   #28
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by rizitis View Post
Well after 24 hours of using zram in my main laptop i have to say that for my needs zram is not what i need.
I have 64Gi ddr5 and nothing else no swap etc.
My cpu is 12700h , very good cpu for needs. I can compile very fast huge programms , and load ai models locally on cpu (llama.cpp).
Load models with zram make crazy cpu 498% of use...
Note this cpu is locked from factory.
Also fans work like helicopters because of cpu madness....

So my point is that its good we have zram in Slackware, for some people it might be very useful, for others like me it will not be... But in any case it needs correctly setup in every system according to hardware and according to software which running.
If I understood you correctly, you normally don't use swap but now you used swap in zram. Did the system actually use swap according to 'free'? And the result of swap was that your program could run using 5 threads at full speed (498%) compared to only what percentage without swap?

There is a reason why some swap space is useful even when the system seems to work without it. If there is memory pressure and the OS can't evict any other memory pages (because of no swap space), it will discard file-backed pages, because they can always be read back from the file system. Like program code and libraries. Then you lose time reading pages from the drive, discarding them, reading, discarding, ad infinitum. Lots of IO but little user CPU time.

It seems to me that swap on zram is good for that reason, and it doesn't need disk space and is fast. And if swap is not used, it does no harm.

Last edited by Petri Kaukasoina; 05-31-2024 at 08:42 AM.
 
Old 05-31-2024, 08:48 AM   #29
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,109

Rep: Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367Reputation: 7367
Quote:
Originally Posted by Petri Kaukasoina View Post
There is a reason why some swap space is useful even when the system seems to work without it. If there is memory pressure and the OS can't evict any other memory pages (because of no swap space), it will discard file-backed pages, because they can always be read back from the file system. Like program code and libraries. Then you lose time reading pages from the drive, discarding them, reading, discarding, ad infinitum. Lots of IO but little user CPU time.

It seems to me that swap on zram is good for that reason, and it doesn't need disk space and is fast. And if swap is not used, it does no harm.
But if you have more RAM because there is no swap in (z)ram the OS will have more room to avoid swapping. It will "automatically" lower that memory pressure.

Anyway, here is a link about swap: https://chrisdown.name/2018/01/02/in...e-of-swap.html
 
1 members found this post helpful.
Old 05-31-2024, 09:28 AM   #30
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,960

Rep: Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571Reputation: 1571
Quote:
Originally Posted by pan64 View Post
But if you have more RAM because there is no swap in (z)ram the OS will have more room to avoid swapping. It will "automatically" lower that memory pressure.
It will lower the memory pressure more when the same pages are in zram because they are compressed there. But anyway, if there is no need to put any pages in the swap in zram, the memory usage of zram is negligible.

Quote:
Originally Posted by pan64 View Post
Yes, that's a good read.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:22 PM.

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