LinuxMint/LinuxMint22_sysctl.conf.sh

132 lines
5.9 KiB
Bash

#!/bin/bash
#
echo -e '\033[33m----Optimise tcp ip----\033[33m'
echo -e "\033[0m"
sleep 2
sudo mv /etc/sysctl.conf /etc/sysctl.conf.default
sudo bash -c 'cat << EOF > /etc/sysctl.conf
#############################
## Battery life tweaks #
#############################
#vm.dirty_writeback_centisecs=3000
#vm.dirty_expire_centisecs=500
#
#############################
## CPU tweaks #
#############################
#
## Queue size modifications
net.core.optmem_max=20480
net.unix.max_dgram_qlen=50
#
## Net Core Settings
## Location: /proc/sys/net/core
net.core.wmem_max=524288
net.core.rmem_max=524288
net.core.rmem_default=256960
net.core.wmem_default=256960
#
#############################
## VM & Filesystem tweaks #
#############################
fs.lease-break-time=10
fs.file-max=65536
vm.overcommit_memory=1
vm.oom_dump_tasks=1
vm.page-cluster=0
vm.swappiness = 26
vm.vfs_cache_pressure = 10000
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
#
#############################
## Net Speed tweaks #
#############################
#
net.core.default_qdisc = cake
net.ipv4.tcp_congestion_control = bbr
#net.ipv4.tcp_congestion_control=cubic
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_keepalive_probes = 6
#
# # Hardening the TCP/IP stack to SYN attacks
net.ipv4.tcp_syncookies=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.tcp_synack_retries=2
net.ipv4.tcp_syn_retries=2
net.ipv4.tcp_max_syn_backlog=1024
net.ipv4.tcp_max_tw_buckets=16384
net.ipv4.icmp_echo_ignore_all=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.tcp_no_metrics_save=1
net.ipv4.tcp_fin_timeout=15
net.ipv4.tcp_keepalive_time=1800
net.ipv4.ip_forward=0
net.ipv4.tcp_moderate_rcvbuf=1
net.ipv4.route.flush=1
net.ipv4.udp_rmem_min=6144
net.ipv4.udp_wmem_min=6144
net.ipv4.tcp_rfc1337=1
net.ipv4.ip_no_pmtu_disc=0
net.ipv4.tcp_ecn=0
net.ipv4.tcp_sack=1
net.ipv4.tcp_fack=1
#
# Dont accept source routing
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
#
# Dont accept redirects
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
EOF'
sudo /sbin/sysctl -p
#---------------------------------------------------------------------
# Network and memory-related optimizationss for 32GB
#---------------------------------------------------------------------
kernel.sysrq = 1 # Enable SysRQ for rebooting the machine properly if it freezes. [Source](https://oglo.dev/tutorials/sysrq/index.html)
net.core.netdev_max_backlog = 30000 # Help prevent packet loss during high traffic periods.
net.core.rmem_default = 262144 # Default socket receive buffer size, improve network performance & applications that use sockets. Adjusted for 32GB RAM.
net.core.rmem_max = 67108864 # Maximum socket receive buffer size, determine the amount of data that can be buffered in memory for network operations. Adjusted for 32GB RAM.
net.core.wmem_default = 262144 # Default socket send buffer size, improve network performance & applications that use sockets. Adjusted for 32GB RAM.
net.core.wmem_max = 67108864 # Maximum socket send buffer size, determine the amount of data that can be buffered in memory for network operations. Adjusted for 32GB RAM.
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_keepalive_intvl = 10 # TCP keepalive interval between probes to detect if a connection is still alive.
net.ipv4.tcp_keepalive_probes = 5 # TCP keepalive probes to detect if a connection is still alive.
net.ipv4.tcp_keepalive_time = 60 # TCP keepalive interval in seconds to detect if a connection is still alive.
vm.dirty_background_bytes = 134217728 # 128 MB
vm.dirty_bytes = 402653184 # 384 MB
vm.min_free_kbytes = 65536 # Minimum free memory for safety (in KB), helping prevent memory exhaustion situations. Adjusted for 32GB RAM.
vm.swappiness = 5 # Adjust how aggressively the kernel swaps data from RAM to disk. Lower values prioritize keeping data in RAM. Adjusted for 32GB RAM.
vm.vfs_cache_pressure = 90 # Adjust vfs_cache_pressure (0-1000) to manage memory used for caching filesystem objects. Adjusted for 32GB RAM.
#---------------------------------------------------------------------
# Nobara Tweaks
#---------------------------------------------------------------------
fs.aio-max-nr = 1000000 # defines the maximum number of asynchronous I/O requests that can be in progress at a given time. 1048576
fs.inotify.max_user_watches = 65536 # sets the maximum number of file system watches, enhancing file system monitoring capabilities. Default: 8192 TWEAKED: 524288
kernel.panic = 5 # Reboot after 5 seconds on kernel panic Default: 0
kernel.pid_max = 131072 # allows a large number of processes and threads to be managed Default: 32768 TWEAKED: 4194304
#---------------------------------------------------------------------
# SSD tweaks: Adjust settings for an SSD to optimize performance.
#---------------------------------------------------------------------
vm.dirty_background_ratio = 40 # Set the ratio of dirty memory at which background writeback starts (5%). Adjusted for SSD.
vm.dirty_expire_centisecs = 3000 # Set the time at which dirty data is old enough to be eligible for writeout (6000 centiseconds). Adjusted for SSD.
vm.dirty_ratio = 80 # Set the ratio of dirty memory at which a process is forced to write out dirty data (10%). Adjusted for SSD.
vm.dirty_writeback_centisecs = 300 # Set the interval between two consecutive background writeback passes (500 centiseconds)