b5b37d1c22
New package submission. See boo#1116056 for more details. Please add me as maintainer. OBS-URL: https://build.opensuse.org/request/show/650228 OBS-URL: https://build.opensuse.org/package/show/filesystems/systemd-zram-service?expand=0&rev=1
35 lines
889 B
Bash
35 lines
889 B
Bash
#!/bin/bash
|
|
|
|
# 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
|
|
# Determine module parm
|
|
mod_parm=$(modinfo zram |grep parm |tr -s " " |cut -f2 -d ":")
|
|
modprobe zram $mod_parm=$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
|