Code: Select all
init=/sbin/openrc-init
-systemd -logind -elogind seatdI am NaN! I am a man!
Code: Select all
init=/sbin/openrc-init
-systemd -logind -elogind seatdI am NaN! I am a man!
zram by default does not have backing storage, it will not use normal swap as back storage. You need to manual configure a back store.Zucca wrote:@pingtoo: I use(d) zram as my portage temporary directory. Not as swap.
I don't use zswap. Let's not mix zswap into the issue here.
I don't have any backing devices for my zram devices as they only host temporary files.
I think I'll convert all (or most) places where I used zram to tmpfs. And maybe enable zswap to have some compression.
If you have LVM installed you can setup like this (This is how I use zram from another machine)zram: Compressed RAM-based block devices:Optional Feature wrote:With CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via:Code: Select all
echo /dev/sda5 > /sys/block/zramX/backing_dev
Code: Select all
nbd-client -N zram littleboy /dev/nbd0
pvcreate -y /dev/nbd0
vgextend vg0 /dev/nbd0
lvcreate --extents 100%PV -n ramdisk vg0 /dev/nbd0
lvextend -L +10G vg0/ramdisk
mkfs.ext4 -O ^has_journal /dev/vg0/ramdisk
mount -o noatime /dev/vg0/ramdisk /chroot/var/tmpCode: Select all
nbd-serverCode: Select all
# This is /etc/nbd-server/config
# This is nbd-server configuration file stored in /etc/nbd-server/config
# This is used in docker container
# listenaddr = 0.0.0.0 bind to docker IPv4 address
# max_threads = 4 because RPI 4 only have 4 CPU cores.
# splice = true for <1MiB none TLS I/O
[generic]
listenaddr = 0.0.0.0
root = root
group = root
max_threads = 4
splice = true
[zram]
exportname = /dev/zram0
virtstyle = none
copyonwrite = falseA-ha! I had completely misunderstood the meaning of this backing device. This explains it! Thanks! [SOLVED]pingtoo wrote:zram by default does not have backing storage, it will not use normal swap as back storage. You need to manual configure a back store.zram: Compressed RAM-based block devices:Optional Feature wrote:With CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via:Code: Select all
echo /dev/sda5 > /sys/block/zramX/backing_dev
Code: Select all
init=/sbin/openrc-init
-systemd -logind -elogind seatdI am NaN! I am a man!
Code: Select all
echo idle > /sys/block/zramX/writebacktnt,tnt wrote:I have set up zram in order to test it for swap purposes (200MB zram device, 10GB backing_dev SSD partition), but although I have added backing_dev, pages never get written to it. I run out of memory sooner.
So, my question is: should zram writeback to backing_dev automatically, or only by explicit command like:
Code: Select all
echo idle > /sys/block/zramX/writeback
Code: Select all
echo 1 > /sys/block/zramX/reset
echo /dev/<dev_partition> > /sys/block/zramX/backing_dev
echo NNNg > /sys/block/zramX/disksize
echo 200m > /sys/block/zramX/mem_limit
# follow is optinal
echo huge > /sys/block/zramX/writeback
# end option
echo all > /sys/block/zramX/idle
echo idle > /sys/block/zramX/writebackWhile you create pressure to memory, can you also dotnt wrote:I have tried suggested approach and it seems it writes pages out to backing device once, but next memory pressure produces OOM event instead of writing more pages to backing device in the real-time
Code: Select all
cat /sys/block/zramX/bd_statCode: Select all
cat /sys/block/zramX/mm_statCode: Select all
cat /sys/kernel/debug/zram/zram0/block_stateCode: Select all
cat /sys/block/zram0/bd_statThis explains a lot.Remember the backing_dev is not a swap concept, it will always hold zram pages unless those pages are free. it will only move zram page into backing_dev when the page is marked idle (i.e no read access) if those pages are needed, it will need zram space to pull them back.
Code: Select all
# cat /proc/meminfo |grep -i swap
SwapCached: 1903236 kB
SwapTotal: 4194300 kB
SwapFree: 1643268 kB
# zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4 4G 633.9M 191.8M 200M 4 [SWAP]
# cat /sys/block/zram0/bd_stat
0 0 0
# swapon -s
Filename Type Size Used Priority
/dev/zram0 partition 4194300 2551032 16000
#Code: Select all
#print various stats info about zram swap device
zram_stats()
{
local zdev="/sys/block/$( basename "$1" )"
printf "\nGathering stats info for zram device \"$( basename "$1" )\"\n\n"
printf "Z-RAM\n-----\n"
printf "%-25s - %s\n" "Block device" $zdev
awk '{ printf "%-25s - %d MiB\n", "Device size", $1/1024/1024 }' <$zdev/disksize
printf "%-25s - %s\n" "Compression algo" "$(cat $zdev/comp_algorithm)"
awk 'BEGIN { fmt = "%-25s - %.2f %s\n"
fmt2 = "%-25s - %d\n"
print "\nDATA\n----" }
{ printf fmt, "Original data size", $1/1024/1024, "MiB"
printf fmt, "Compressed data size", $2/1024/1024, "MiB"
printf fmt, "Compress ratio", $1/$2, ""
print "\nMEMORY\n------"
printf fmt, "Memory used, total", $3/1024/1024, "MiB"
printf fmt, "Allocator overhead", ($3-$2)/1024/1024, "MiB"
printf fmt, "Allocator efficiency", $2/$3*100, "%"
printf fmt, "Maximum memory ever used", $5/1024/1024, "MiB"
printf fmt, "Memory limit", $4/1024/1024, "MiB"
print "\nPAGES\n-----"
printf fmt2, "Same pages count", $6
printf fmt2, "Pages compacted", $7 }' <$zdev/mm_stat
awk '{ printf "%-25s - %d\n", "Free pages discarded", $4 }' <$zdev/io_stat
}
zram_stats zram0Code: Select all
Gathering stats info for zram device "zram0"
Z-RAM
-----
Block device - /sys/block/zram0
Device size - 4096 MiB
Compression algo - lzo lzo-rle [lz4] lz4hc zstd
DATA
----
Original data size - 624.99 MiB
Compressed data size - 190.28 MiB
Compress ratio - 3.28
MEMORY
------
Memory used, total - 199.23 MiB
Allocator overhead - 8.96 MiB
Allocator efficiency - 95.50 %
Maximum memory ever used - 200.06 MiB
Memory limit - 200.00 MiB
PAGES
-----
Same pages count - 36465
Pages compacted - 5
Free pages discarded - 5154109