microsd card optimisation daemon

This commit is contained in:
Bob Mottram 2018-04-21 14:05:44 +01:00
parent 572076dffa
commit 968319ded3
1 changed files with 40 additions and 10 deletions

View File

@ -794,16 +794,46 @@ function install_shellcheck {
apt-get -yq install shellcheck apt-get -yq install shellcheck
} }
function set_read_ahead { function microsd_card_optimisations {
# Setting this can significantly improve microSD read performance # These values can improve performance on microSD cards
read_ahead="$1" if [ ! -d /etc/network/if-up.d ]; then
if [ ! "$read_ahead" ]; then mkdir /etc/network/if-up.d
read_ahead=4096
fi fi
if [ ! -f /sys/devices/virtual/bdi/179:0/read_ahead_kb ]; then printf '#!/bin/bash\n' > /usr/bin/enable_optimisations
return
if [ -f /sys/devices/virtual/bdi/179:0/read_ahead_kb ]; then
echo -n '4096' > /sys/devices/virtual/bdi/179:0/read_ahead_kb
echo "echo -n '4096' > /sys/devices/virtual/bdi/179:0/read_ahead_kb" >> /usr/bin/enable_optimisations
fi fi
echo -n "$read_ahead" > /sys/devices/virtual/bdi/179:0/read_ahead_kb
if [ -f /proc/sys/vm/dirty_expire_centisecs ]; then
echo -n '100' > /proc/sys/vm/dirty_expire_centisecs
echo "echo -n '100' > /proc/sys/vm/dirty_expire_centisecs" >> /usr/bin/enable_optimisations
fi
if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
echo -n '100' > /proc/sys/vm/dirty_writeback_centisecs
echo "echo -n '100' > /proc/sys/vm/dirty_writeback_centisecs" >> /usr/bin/enable_optimisations
fi
chmod +x /usr/bin/enable_optimisations
{ echo '[Unit]';
echo "Description=${PROJECT_NAME} optimisations";
echo 'After=syslog.target';
echo 'After=network.target';
echo 'After=remote-fs.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=root';
echo 'Group=root';
echo 'WorkingDirectory=/root';
echo 'ExecStart=/usr/bin/enable_optimisations';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/optimisations.service
systemctl enable optimisations
} }
function setup_utils { function setup_utils {
@ -828,8 +858,8 @@ function setup_utils {
function_check separate_tmp_filesystem function_check separate_tmp_filesystem
separate_tmp_filesystem 150 separate_tmp_filesystem 150
function_check set_read_ahead function_check microsd_card_optimisations
set_read_ahead 4096 microsd_card_optimisations
function_check proc_filesystem_settings function_check proc_filesystem_settings
proc_filesystem_settings proc_filesystem_settings