Optimizing Debian, Ubuntu, Linux Mint, and Other Debian Based Distros

This guide should work for all Debian and Ubuntu based Linux distros using the EXT4 filesystem. However, I am using this currently on Ubuntu Mate 17.04.

First of all, I suggest replacing the default kernel with a much more performance optimized one. Two of the best kernel alternatives are Liquorix and XanMod. However, for this tutorial we will be using my favorite kernel, XanMod. I suggest using the latest XanMod kernel available, which is version 4.13 at the time of writing this article.

Installing XanMod 4.13 Kernel
Please execute the following command in terminal to add the XanMod repository.
echo 'deb http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list && wget -qO - http://deb.xanmod.org/gpg.key | sudo apt-key add -
This next command will update your system’s package lists and then install XanMod.
sudo apt update && sudo apt install linux-xanmod-4.13

Install the latest microcodes for your processor:
For Intel Processors:
sudo apt install intel-microcode iucode-tool
For AMD Processors:
sudo apt install amd64-microcode

Modify and optimize your mount options.
sudo pluma /etc/fstab
Replace pluma with whatever text editor you wish to use. It should look something like this.

You need to replace: errors=remount-ro
With: noatime,data=writeback

Do not add anything else other than exactly what I have added. No extra punctuation or spaces.

The importance of the noatime setting is that it eliminates the need by the system to make writes to the file system for files which are simply being read. Since writes can be somewhat expensive, this can result in measurable performance gains. The ‘data=writeback’ mode does not preserve data ordering when writing to the disk, so commits to the journal may happen before the data is written to the file system. This method is faster because only the meta data is journaled.

Modify a line in grub settings to enable Multi-Queue Block IO Queueing Mechanisms.
sudo pluma /etc/default/grub
Replace pluma with whatever text editor you wish to use.

We want to change the line regarding GRUB_CMDLINE_LINUX_DEFAULT to read the following:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash scsi_mod.use_blk_mq=y dm_mod.use_blk_mq=y"
This allows us to enable blk-mq (Multi-Queue Block IO Queueing Mechanism).

Specify what Linux Multi-Queue Block IO Queueing Mechanism / IO Scheduler to use.
sudo pluma /etc/udev/rules.d/60-scheduler.rules
Replace pluma with whatever text editor you wish to use.
Add the following line to this file, replacing kyber with whatever scheduler/mechanism you want to use:
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="kyber"

I suggest the following, however I do highly recommend you test these yourself and choose whatever you feel you get the best results with. Here are some benchmarks to help you decide.
For Desktop PC use BFQ or Kyber IO Scheduler.
For Server/Seedbox with Sata3 SSD/HDD use tuned CFQ IO Scheduler that comes with XanMod kernel.
For Desktop or Server with NVMe SSD use none as IO Scheduler setting.
Please Note: Only use lowercase when referencing cfq, bfq, kyber, none, etc in 60-scheduler.rules file.

Optimal settings for sysctl.conf file.
sudo pluma /etc/sysctl.conf
Replace pluma with whatever text editor you wish to use.
Scroll to the bottom of this file and add the following:
vm.swappiness = 1
fs.file-max = 2000000
kernel.pid_max = 4194303
kernel.sched_migration_cost_ns = 5000000
kernel.sched_autogroup_enabled = 0
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_abort_on_overflow = 0
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_tw_reuse = 1
vm.dirty_background_ratio = 20
vm.dirty_ratio = 30
net.ipv4.tcp_rfc1337 = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_workaround_signed_windows = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_orphan_retries = 2
net.ipv4.tcp_retries2 = 8
net.ipv4.ip_local_port_range = 1024 65535
net.core.netdev_max_backlog = 3240000
net.core.somaxconn = 50000
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_max_syn_backlog = 3240000
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.ip_no_pmtu_disc = 0
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.optmem_max = 16777216
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_adv_win_scale = 2
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

Increase limit of max open soft/hard files.
sudo pluma /etc/security/limits.conf
Replace pluma with whatever text editor you wish to use.
Add the following line to this file:
* - nofile 2000000

Tune the hard drive and journaling system.

You will need to enter the command df -h to get a filesystem/partition listing like the one pictured above. Obviously you will need to change sda1 in the command below to whatever filesystem your computer says / is mounted on.

You will probably have to run the command below as root or su. If you are not under root account just type su and press enter. It should prompt you for root or admin password. Enter password and then you will gain root privileges. Now you can enter command below.

umount /dev/sda1 && tune2fs -o journal_data_writeback /dev/sda1 && tune2fs -O ^has_journal /dev/sda1 && e2fsck -f /dev/sda1

Optional script to change the CPU Governor.
echo "gov - show or set governor (set requires root privileges)"
echo "usage: [sudo] gov
echo "governor in use:"
getgov=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)
case $1 in
o|ondemand) governor=ondemand;;
f|performance) governor=performance;;
p|powersave) governor=powersave;;
c|conservative) governor=conservative;;
*) echo $getgov
for g in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo $governor > $g; done
echo $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)

Save as gov.sh then make executable and then execute the script like this:
sudo bash gov.sh performance
You will have to run this command each reboot unless you have it execute automatically at startup. [1][2][3]

echo 1 | tee /sys/block/sd*/queue/iosched/fifo_batch > /dev/null
echo 100000 | tee /sys/block/sd*/queue/nr_requests > /dev/null
echo 4096 | tee /sys/block/sd*/queue/read_ahead_kb > /dev/null

These 3 commands are also not persistent though reboot.

Do you have a Nvidia GPU and are using proprietary Nvidia drivers?
Please Note: I doubt this will work with Nvidia Laptops running Bumblebee drivers.

Add these commands under startup applications:
nvidia-settings -a GPUFanControlState=1
nvidia-settings -a GPUTargetFanSpeed=65
nvidia-settings -a GpuPowerMizerMode=1

I prefer my GPU fan to run at 65%. Obviously you can change this number to whatever percent you prefer. 100% is super cool temperatures but super loud. Play with this number to get a perfect balance between low temperatures and tolerable fan noise.

Next we need to generate a xorg.conf file. You should be able to do so using the following command:
sudo nvidia-xconfig
This should generate a config file either /etc/X11/xorg.conf or /etc/X11/xorg.conf.d/20-nvidia.conf

Use the following command to open the newly generated file and edit it:
sudo pluma /etc/X11/xorg.conf
Please Note: The spacing is not displaying properly on this WordPress Blog, but you should still be able to get the general idea.

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "Graphics Device"
Option "Coolbits" "28"
Option "TripleBuffer" "True"

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "Stereo" "0"
Option "nvidiaXineramaInfoOrder" "DFP-5"
Option "metamodes" "nvidia-auto-select +0+0 {ForceCompositionPipeline=On}"
Option "SLI" "Off"
Option "MultiGPU" "Off"
Option "BaseMosaic" "off"
SubSection "Display"
Depth 24

The main changes I want to highlight in the above script are these 3 commands below:
Option "Coolbits" "28"
Option "TripleBuffer" "True"
Option "metamodes" "nvidia-auto-select +0+0 {ForceCompositionPipeline=On}"

Conclusion and Reboot
Please reboot your machine now.
You can double check that some of the new settings have been successfully changed by running the following two commands:
cat /proc/sys/net/ipv4/tcp_available_congestion_control
This should output a number of different TCP Congestion Control methods, however bbr should be listed first if done correctly.
What is bbr?
cat /sys/block/sd*/queue/scheduler
This should output all the available IO Schedulers / IO Queueing Mechanisms. The one that the system is currently using will be surrounded by [brackets].

The last two are optional and bonus tweaks if you are using this tweaked Linux install to download and seed torrents. The first set of tweaks posted below is for rTorrent/ruTorrent and the second is for Deluge.

Bonus #1 – Optimal settings for .rtorrent.rc file.
It is usually located here, although yours may be different: ~/.rtorrent.rc
sudo pluma ~/.rtorrent.rc

min_peers = 1
max_peers = 512
min_peers_seed = -1
max_peers_seed = -1
max_uploads = 512
download_rate = 0
upload_rate = 0
network.max_open_files.set = 1024
network.http.max_open.set = 512
pieces.memory.max.set = 28000M
network.xmlrpc.size_limit.set = 4M
network.max_open_sockets.set = 1024
throttle.global_up.max_rate.set_kb = 0
throttle.global_down.max_rate.set_kb = 0
system.file_allocate.set = yes
pieces.preload.type.set = 1
pieces.preload.min_size.set = 262144
pieces.preload.min_rate.set = 5120
network.send_buffer.size.set = 16M
network.receive_buffer.size.set = 16M

On this “pieces.memory.max.set = 28000M” I typically set this to 80-90% of my available ram.
In this case the machine I was using had 32GB of ram.

Bonus #2 – Optimal settings for Deluge ltConfig.
Please install the latest version of ltConfig for Deluge.
"allow_multiple_connections_per_ip": true,
"cache_expiry": 120
"cache_size": 512000,
"choking_algorithm": 1,
"enable_incoming_utp": false,
"enable_outgoing_utp": false,
"low_prio_disk": false,
"max_queued_disk_bytes": 262144000,
"max_queued_disk_bytes_low_watermark": 131072000,
"seed_choking_algorithm": 1,
"send_buffer_low_watermark": 13107200,
"send_buffer_watermark": 26214400,
"send_buffer_watermark_factor": 250,
"strict_end_game_mode": false,
"use_parole_mode": false,

Please Note: I have taken some of these settings and suggestions from this Reddit thread.

9 Replies to “Optimizing Debian, Ubuntu, Linux Mint, and Other Debian Based Distros”

  1. NA says:

    tcp_adv_win_scale =1 on newer kernel. I think its better.

  2. Carlos says:

    After editing the grub config you are missing the grub-update part.

    Also, some explanation of the numbers would be great. Where do they come from?

  3. diona says:

    thanks that u are back to posting after a long time genius

  4. Mateus Batalha says:


    When I run the command (as root):

    “umount /dev/sda2 && tune2fs -o journal_data_writeback /dev/sda2 && tune2fs -O ^has_journal /dev/sda2 && e2fsck -f /dev/sda2”

    I got “umount: /: target is busy”.

    Do you can please help me?

    1. admin says:

      I will try an install from scratch here in a few days and I will try to get the same error as you. I will let you know if I figure out your error.

      1. Pedro says:

        Same here.

        I tried to boot in rescue mode like someone suggested on reddit but with no luck.

    2. Carlos says:

      Yes, umount the root directory is tricky 🙂 It’s doable (check a pivot_root tutorial if you really want to do it) but it’s probably just much simpler to boot from network or a live USB. Only reason to really hot-do it is we none of those are available.

    3. Aaron says:

      I’m also getting this response. Did you find any solution?

    4. ciss says:

      if you installed QB before running the command, screens with rtorrent and irssi are running at boot so you need to kill them.
      quick command by replacing your mapped /dev/sdx:

      kill `lsof /dev/sda3 | awk ‘{print $2}’`

Leave a Reply

Your email address will not be published. Required fields are marked *

scroll to top