From 72d764ef8bfa414ffa9c3715467b7de4d44c3ac0 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Sat, 15 Jun 2024 12:55:51 +0200 Subject: [PATCH] sequentialio: add new Signed-off-by: AuxXxilium --- sequentialio/all/usr/bin/sequentialio.sh | 110 +++++++++++++++++++++++ sequentialio/install.sh | 41 +++++++++ sequentialio/manifest.yml | 19 ++++ 3 files changed, 170 insertions(+) create mode 100755 sequentialio/all/usr/bin/sequentialio.sh create mode 100755 sequentialio/install.sh create mode 100644 sequentialio/manifest.yml diff --git a/sequentialio/all/usr/bin/sequentialio.sh b/sequentialio/all/usr/bin/sequentialio.sh new file mode 100755 index 0000000..af5808b --- /dev/null +++ b/sequentialio/all/usr/bin/sequentialio.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2023 AuxXxilium and 007revad +# +# This is free software, licensed under the MIT License. +# See /LICENSE for more information. +# + +script="Sequential I/O SSD caches" +color=no + +# Check script is running as root +if [[ $( whoami ) != "root" ]]; then + echo -e "$script" + echo -e "ERROR This script must be run as sudo or root!" + exit 1 +fi + +# Save options used +args=("$@") + +if [[ -z "$1" ]]; then + kb="0" +elif [[ "$1" == "true" ]]; then + kb="0" +elif [[ "$1" == "false" ]]; then + kb="1024" +fi + +# Show options used +if [[ ${#args[@]} -gt "0" ]]; then + echo "Using options: ${args[*]}" +fi + + +# Get list of volumes with caches +cachelist=("$(sysctl dev | grep skip_seq_thresh_kb)") +IFS=$'\n' caches=($(sort <<<"${cachelist[*]}")); unset IFS + + +if [[ ${#caches[@]} -lt "1" ]]; then + echo "No caches found!" && exit 1 +fi + + +# Get caches' current setting +for c in "${caches[@]}"; do + volume="$(echo "$c" | cut -d"+" -f2 | cut -d"." -f1)" + kbs="$(echo "$c" | cut -d"=" -f2 | awk '{print $1}')" + volumes+=("${volume}|$kbs") + + sysctl_dev="$(echo "$c" | cut -d"." -f2 | awk '{print $1}')" + sysctl_devs+=("$sysctl_dev") +done + + +# Show cache volumes and current setting +if [[ ${#volumes[@]} -gt 0 ]]; then + IFS="|" read -r cachevol setting <<< "${volumes}" + cachevols=("$cachevol") +fi + + +for v in "${sysctl_devs[@]}"; do + for c in "${cachevols[@]}"; do + if [[ $v =~ "$c" ]]; then + cachevol="$c" + + # Get cache's key name + cacheval="$(sysctl dev | grep skip_seq_thresh_kb | grep "$cachevol")" + key="$(echo "$cacheval" | cut -d"=" -f1 | cut -d" " -f1)" + + # Set new cache kb value + val="$(synosetkeyvalue /etc/sysctl.conf "$key")" + if [[ $val != "$kb" ]]; then + synosetkeyvalue /etc/sysctl.conf "$key" "$kb" + fi + + if echo "$v" | grep "$cachevol" >/dev/null; then + echo "$kb" > "/proc/sys/dev/${v}/skip_seq_thresh_kb" + fi + + # Check we set key value + check="$(synogetkeyvalue /etc/sysctl.conf "$key")" + if [[ "$check" == "0" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Green}Enabled${Off} in /etc/sysctl.conf" + elif [[ "$check" == "1024" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Red}Disabled${Off} in /etc/sysctl.conf" + elif [[ -z "$check" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Red}not set${Off} in /etc/sysctl.conf" + else + echo -e "Sequential I/O for $cachevol cache is set to ${Cyan}$check${Off} in /etc/sysctl.conf" + fi + + # Check we set proc/sys/dev + val="$(cat /proc/sys/dev/"${v}"/skip_seq_thresh_kb)" + if [[ "$val" == "0" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Green}Enabled${Off} in /proc/sys/dev\n" + elif [[ "$val" == "1024" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Red}Disabled${Off} in /proc/sys/dev\n" + elif [[ -z "$val" ]]; then + echo -e "Sequential I/O for $cachevol cache is ${Red}not set${Off} in /proc/sys/dev\n" + else + echo -e "Sequential I/O for $cachevol cache is set to ${Cyan}$val${Off} in /proc/sys/dev\n" + fi + fi + done +done + +exit 0 \ No newline at end of file diff --git a/sequentialio/install.sh b/sequentialio/install.sh new file mode 100755 index 0000000..e5c6ad5 --- /dev/null +++ b/sequentialio/install.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env ash +# +# Copyright (C) 2023 AuxXxilium and Ing +# +# This is free software, licensed under the MIT License. +# See /LICENSE for more information. +# + +if [ "${1}" = "late" ]; then + echo "Installing addon sequentialio - ${1}" + mkdir -p "/tmpRoot/usr/arc/addons/" + cp -vf "${0}" "/tmpRoot/usr/arc/addons/" + + cp -vf /usr/bin/sequentialio.sh /tmpRoot/usr/bin/sequentialio.sh + + mkdir -p "/tmpRoot/usr/lib/systemd/system" + DEST="/tmpRoot/usr/lib/systemd/system/sequentialio.service" + echo "[Unit]" >${DEST} + echo "Description=Sequential I/O SSD caches" >>${DEST} + echo "After=multi-user.target" >>${DEST} + echo >>${DEST} + echo "[Service]" >>${DEST} + echo "Type=oneshot" >>${DEST} + echo "RemainAfterExit=yes" >>${DEST} + echo "ExecStart=/usr/bin/sequentialio.sh $@" >>${DEST} + echo >>${DEST} + echo "[Install]" >>${DEST} + echo "WantedBy=multi-user.target" >>${DEST} + + mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants + ln -vsf /usr/lib/systemd/system/sequentialio.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/sequentialio.service +elif [ "${1}" = "uninstall" ]; then + echo "Installing addon sequentialio - ${1}" + + rm -f "/tmpRoot/usr/lib/systemd/system/multi-user.target.wants/sequentialio.service" + rm -f "/tmpRoot/usr/lib/systemd/system/sequentialio.service" + + [ ! -f "/tmpRoot/usr/arc/revert.sh" ] && echo '#!/usr/bin/env bash' >/tmpRoot/usr/arc/revert.sh && chmod +x /tmpRoot/usr/arc/revert.sh + echo "/usr/bin/sequentialio.sh --restore" >> /tmpRoot/usr/arc/revert.sh + echo "rm -f /usr/bin/sequentialio.sh" >> /tmpRoot/usr/arc/revert.sh +fi \ No newline at end of file diff --git a/sequentialio/manifest.yml b/sequentialio/manifest.yml new file mode 100644 index 0000000..983a92d --- /dev/null +++ b/sequentialio/manifest.yml @@ -0,0 +1,19 @@ +version: 1 +name: sequentialio +description: "Enables sequential I/O for your SSD caches (Can cause overheating)" +system: false +beta: false +all: + install-script: "install.sh" + copy: "all" +apollolake: true +broadwell: true +broadwellnk: true +broadwellnkv2: true +broadwellntbap: true +denverton: true +geminilake: true +purley: true +v1000: true +r1000: true +epyc7002: true \ No newline at end of file