Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
1
votes
0
answers
91
views
How does the output of zramctl relate to swapped memory usage?
I have a Raspberry PI 5 with 8GB of ram. I have allocated a zram swap partition with disksize of 1GB, which after a few days is now being used. $ free -hw total used free shared buffers cache available Mem: 7.8Gi 4.1Gi 390Mi 258Mi 855Mi 3.1Gi 3.6Gi Swap: 1.0Gi 694Mi 329Mi $ zramctl NAME ALGORITHM DI...
I have a Raspberry PI 5 with 8GB of ram. I have allocated a zram swap partition with disksize of 1GB, which after a few days is now being used.
$ free -hw
total used free shared buffers cache available
Mem: 7.8Gi 4.1Gi 390Mi 258Mi 855Mi 3.1Gi 3.6Gi
Swap: 1.0Gi 694Mi 329Mi
$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle 1G 445.6M 78.4M 82.6M 4 [SWAP]
$ zramctl --output-all
NAME DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0 1G 445.6M 78.4M lzo-rle 4 263 82.6M 0B 116.5M 5.3K [SWAP]
The "free" program states that I am using about 70% of my zram swap (~700MB). The graphical memory display of "top" agrees with this.
Looking at zramctl, it agrees on disksize, but the only way I can make any sense of this is to assume that my swap contains 445.6MB of swapped data (compressed from ~700MB).
If this _is_ the case, what is the meaning of the other columns in zramctl output (most importantly, COMPR, TOTAL, & MEM-USED). If not, please point out my misunderstanding.
I have read the kernel documentation, but that is mostly regarding the zram "core", rather than actual operation of swap.
m4r35n357
(111 rep)
Feb 27, 2025, 03:10 PM
• Last activity: Jul 28, 2025, 12:09 PM
5
votes
1
answers
724
views
How much percentage should zram take?
I'm setting up zram on my server, let's say I have 4GB ram, should zram take 3.5G or 1G or something in between? What trade off will I have when going to the extremes? And, for example I have a single thread that's taking 30mb of ram in zram, when this thread gets invoked by other threads, does the...
I'm setting up zram on my server, let's say I have 4GB ram, should zram take 3.5G or 1G or something in between? What trade off will I have when going to the extremes?
And, for example I have a single thread that's taking 30mb of ram in zram, when this thread gets invoked by other threads, does the system uncompress all the zram in ram and run the thread in ram, or the system just read and write the zram in place?
Pegasis
(151 rep)
Apr 6, 2021, 11:17 AM
• Last activity: Jun 21, 2025, 02:55 PM
0
votes
0
answers
53
views
How is zram memory usage accounted for in Linux
The compressed RAM actually in use by zram (from the MEM-USED column of zramctl --output-all) should in practice be visible in the data from the "free" command. I assume that it is accounted for in the "used" column (I can see it is not subtracted from the "total" column!). Is this correct? (However...
The compressed RAM actually in use by zram (from the MEM-USED column of zramctl --output-all) should in practice be visible in the data from the "free" command. I assume that it is accounted for in the "used" column (I can see it is not subtracted from the "total" column!). Is this correct?
(However, it is not "used" in the sense of "eligible for swap", like resident program memory, so perhaps a separate column would be more appropriate . . .)
Example:
$ free -hw
total used free shared buffers cache available
Mem: 2.8Gi 2.4Gi 208Mi 65Mi 7.6Mi 459Mi 456Mi
Swap: 3.0Gi 1.2Gi 1.8Gi
$ zramctl --output-all
NAME DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0 3G 1.2G 262.6M lz4 2 15281 270.1M 0B 321.3M 18.6K [SWAP]
m4r35n357
(111 rep)
May 7, 2025, 02:14 PM
• Last activity: May 7, 2025, 02:25 PM
7
votes
1
answers
11758
views
Why does zram occupy much more memory compared to its "compressed" value?
I set up zram and made extensive tests inside my Linux machines to measure that it really helps in my scenario. However, I'm very confused that zram *seems* to use up memory of the whole uncompressed data size. When I type in "zramctl" I see this: NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOU...
I set up zram and made extensive tests inside my Linux machines to measure that it really helps in my scenario. However, I'm very confused that zram *seems* to use up memory of the whole uncompressed data size. When I type in "zramctl" I see this:
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 2G 853,6M 355,1M 367,1M 4 [SWAP]
According to the help command of zramctl ,
DATA
is the uncompressed size and TOTAL
the compressed memory including metadata. Yet, when I type in swapon -s
, I see this output:
Filename Type size used Priority
/dev/sda2 partition 1463292 0 4
/dev/zram0 partition 2024224 906240 5
906240
is the used memory in Kilobytes, which translates to the 853,6M DATA
value of zramctl. Which leaves the impression that the compressed zram device needs more memory than it saves. Once DATA
is full, it actually starts swapping to the disk drive, so it must be indeed full.
Why does zram seemingly occupy memory of the original data size? Why is it not the size of COMPR
or TOTAL
? It seems there is no source about that on the Internet yet, because I haven't found any information about this. Thank you!
Testerhood
(419 rep)
Jun 24, 2020, 02:36 PM
• Last activity: Apr 16, 2025, 12:17 AM
4
votes
1
answers
200
views
zramctl showing incorrect values
I have setup a ```zram``` with the ```zram-generator``` package on a Manjaro (stable) install. I don't have any other swap configured. When I run the ```zramctl``` command, the given values are significantly lower than what swap uses (see command outputs below). ```zramctl```, where ```DATA``` is th...
I have setup a
with the -generator
package on a Manjaro (stable) install. I don't have any other swap configured. When I run the
command, the given values are significantly lower than what swap uses (see command outputs below).
, where
is the size of the uncompressed data on the ramdisk,
is the compressed data and
is the current size of the ramdisk:
$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 31,3G 10,2G 3,2G 3,4G 12 [SWAP]
Output of
:
$ swapon
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 31,3G 14,8G 100
And output of
(it's also interesting that it cuts off the decimal part on used, but not relevant here):
$ free -h
total used free shared buff/cache available
Mem: 31Gi 24Gi 2,5Gi 314Mi 6,0Gi 6,4Gi
Swap: 31Gi 14Gi 16Gi
/proc/meminfo
contains some relevant info as well:
$ cat /proc/meminfo | grep swap
Zswap: 993724 kB
Zswapped: 4745548 kB
What is strange here is that if I subtract this
value from used swap, I get approximately the
report
value
My question is - even though swapping seems to work fine - why is this the case? Is it a problem with
?
Light Darkmatter
(66 rep)
Jul 7, 2024, 09:17 PM
• Last activity: Mar 22, 2025, 01:12 AM
14
votes
5
answers
29742
views
How to set up properly zram and swap
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram. Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram.
Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
Maja Piechotka
(16936 rep)
Jul 22, 2011, 09:45 PM
• Last activity: Jul 12, 2024, 08:45 PM
22
votes
4
answers
18560
views
What is the appropriate value of vm.swappiness when using zram?
I'm using zram on my computer as a compressed RAM-backed swap. When the system needs to swap something out, swapping it to a zram-backed swap file is more or less equivalent to compressing that data in-memory to free up space. This makes swapping very fast most of the time, relative to disk-backed s...
I'm using zram on my computer as a compressed RAM-backed swap. When the system needs to swap something out, swapping it to a zram-backed swap file is more or less equivalent to compressing that data in-memory to free up space. This makes swapping very fast most of the time, relative to disk-backed swap. Because of this, I wonder if there is some performance to be gained by encouraging the system to swap out unused stuff more aggressively, since it can do so without actually hitting the disk?
So has anyone messed around with, say, setting
vm.swappiness
to 100 while using zram? Would this be desirable?
sysctl -w vm.swappiness=100
Ryan C. Thompson
(5520 rep)
Mar 12, 2012, 09:26 PM
• Last activity: Apr 8, 2024, 01:24 PM
0
votes
1
answers
51
views
Can you mount heap onto zram
I'm new to zram, and reading the documentation it looks like it mounts something similar to a filesystem under `/dev/zram `. If I understand correctly, anything stored here would be similar to tmpfs, except it would be swapped out to compressed ram. I'm wondering if this concept can be applied to th...
I'm new to zram, and reading the documentation it looks like it mounts something similar to a filesystem under
/dev/zram
. If I understand correctly, anything stored here would be similar to tmpfs, except it would be swapped out to compressed ram.
I'm wondering if this concept can be applied to the heap of a program, such that any memory in the heap would be swapped to compressed ram instead of hdd?
HardcoreHenry
(111 rep)
Feb 15, 2024, 06:22 PM
• Last activity: Feb 15, 2024, 07:17 PM
3
votes
1
answers
730
views
How to change zram sector size?
I have cloned a disk into a sparse file that is about 80G but indeed requires only about 12G, even not compressed it fits on my memory, but in order to save some resources I want to use **zram**: sudo modprobe zram num_devices=1 echo 79999997952 | sudo tee /sys/block/zram0/disksize sudo fdisk -c=dos...
I have cloned a disk into a sparse file that is about 80G but indeed requires only about 12G, even not compressed it fits on my memory, but in order to save some resources I want to use **zram**:
sudo modprobe zram num_devices=1
echo 79999997952 | sudo tee /sys/block/zram0/disksize
sudo fdisk -c=dos --sector-size 512 /dev/zram0
However when I create the partition it is using 4096 sector size even I told **fdisk** to use 512.
It do not let me type the size of the partition based on 512 sector size, and it is not a exact number which I could divide by 8 in order to have a 4096 based one, so I have done on a sparse **mbr**:
truncate -s79999997952 /tmp/block
fdisk -c=dos --sector-size 512 /tmp/block
# o, n, p, 1, 63, 156232124, t, 7, a, w
sudo dd if=/tmp/block of=/dev/zram0 count=1 bs=512
It seems with regular files **fdisk** sees no problem in using a 512 sector size! But **zram** is still weird, I do not know if it is going to work, because it shows a different disk size when on 512 mode:
$ sudo fdisk -lu /dev/zram0
Disk /dev/zram0: 74.5 GiB, 80000000000 bytes, 19531250 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x5f8b6465
Device Boot Start End Sectors Size Id Type
/dev/zram0p1 * 63 156232124 156232062 596G 7 HPFS/NTFS/exFAT
$ sudo fdisk -lu --sector-size 512 /dev/zram0
Disk /dev/zram0: 9.3 GiB, 10000000000 bytes, 19531250 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x5f8b6465
Device Boot Start End Sectors Size Id Type
/dev/zram0p1 * 63 156232124 156232062 74.5G 7 HPFS/NTFS/exFAT
Understand, once
156232062 / 8 = 19529007.75
there is no way it can fit on 4096 sector size.
How to force **fdisk** or the **zram** itself to use 512 sector size?
Tiago Pimenta
(646 rep)
Mar 5, 2019, 02:45 PM
• Last activity: Dec 20, 2023, 04:52 PM
0
votes
0
answers
539
views
Arch: Recreate Swap Partition?
I'm running arch, installed with [archinstall][1]. I read that arch uses [zram][2] for swapping, not disk. Also read somewhere that zram doesn't use disk for swap, so i don't need a swap partition. (I don't get why archinstall creates a swap partition if it's not needed) Believing it wasn't needed,...
I'm running arch, installed with archinstall .
I read that arch uses zram for swapping, not disk. Also read somewhere that zram doesn't use disk for swap, so i don't need a swap partition. (I don't get why archinstall creates a swap partition if it's not needed)
Believing it wasn't needed, i deleted the swap partition (using cfdisk from the Live ISO).
Now arch won't boot. I'm getting a message about waiting 10 seconds for a partition, and then i get dropped into emergency shell.
Loading keymap.... Done.
Waiting 10 seconds for device /dev/disk/by-partuuid/ecec0......[long number]
Error: Device /dev/disk/by-partuuid/ecec0......[long number] not found.
I attempted to recreate a swap partition in the same location on disk, using cfdisk, of "Linux Swap" type. Then i did mkswap on the reformatted swap partition.
# mkswap /dev/sdb2
But still not booting.
Do i need to change a partition ID in a grub config file?
I also attempted to mount the boot partition from the live ISO, and chroot into it, but that fails.
# mount /dev/sdb1 /mnt
# arch-chroot /mnt
chroot: failed to run command /bin/bash No such file or directory.
# chroot /mnt
chroot: failed to run command /usr/bin/zsh No such file or directory.
johny why
(371 rep)
Sep 4, 2023, 04:24 AM
• Last activity: Sep 4, 2023, 05:46 AM
1
votes
2
answers
2122
views
Effect of enabling zswap on zram without any disk swap
I have set up a system that has 4 GB RAM with 1.5 GiB of zram. It also has zswap enabled. I don't have any swap partition on the secondary storage. As I have noticed, the performance is good on my systems. Is the zswap being used on zram? Can using zswap on zram lead to any performance issues?
I have set up a system that has 4 GB RAM with 1.5 GiB of zram. It also has zswap enabled. I don't have any swap partition on the secondary storage.
As I have noticed, the performance is good on my systems.
Is the zswap being used on zram? Can using zswap on zram lead to any performance issues?
15 Volts
(2149 rep)
Nov 29, 2019, 07:11 AM
• Last activity: May 21, 2023, 02:35 AM
1
votes
0
answers
206
views
initramfs on zram
I use a minimal initramfs as my root filesystem which I load from the network. Since the initramfs is just there to get the system started (and I have no other rootfs) I'd like it to take up as little memory as possible. From what I understand the initramfs loads into /dev/ram0. Is it possible to lo...
I use a minimal initramfs as my root filesystem which I load from the network. Since the initramfs is just there to get the system started (and I have no other rootfs) I'd like it to take up as little memory as possible. From what I understand the initramfs loads into /dev/ram0.
Is it possible to load initramfs into /dev/zram0?
Fallen
(161 rep)
Aug 19, 2022, 04:18 PM
• Last activity: Feb 26, 2023, 08:37 PM
0
votes
1
answers
3335
views
PopOS 22.04 - Swappiness ZRAM value, size
How to change the "zram" size in PopOS 22.04? I did not create a ram partition, I was automatically added zram, which is 16.6 gb. It has a swappiness of 180, I want to change it to swappines 10 and reduce it from 16.6 gb to 2 GB. How to do it? PopOS 22.04
How to change the "zram" size in PopOS 22.04? I did not create a ram partition, I was automatically added zram, which is 16.6 gb. It has a swappiness of 180, I want to change it to swappines 10 and reduce it from 16.6 gb to 2 GB. How to do it?
PopOS 22.04
virtual_robot
(11 rep)
Jan 27, 2023, 09:17 PM
• Last activity: Feb 6, 2023, 04:34 PM
1
votes
1
answers
329
views
Any way to create zram disk (not swap) during boot time except via script?
https://askubuntu.com/questions/130374/ramdisk-compressed-writeable-no-swap Gives script to make zram disk (load module, set parameter, format block device, mount). Is there any way to have same result via `/etc/fstab`? I guess if not best way to run the script is via `Systemd` (system is Linux Mint...
https://askubuntu.com/questions/130374/ramdisk-compressed-writeable-no-swap
Gives script to make zram disk (load module, set parameter, format block device, mount). Is there any way to have same result via
/etc/fstab
? I guess if not best way to run the script is via Systemd
(system is Linux Mint)? TIA
Edited part of the script:
modprobe zram num_devices=1
echo 256M > /sys/block/zram0/disksize
mke2fs -q -m 0 -b 4096 -O sparse_super -L zram /dev/zram0
mount -o discard /dev/zram0 /mount_point
Alex Martian
(1287 rep)
Nov 11, 2022, 09:51 AM
• Last activity: Nov 12, 2022, 07:02 AM
1
votes
1
answers
888
views
Can't mount zram device on /tmp (Booting problem)
I have a simple script that creates a zram device and formats it to ext4 and finally, it mounts zram on /tmp. ``` #!/bin/bash # create zram with size 1.5G # $zram_dev is created device path (eg. /dev/zram1) zram_dev=$(/usr/sbin/zramctl -f -s 1536M) # format it to ext4 yes | /usr/sbin/mkfs.ext4 $zram...
I have a simple script that creates a zram device and formats it to ext4 and finally, it mounts zram on /tmp.
#!/bin/bash
# create zram with size 1.5G
# $zram_dev is created device path (eg. /dev/zram1)
zram_dev=$(/usr/sbin/zramctl -f -s 1536M)
# format it to ext4
yes | /usr/sbin/mkfs.ext4 $zram_dev
# mount it on /tmp
/usr/bin/mount $zram_dev /tmp
It works when I manually run it.
But obviously, I don't want to run it after every login.
I put that script in root crontab and I rebooted the system, and then I couldn't get my graphical interface, I removed it from crontab and everything worked fine.
And at the end of the day, I changed the mount directory to something else like /zram and rebooted the system, surprisingly system comes up. (zram device was created and was mounted on /zram)
I should mention that I tried to do that automation with systemd service and I get the same result
I just want to know why I can't mount the zram device on /tmp?
OS: Linux fedora 5.17.5-300.fc36.x86_64 #1 SMP PREEMPT x86_64 x86_64 x86_64 GNU/Linux
linux user
(11 rep)
Jul 16, 2022, 09:18 AM
• Last activity: Sep 11, 2022, 05:46 PM
0
votes
0
answers
111
views
How to limit swap usage without using sysctl or resizing the partition?
There is the following scenario: I have an HDD disk that uses LVM and I cannot resize the partitions in it, in this disk, there is a swap partition that is 10gb. I also use zram apart from disk based swap, so I cannot tweak sysctl parameters because I am using these values to make zram work well. Al...
There is the following scenario: I have an HDD disk that uses LVM and I cannot resize the partitions in it, in this disk, there is a swap partition that is 10gb. I also use zram apart from disk based swap, so I cannot tweak sysctl parameters because I am using these values to make zram work well. Also, the swap disk has -1 priority while the zram is top priority, nevertheless, the swap disk usage is way higher than it should be, so I thought resizing it to 1gb would avoid this.
The only option that I thought about was setting up fstab to pretend the swap is smaller than it is, but as I researched, could not found a way to configure it.
The information about the disk is the following:
┌──(root💀debian)-[~skid]
└─# pvdisplay -m
--- Physical volume ---
PV Name /dev/mapper/sda3_crypt
VG Name debian-vg
PV Size <930.52 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 238212
Free PE 0
Allocated PE 238212
PV UUID 3SCpEr-CHMe-96gN-mN9y-goNs-3ZOj-Mk4JcD
--- Physical Segments ---
Physical extent 0 to 2383:
Logical volume /dev/debian-vg/swap
Logical extents 0 to 2383
Physical extent 2384 to 238211:
Logical volume /dev/debian-vg/root
Logical extents 0 to 235827
Overclocked Skid
(126 rep)
May 26, 2022, 11:52 PM
• Last activity: May 27, 2022, 09:36 PM
4
votes
3
answers
1679
views
Does swap on zram free backing pages when pages are unswapped from it?
Imagine a scenario where 2GiB is swapped out to zram and compresses down to 1GiB. Once the memory pressure is alleviated and the 2GiB gradually become unswapped, does Linux free the 1GiB of pages that were used to store the compressed zram pages? If so, does it defragment existing pages? There must...
Imagine a scenario where 2GiB is swapped out to zram and compresses down to 1GiB.
Once the memory pressure is alleviated and the 2GiB gradually become unswapped, does Linux free the 1GiB of pages that were used to store the compressed zram pages?
If so, does it defragment existing pages?
There must be multiple pages in a compressed page, what happens when all but one are unswapped? Do all pages stay in memory until that last page is freed aswell?
Atemu
(857 rep)
Feb 13, 2022, 08:58 AM
• Last activity: May 20, 2022, 01:54 PM
1
votes
1
answers
642
views
Explain Zram and Swap numbers
Ok, so there are really 2 questions here, why is my on disk swap being used? Is the compression of my swap really this good? It seems pretty unlikely, but it's also possible it is because it's memory that applications (like the JVM) have reserved, but aren't actually using. ``` Linux manjaro 5.10.59...
Ok, so there are really 2 questions here, why is my on disk swap being used? Is the compression of my swap really this good? It seems pretty unlikely, but it's also possible it is because it's memory that applications (like the JVM) have reserved, but aren't actually using.
Linux manjaro 5.10.59-1-MANJARO #1 SMP PREEMPT Sun Aug 15 13:11:32 UTC 2021 x86_64 GNU/Linux
Here's my initial measurements
❯ swapon
NAME TYPE SIZE USED PRIO
/dev/nvme0n1p6 partition 32.2G 2.4G -2
/dev/zram0 partition 4G 3.5G 100
❯ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 4G 42.4M 42.4M 42.4M 8 [SWAP]
❯ cat /proc/meminfo
MemTotal: 16138912 kB
MemFree: 506156 kB
MemAvailable: 1338368 kB
Buffers: 32 kB
Cached: 3733980 kB
SwapCached: 2874732 kB
Active: 6357760 kB
Inactive: 7098592 kB
Active(anon): 5746908 kB
Inactive(anon): 6665988 kB
Active(file): 610852 kB
Inactive(file): 432604 kB
Unevictable: 367084 kB
Mlocked: 224 kB
SwapTotal: 37986296 kB
SwapFree: 31745392 kB
Dirty: 2172 kB
Writeback: 0 kB
AnonPages: 7635524 kB
Mapped: 628752 kB
Shmem: 2692308 kB
KReclaimable: 104768 kB
Slab: 330300 kB
SReclaimable: 104768 kB
SUnreclaim: 225532 kB
KernelStack: 25600 kB
PageTables: 81764 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 46055752 kB
Committed_AS: 24622488 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 110656 kB
VmallocChunk: 0 kB
Percpu: 7552 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 813792 kB
DirectMap2M: 15714304 kB
DirectMap1G: 0 kB
❯ free -h
total used free shared buff/cache available
Mem: 15Gi 11Gi 274Mi 2.5Gi 3.9Gi 1.4Gi
Swap: 36Gi 6.0Gi 30Gi
❯ sudo swapoff /dev/nvme0n1p6
After swapoff
❯ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 4G 42.9M 42.9M 42.9M 8 [SWAP]
❯ swapon
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 4G 3.5G 100
❯ cat /proc/meminfo
MemTotal: 16138912 kB
MemFree: 450240 kB
MemAvailable: 1018456 kB
Buffers: 28 kB
Cached: 3643988 kB
SwapCached: 1249912 kB
Active: 6562884 kB
Inactive: 7350540 kB
Active(anon): 5994940 kB
Inactive(anon): 7018496 kB
Active(file): 567944 kB
Inactive(file): 332044 kB
Unevictable: 168744 kB
Mlocked: 224 kB
SwapTotal: 4194300 kB
SwapFree: 115892 kB
Dirty: 696 kB
Writeback: 0 kB
AnonPages: 9229592 kB
Mapped: 477084 kB
Shmem: 2744240 kB
KReclaimable: 105376 kB
Slab: 326216 kB
SReclaimable: 105376 kB
SUnreclaim: 220840 kB
KernelStack: 26096 kB
PageTables: 83560 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 12263756 kB
Committed_AS: 25151912 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 115640 kB
VmallocChunk: 0 kB
Percpu: 7552 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 821984 kB
DirectMap2M: 15706112 kB
DirectMap1G: 0 kB
❯ cat /proc/swaps
Filename Type Size Used Priority
/dev/zram0 partition 4194300 4086744 100
❯ free -h
total used free shared buff/cache available
Mem: 15Gi 10Gi 1.0Gi 2.6Gi 4.1Gi 2.1Gi
Swap: 4.0Gi 3.9Gi 97Mi
`
So why is zram only 42M? Is that really what it has compressed down to from 3.5G? If that's true, why is my swap partition being used? should't all of it be in zram
?
xenoterracide
(61203 rep)
Aug 26, 2021, 03:01 AM
• Last activity: Apr 16, 2022, 06:22 PM
5
votes
1
answers
2232
views
Using loopdev for zRAM writeback feature
Documentation states that zRAM writeback feature supports only swap partitions as it's `backing_dev`. But I've successfully used a swap file too, by attaching it to a loop device ``` losetup /dev/loop0 /swapfile cd /sys/block/zram0 echo /dev/loop0 > backing_dev echo 8G > disksize mkswap /dev/zram0 s...
Documentation states that zRAM writeback feature supports only swap partitions as it's
backing_dev
. But I've successfully used a swap file too, by attaching it to a loop device
losetup /dev/loop0 /swapfile
cd /sys/block/zram0
echo /dev/loop0 > backing_dev
echo 8G > disksize
mkswap /dev/zram0
swapon /dev/zram0
After this, swapon -s
shows zRAM device enabled, cat /sys/block/zram0/backing_dev
returns /dev/loop0
and echo huge > /sys/block/zram0/writeback
works with no problem, with cat /sys/block/zram0/bd_stats
confirming that the write indeed succeeded
Can this be used, or does this method have some kind of nasty drawbacks?
Роман Мавроян
(787 rep)
Apr 20, 2020, 07:00 AM
• Last activity: Apr 4, 2022, 04:32 PM
2
votes
1
answers
409
views
Get % used of zram in script
I've got a script that collects various bits of system data and reports this via MQTT to a central local server. I recently implemented zram with priority over swap to see if this offers a performance boost. As part of monitoring this I need to be able to workout the % used zram, so that it can be r...
I've got a script that collects various bits of system data and reports this via MQTT to a central local server. I recently implemented zram with priority over swap to see if this offers a performance boost. As part of monitoring this I need to be able to workout the % used zram, so that it can be reported.
I know that I can see basic stats for swap & zram with the following commands:
cat /proc/swap
or swapon -s
Filename Type Size Used Priority
/var/swap file 102396 0 -2
/dev/zram0 partition 5055516 170752 5
or
zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4 4.8G 165.5M 58.4M 62.8M 4 [SWAP]
But these don't present a % used and in the case of the first 2 commands also report the standard swap. Is there a way to determine & output the % used zram and nothing else in a single-line command?
edit:
It looks like swapon -s
offers the easiest results to use since it gives size and used values in the zram line. If anyone can offer a way to return just the %used I'd really appreciate it.
Thanks.
Phill Healey
(123 rep)
May 23, 2020, 08:23 PM
• Last activity: Jan 3, 2022, 11:15 AM
Showing page 1 of 20 total questions