Enable NONE in the i/o scheduler

Greetings everyone,

I am seeking guidance regarding the configuration of a snippet to establish the I/O scheduler as “NONE.” on my SSD ( Samsung evo 870 )

[tolga@HP-G1-800:/home/tolga]$ cat /sys/block/sda/queue/scheduler

[none] mq-deadline kyber

I would appreciate insight into whether this is feasible on NixOS.

cheers
tolga

I do something like this on my Odroid board to control the leds.

  systemd.services.setleds = {
    script = ''
      echo "Setting Odroid LEDs"
      echo none > /sys/class/leds/blue\:heartbeat/trigger
      cat /sys/class/leds/blue\:heartbeat/trigger
    '';
    wantedBy = ["multi-user.target"];
  };```

I’d add a udev rule to set that.
For my zfs devices I am doing something like that

    udev.extraRules = lib.optionalString
      (builtins.elem "zfs" config.boot.supportedFilesystems) ''
        ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="zfs_member", ATTR{../queue/scheduler}="none"
      '';

Edit: be aware that the optinalString part is, that I set that just on those systems that are using zfs (I have a multi system flake and setting that in a module that is loaded by ever host)

2 Likes

Alright, between the two options provided, which one is recommended? I’ve successfully implemented the systemd version on my Fedora 39, and it functions as expected. However, I’m a bit unclear on how to replicate the process on NixOS.

[Unit]
Description=Set i/o scheduler
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/none.sh
User=tolga
Group=tolga
Restart=always

[Install]
WantedBy=default.target
#!/bin/bash
# tolga erok
# 10/12/2023

# Log file path
LOG_FILE="$HOME/none_script.log"

# Function to log a message
log_message() {
    echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}

# Function to display a desktop notification
show_notification() {
    DISPLAY=:0 notify-send "Script Notification" "$1"
}

sleep 5

# Password
PASSWORD="xxx"

# Apply scheduler
echo "$PASSWORD" | sudo -S sh -c 'echo none > /sys/block/sda/queue/scheduler' > /dev/null 2>&1

if [ $? -eq 0 ]; then
    show_notification "Scheduler applied successfully."
    log_message "Scheduler applied successfully."
else
    show_notification "Failed to apply scheduler."
    log_message "Failed to apply scheduler."
fi

# Display current scheduler
current_scheduler=$(cat /sys/block/sda/queue/scheduler)
show_notification "Current scheduler: $current_scheduler"
log_message "Current scheduler: $current_scheduler"

# Enable and display status of earlyoom
#log_message "Enabling and checking status of earlyoom..."
#echo "$PASSWORD" | sudo -S /usr/bin/systemctl enable --now earlyoom > >(tee -a "$LOG_FILE") 2> >(tee -a "$LOG_FILE" >&2)
#if [ $? -eq 0 ]; then
 #   show_notification "Earlyoom enabled successfully."
  #  log_message "Earlyoom enabled successfully."
#else
 #   show_notification "Failed to enable Earlyoom."
 #   log_message "Failed to enable Earlyoom."
#fi

# Display available kernel congestion control
log_message "Displaying available kernel congestion control..."
/usr/sbin/sysctl net.ipv4.tcp_available_congestion_control >> "$LOG_FILE"

# Display current congestion control
log_message "Displaying current congestion control..."
/usr/sbin/sysctl net.ipv4.tcp_congestion_control >> "$LOG_FILE"

# Wait for a moment
sleep 1
log_message "Script execution completed."
exit

Would i be correct to use the following to suit ext4

udev.extraRules = lib.optionalString
  (builtins.elem "ext4" config.boot.supportedFilesystems) ''
    ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="ext4", ATTR{../queue/scheduler}="none"
  '';

In case the config is used just be the one host or you want to use it anyways for every config you can ditch the lib.optionalString part and just set the udev rule content.
Be aware that it’s best to do a clean restart your system to verify if the scheduler was set correctly.

1 Like

Hi and thanks for the reply. Do you mean like this if i use it as a system wide config:

udev.extraRules = builtins.elem "ext4" config.boot.supportedFilesystems ''
  ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="ext4", ATTR{../queue/scheduler}="none"
'';

Please advise if this is correct: :
:point_down:

https://github.com/tolgaerok/nixos-kde/blob/3ba4be88810499229986319c24b8ef972efd1edc/core/services/udev/default.nix#L12

I meant just

udev.extraRules =  ''
  ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="ext4", ATTR{../queue/scheduler}="none"
'';

according your system config, you already have figured that out :slight_smile:

builtins.elem "ext4" config.boot.supportedFilesystems is the condition for the lib.optionalString

But what you have on the git repo looks correct for me.
Did that work?

1 Like

it works.

cheers

1 Like