LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File zramswapon of Package systemd-zram-service (Project home:so_it_team)

#!/bin/bash

# get the number of CPUs
get_cpus=$(grep -c processor /proc/cpuinfo)

if [[ "$get_cpus" -gt "28" ]]; then
	num_cpus=28
else
	num_cpus="$get_cpus"
fi

# 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