Project

General

Profile

action #30595 ยป bcache-zram.sh

Script used by Rudi to generate bcache backed ramdisk - szarate, 2018-04-10 14:05

 
#!/bin/bash

. /etc/buildhost.config

PAGES=$(($OBS_WORKER_INSTANCES * $OBS_INSTANCE_MEMORY / 2))

grep -q hugepages /etc/init.d/boot.local || {
cat << EOF >> /etc/init.d/boot.local
echo 3 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/compact_memory
echo 65536 > /proc/sys/vm/min_free_kbytes
echo $PAGES > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
echo "got \$(< /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages) huge pages"
EOF

}

. /etc/init.d/boot.local


F=`cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages`
test "$F" = "$PAGES" || {
echo "wanted $PAGES 2M hugepages and got $F"
sleep 240
echo s > /proc/sysrq-trigger
echo u > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger
}


test -z "$OBS_WORKER_DISK" && OBS_WORKER_DISK=/dev/sdb

if [ -x /usr/sbin/make-bcache ] ; then
wipefs -f -a $OBS_WORKER_DISK
sleep 2
modprobe zram num_devices=1
modprobe bcache
echo 32G > /sys/block/zram0/disksize
wipefs -f -a /dev/zram0
sleep 2
fuser /dev/sdb
#make-bcache -C /dev/zram0
#make-bcache -B $OBS_WORKER_DISK
make-bcache --wipe-bcache --block 4k --bucket 2M -B $OBS_WORKER_DISK -C /dev/zram0
sleep 2
echo /dev/zram0 > /sys/fs/bcache/register
sleep 4
echo writeback > /sys/block/bcache0/bcache/cache_mode
echo 1500M > /sys/block/bcache0/bcache/sequential_cutoff
OBS_WORKER_DISK=/dev/bcache0
fi



disk=$OBS_WORKER_DISK
test -e $disk || exit 1
mkdir -p /var/cache/obs/worker
grep -q $disk /etc/fstab || {
#mkfs.xfs -f -s size=4096 $disk
#mkfs.ext2 -F $disk
mke2fs -t ext4 -O ^has_journal -F $disk
#echo "$disk $OBS_WORKER_DIRECTORY xfs noatime,nodiratime,logbufs=8,logbsize=256k,barrier=0 1 2" >> /etc/fstab
#echo "$disk $OBS_WORKER_DIRECTORY ext2 noatime,nodiratime,async 1 2" >> /etc/fstab
echo "$disk $OBS_WORKER_DIRECTORY ext4 noatime,nodiratime,nobarrier,async 1 2" >> /etc/fstab
}
mount $OBS_WORKER_DIRECTORY

grep "OBS_WORKER_DIRECTORY" /etc/buildhost.config || echo "OBS_WORKER_DIRECTORY=$OBS_WORKER_DIRECTORY" >> /etc/buildhost.config
grep "OBS_CACHE_DIR" /etc/buildhost.config || echo "OBS_CACHE_DIR=$OBS_WORKER_DIRECTORY/cache" >> /etc/buildhost.config

mkinitrd -A
    (1-1/1)