如何为 Debian Wheezy (3.2 内核) 设置和配置 compcache。据我所知,compcache 现在位于内核中,在 debian repo 中也找不到。据我所知,Compcache 应该可以通过 /sys 或 /proc 接口访问,但我不知道它在 Debian 中的位置/名称。
答案1
经过一番搜索,我找到了一个脚本,它很好地解释了如何打开 zram 来替换 compcache。编辑:我还对脚本做了一些修改 - 这是更新后的版本。
编辑:2016. 下面我还为 zram 添加了 systemd 服务示例(与 compcache 相同)
#! /bin/sh
### BEGIN INIT INFO
# Provides: zramstuff
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2
# Default-Stop: 0 6
# Short-Description: Enable swap to compressed ram
# Description: Enables swapping to compressed ram
### END INIT INFO
case "$1" in
start)
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# if something goes wrong, assume we have 1
[ "$num_cpus" != 0 ] || num_cpus=1
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
mem_total=$((mem_total_kb * 1024))
# load dependency modules
modprobe zram zram_num_devices=$num_cpus
# initialize the devices
for i in $(seq 0 $decr_num_cpus); do
echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
done
# Creating swap filesystems
for i in $(seq 0 $decr_num_cpus); do
mkswap /dev/zram$i
done
# Switch the swaps on
for i in $(seq 0 $decr_num_cpus); do
swapon -p 100 /dev/zram$i
done
;;
stop)
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# Switching off swap
for i in $(seq 0 $decr_num_cpus); do
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
swapoff /dev/zram$i
fi
done
rmmod zram
;;
esac
Systemd 服务示例:(在 Debian 上测试)
[Unit]
Description=Set up zram
Conflicts=hibernate.service
[Service]
Environment=ZRAM_MEM=1G
Environment=ZRAM_CMPALGO=lz4
Environment=ZRAM_CMPSTREAMS=2
Type=oneshot
User=root
ExecStartPre=/bin/sh -c "/sbin/modprobe zram num_devices=1"
ExecStartPre=/bin/sh -c "echo $ZRAM_CMPALGO >/sys/block/zram0/comp_algorithm"
ExecStartPre=/bin/sh -c "echo $ZRAM_CMPSTREAMS >/sys/block/zram0/max_comp_streams"
ExecStartPre=/bin/sh -c "echo $ZRAM_MEM > /sys/block/zram0/disksize"
ExecStartPre=/bin/sh -c "/sbin/mkswap /dev/zram0"
ExecStart=/sbin/swapon /dev/zram0 -p 10
ExecStop=/sbin/swapoff /dev/zram0
ExecStop=/bin/echo 1 > /sys/block/zram0/reset
ExecStop=/sbin/rmmod zram
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
答案2
我相信compcache
将显示为名为 SWAP 类型的设备/dev/ramzswap0
。您应该能够使用 看到它被列出blkid
。