Project

General

Profile

bcache-zram.sh

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

 
1
#!/bin/bash
2

    
3
. /etc/buildhost.config
4

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

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

    
16
}
17

    
18
. /etc/init.d/boot.local
19

    
20

    
21
F=`cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages`
22
test "$F" = "$PAGES" || {
23
    echo "wanted $PAGES 2M hugepages and got $F"
24
    sleep 240
25
    echo s > /proc/sysrq-trigger
26
    echo u > /proc/sysrq-trigger
27
    echo b > /proc/sysrq-trigger
28
}
29

    
30

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

    
33
if [ -x /usr/sbin/make-bcache ] ; then
34
wipefs -f -a $OBS_WORKER_DISK
35
sleep 2
36
modprobe zram num_devices=1
37
modprobe bcache
38
echo 32G > /sys/block/zram0/disksize
39
wipefs -f -a /dev/zram0
40
sleep 2
41
fuser /dev/sdb
42
#make-bcache -C /dev/zram0
43
#make-bcache -B $OBS_WORKER_DISK
44
make-bcache --wipe-bcache --block 4k --bucket 2M -B $OBS_WORKER_DISK -C /dev/zram0
45
sleep 2
46
echo /dev/zram0 > /sys/fs/bcache/register
47
sleep 4
48
echo writeback > /sys/block/bcache0/bcache/cache_mode
49
echo 1500M > /sys/block/bcache0/bcache/sequential_cutoff
50
OBS_WORKER_DISK=/dev/bcache0
51
fi
52

    
53

    
54

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

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

    
71
mkinitrd -A