今天要說的是zram,從名字就可以看出他就是zip ram的意思,在Amazon Linux 2023 中已經預裝了相關的組件,可以直接修改配置文件即可啟用這項功能。
我也是偶然發現他的,因為我發現在micro type 的instance 上才會有swap 而更大的instance type 沒有,而且在更換instance type 的時候他會自己更動。
在預設的配置文件中,只有memory 小於800M 的instance type 才會啟用一個和memory 大小相同的zram device,只需要將host-memory-limit 改為超過當前instance type memory size 的大小,重啟即可。
cat /usr/lib/systemd/zram-generator.conf
# This config file enables a /dev/zram0 device with the default settings:
# — size — same as available RAM or 8GB, whichever is less
# - host-memory-limit: Enable only on small instance types (less than 800MB)
# — compression — most likely lzo-rle
#
# To disable, uninstall zram-generator-defaults or create empty
# /etc/systemd/zram-generator.conf file.
# zram0 defaults to swap
[zram0]
# Up to 8GiB of zram, follows Fedora/CentOS defaults
zram-size = min(ram, 8192)
# Instances with more than 800MiB of RAM don't need this on AL2023
host-memory-limit=4096
# This is the kernel default, fastest but maybe we want zstd for
# small instances which compresses more ?
compression-algorithm=lzo-rle
看看加上沒有:
zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle 3.7G 11.7M 336.5K 708K 1 [SWAP]
<?php
//simple counter to test sessions. should increment on each page reload.
session_start();
$count = isset($_SESSION['count']) ? $_SESSION['count'] : 1;
echo $count;
$_SESSION['count'] = ++$count;