{"slug":"linux-sysctl-tuning","title":"linux-sysctl-tuning","summary":"Use when measured Linux performance evidence justifies persistent network, queue, writeback, swap, or congestion-control sysctl changes on Debian/Ubuntu or RHEL-family hosts. Profile first; use linux-server-hardening for security sysctls.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:53:04.612291Z","repo":{"url":"https://github.com/beginwithu/agent-skills","stars":11,"forks":2,"license":"MIT","updatedAt":"2026-12-02T16:37:11Z"},"bodyHtml":"<hr>\n<h2>name: linux-sysctl-tuning\ndescription: Use when measured Linux performance evidence justifies persistent network, queue, writeback, swap, or congestion-control sysctl changes on Debian/Ubuntu or RHEL-family hosts. Profile first; use linux-server-hardening for security sysctls.\nlicense: MIT\nmetadata:\nportable: true\ncompatible_with: [claude-code, codex]\nauthor: Peter Bamuhigire\nauthor_url: techguypeter.com\nauthor_contact: \"+256784464178\"</h2>\n<h1>Sysctl Performance Tuning</h1>\n<h2>Distro support</h2>\n<p>One-family-pair skill: the <code>sysctl</code> interface, the <code>/etc/sysctl.d/</code> drop-in\ndirectory, and <code>sysctl --system</code> are <strong>identical</strong> on Debian/Ubuntu and the\nRHEL family (Fedora, RHEL, CentOS Stream, Rocky, Alma, Oracle). The kernel\nexposes the same <code>net.*</code> and <code>vm.*</code> keys on both. Only the package that ships a\ngiven module differs.</p>\n<table>\n<thead>\n<tr>\n<th>Concept</th>\n<th>Debian/Ubuntu</th>\n<th>RHEL family</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Show one key</td>\n<td><code>sysctl net.core.somaxconn</code></td>\n<td><code>sysctl net.core.somaxconn</code></td>\n</tr>\n<tr>\n<td>Show all keys</td>\n<td><code>sysctl -a</code></td>\n<td><code>sysctl -a</code></td>\n</tr>\n<tr>\n<td>Set live (transient)</td>\n<td><code>sysctl -w vm.swappiness=10</code></td>\n<td><code>sysctl -w vm.swappiness=10</code></td>\n</tr>\n<tr>\n<td>Persist</td>\n<td><code>/etc/sysctl.d/60-perf.conf</code></td>\n<td><code>/etc/sysctl.d/60-perf.conf</code></td>\n</tr>\n<tr>\n<td>Reload all drop-ins</td>\n<td><code>sudo sysctl --system</code></td>\n<td><code>sudo sysctl --system</code></td>\n</tr>\n<tr>\n<td>BBR module</td>\n<td><code>tcp_bbr</code> (in-tree, modprobe)</td>\n<td><code>tcp_bbr</code> (in-tree, modprobe)</td>\n</tr>\n<tr>\n<td>Available cc list</td>\n<td><code>sysctl net.ipv4.tcp_available_congestion_control</code></td>\n<td>same</td>\n</tr>\n</tbody>\n</table>\n<p><code>[GROUNDING-GAP: BBR/swappiness/TCP-buffer perf tuning — thin/absent in the RHCSA grounding corpus; authored from kernel networking docs (Documentation/ networking, Documentation/admin-guide/sysctl) and tcp(7)/sysctl(8) man pages. Deepen with Systems Performance 2e (Brendan Gregg).]</code></p>\n\n<h2>Use When</h2>\n<ul>\n<li>Raising socket buffers / TCP window for high-throughput (10GbE+) transfers.</li>\n<li>Scaling a server to many concurrent connections (<code>somaxconn</code>, syn backlog).</li>\n<li>Enabling <strong>BBR</strong> congestion control with the <code>fq</code> qdisc.</li>\n<li>Tuning memory writeback / swap behaviour (<code>swappiness</code>, <code>dirty_ratio</code>).</li>\n</ul>\n<h2>Do Not Use When</h2>\n<ul>\n<li>The goal is SECURITY hardening (rp_filter, tcp_syncookies, kptr_restrict,\nredirects). That sysctl lives in <code>linux-server-hardening</code>\n(<code>references/sysctl-reference.md</code>) — cross-reference it, do not duplicate it.</li>\n<li>The bottleneck is per-service CPU/memory share; use <code>linux-service-priority</code>\n(cgroup limits) instead.</li>\n<li>You are diagnosing, not tuning; profile first with <code>linux-perf-profiling</code>.</li>\n</ul>\n<h2>Required Inputs</h2>\n<table>\n<thead>\n<tr>\n<th>Artefact</th>\n<th>Required?</th>\n<th>Source</th>\n<th>If absent</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Measured bottleneck, workload/SLO, baseline, and candidate key rationale</td>\n<td>yes</td>\n<td><code>linux-perf-profiling</code> evidence</td>\n<td>Stop; do not tune from a generic recipe.</td>\n</tr>\n<tr>\n<td>Kernel/version, current/effective values, config precedence, and feature availability</td>\n<td>yes</td>\n<td>Host inspection</td>\n<td>Produce read-only discovery only.</td>\n</tr>\n<tr>\n<td>Load test, window, rollback threshold, and authority</td>\n<td>mutation</td>\n<td>Change plan</td>\n<td>Do not apply persistent or live values.</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>The workload class (throughput-bound transfer, connection-heavy server, or\nbalanced general server).</li>\n<li>The NIC speed and expected concurrent-connection count.</li>\n<li>Whether a maintenance window applies (most keys are live, but verify).</li>\n</ul>\n<h2>Capability Contract</h2>\n<p>Reading sysctls and drop-ins is read-only. Live writes, drop-in edits, module loading, load generation, and rollback require explicit authority. Security sysctls route to <code>linux-server-hardening</code>.</p>\n<h2>Degraded Mode</h2>\n<p>Without representative load testing, return candidate keys and an experiment design only. If a key/algorithm is unavailable, do not force it. If rollback cannot be observed, do not apply the change.</p>\n<h2>Decision Rules</h2>\n<table>\n<thead>\n<tr>\n<th>Choice</th>\n<th>Action</th>\n<th>Failure or risk avoided</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Tune or retain</td>\n<td>Change only a key linked to measured saturation and a testable hypothesis.</td>\n<td>Cargo-cult tuning.</td>\n</tr>\n<tr>\n<td>Live or persistent</td>\n<td>Test the narrow live delta, then persist only a verified winner in one owned drop-in.</td>\n<td>Boot-time regression.</td>\n</tr>\n<tr>\n<td>BBR</td>\n<td>Select only when available and pair with supported pacing qdisc after workload comparison.</td>\n<td>Unsupported congestion setup.</td>\n</tr>\n<tr>\n<td>Keep or rollback</td>\n<td>Keep only if target metric improves without crossing guardrails; otherwise restore previous values.</td>\n<td>Hidden latency/memory regression.</td>\n</tr>\n</tbody>\n</table>\n<h2>Workflow</h2>\n<ol>\n<li><p><strong>Measure first</strong> — profile with <code>linux-perf-profiling</code> so you tune the real\nbottleneck, not a guess.</p>\n</li>\n<li><p>Show the current live value of each candidate key (<code>sysctl &lt;key&gt;</code>).</p>\n</li>\n<li><p>Write the delta to a drop-in in <code>/etc/sysctl.d/</code> (never edit\n<code>/etc/sysctl.conf</code> or vendor files in <code>/usr/lib/sysctl.d/</code>).</p>\n</li>\n<li><p>Apply with <code>sudo sysctl --system</code> and re-read the keys to confirm.</p>\n</li>\n<li><p>Load-test, then keep or roll back by deleting the one drop-in.</p>\n</li>\n<li><p>Stop when target improvement is absent or a guardrail regresses; recover by removing the owned drop-in, restoring recorded live values, and rerunning the baseline test.</p>\n</li>\n</ol>\n<h2>Quality Standards</h2>\n<ul>\n<li>One owned drop-in file, high number prefix (e.g. <code>60-</code>/<code>99-</code>) so it wins.</li>\n<li>Set only keys you can justify against a measured bottleneck.</li>\n<li>Confirm BBR is available before selecting it (<code>tcp_available_congestion_control</code>).</li>\n</ul>\n<h2>Anti-Patterns</h2>\n<ul>\n<li><p>Copying a tuning blob. Fix: link every key to measured saturation and a hypothesis.</p>\n</li>\n<li><p>Editing vendor/global config. Fix: use one owned drop-in with documented precedence.</p>\n</li>\n<li><p>Claiming improvement without comparable load. Fix: repeat baseline and candidate under identical workload.</p>\n</li>\n<li><p>Forcing unavailable BBR or qdisc support. Fix: inspect kernel features before selection.</p>\n</li>\n<li><p>Keeping a regressing change. Fix: enforce guardrails and restore prior effective values.</p>\n</li>\n<li><p>Copy-pasting a giant \"ultimate sysctl\" blob without measuring.</p>\n</li>\n<li><p>Editing <code>/etc/sysctl.conf</code> directly (use a drop-in — easy diff/rollback).</p>\n</li>\n<li><p>Setting <code>vm.swappiness=0</code> (can trigger OOM under pressure; 10 is the safe low).</p>\n</li>\n<li><p>Mixing security and performance keys in one file (split ownership).</p>\n</li>\n<li><p>Claiming improvement without a comparable load test. Correction: repeat baseline and candidate runs under the same workload.</p>\n</li>\n<li><p>Ignoring config precedence. Correction: inspect effective values and every supplying drop-in before choosing the filename.</p>\n</li>\n</ul>\n<h2>Outputs</h2>\n<table>\n<thead>\n<tr>\n<th>Artefact</th>\n<th>Consumer</th>\n<th>Acceptance condition</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Tuning hypothesis</td>\n<td>Performance owner</td>\n<td>Links each key to measured evidence, target metric, guardrail, and rollback threshold.</td>\n</tr>\n<tr>\n<td>Owned drop-in/change record</td>\n<td>Operator</td>\n<td>Contains only approved deltas plus before/after effective values and rollback.</td>\n</tr>\n<tr>\n<td>Experiment result</td>\n<td>Service owner</td>\n<td>Comparable test shows improvement and guardrails, or records successful rollback.</td>\n</tr>\n</tbody>\n</table>\n<h2>Evidence Produced</h2>\n<table>\n<thead>\n<tr>\n<th>Artefact</th>\n<th>Acceptance</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Tuning experiment evidence</td>\n<td>Contains kernel/config provenance, before/after values, comparable load metrics, guardrails, and rollback result.</td>\n</tr>\n</tbody>\n</table>\n<p>Capture kernel, feature availability, config provenance, before/after keys, load-test parameters and metrics, errors, guardrails, and rollback result.</p>\n<h2>Worked Example</h2>\n<p>After profiling shows a connection-accept queue bottleneck, record current <code>somaxconn</code>, application backlog, and saturation, test one bounded increase under the same load, then persist only if latency improves without memory or error regression.</p>\n<ul>\n<li>The drop-in file written and the keys it changed.</li>\n<li>Before/after values for each tuned key.</li>\n<li>The load-test result that justified (or reverted) the change.</li>\n</ul>\n<h2>sysctl basics</h2>\n<pre><code>sysctl net.core.somaxconn                 # read one key\nsysctl -a | grep tcp_congestion           # search\nsudo sysctl -w vm.swappiness=10           # transient (lost on reboot)\n\n# Persist: a drop-in is read at boot and by `sysctl --system`.\n# Files are read in lexical order across /usr/lib, /run, /etc — last wins.\nsudo tee /etc/sysctl.d/60-perf.conf &gt;/dev/null &lt;&lt;'EOF'\nnet.core.somaxconn = 65535\nvm.swappiness = 10\nEOF\nsudo sysctl --system                      # apply ALL drop-ins\n</code></pre>\n<h2>High-throughput networking</h2>\n<pre><code># Socket buffer ceilings (bytes) — needed for large bandwidth-delay products.\nnet.core.rmem_max = 134217728\nnet.core.wmem_max = 134217728\n# Per-socket TCP autotuning: min default max\nnet.ipv4.tcp_rmem = 4096 87380 67108864\nnet.ipv4.tcp_wmem = 4096 65536 67108864\n\n# BBR congestion control — pair it with the fq qdisc (BBR's pacing needs fq).\nnet.core.default_qdisc = fq\nnet.ipv4.tcp_congestion_control = bbr\n</code></pre>\n<pre><code># Verify BBR is usable BEFORE setting it:\nsysctl net.ipv4.tcp_available_congestion_control     # must list 'bbr'\nsudo modprobe tcp_bbr                                 # load if absent\n</code></pre>\n<h2>Connection scaling</h2>\n<pre><code>net.core.somaxconn = 65535          # accept-queue depth (also raise app backlog!)\nnet.ipv4.tcp_max_syn_backlog = 8192 # half-open (SYN_RECV) queue\nnet.core.netdev_max_backlog = 16384 # per-CPU packet ingress queue\nnet.ipv4.ip_local_port_range = 1024 65535   # ephemeral ports for outbound\nnet.ipv4.tcp_tw_reuse = 1           # reuse TIME_WAIT sockets for new outbound\n</code></pre>\n<blockquote>\n<p><code>somaxconn</code> only caps the kernel queue; the application's <code>listen()</code> backlog\nmust be raised too (e.g. nginx <code>backlog=</code>, the app's listen() argument).</p>\n</blockquote>\n<h2>Memory behaviour</h2>\n<pre><code>vm.swappiness = 10            # 0..200; lower = avoid swap, keep page cache (NOT 0)\nvm.dirty_ratio = 20          # % RAM dirty before a writing process blocks\nvm.dirty_background_ratio = 5 # % RAM dirty before kernel starts async flush\nvm.overcommit_memory = 0     # 0=heuristic, 1=always, 2=strict (with overcommit_ratio)\n</code></pre>\n<h2>Cross-reference: security sysctl</h2>\n<p>SECURITY-focused <code>net.*</code>/<code>kernel.*</code> tunables (<code>rp_filter</code>, <code>tcp_syncookies</code>,\n<code>kptr_restrict</code>, <code>accept_redirects</code>, core-dump hygiene) are owned by the\n<strong><code>linux-server-hardening</code></strong> skill — see its\n<code>references/sysctl-reference.md</code>. Keep security keys in that skill's drop-in\nand performance keys in this one; do not move or duplicate either set.</p>\n<h2>Optional fast path (when sk-* scripts are installed)</h2>\n<table>\n<thead>\n<tr>\n<th>Task</th>\n<th>Fast-path script</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Show live vs profile delta (read-only)</td>\n<td><code>sk-sysctl-tune --profile throughput</code></td>\n</tr>\n<tr>\n<td>Write a profile drop-in + <code>sysctl --system</code></td>\n<td><code>sudo sk-sysctl-tune --profile web --apply</code></td>\n</tr>\n<tr>\n<td>Preview an apply without writing</td>\n<td><code>sudo sk-sysctl-tune --profile web --apply --dry-run</code></td>\n</tr>\n</tbody>\n</table>\n<h2>Scripts</h2>\n<p>This skill installs the following scripts to <code>/usr/local/bin/</code>. To install:</p>\n<pre><code>sudo install-skills-bin linux-sysctl-tuning\n</code></pre>\n<table>\n<thead>\n<tr>\n<th>Script</th>\n<th>Source</th>\n<th>Core?</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>sk-sysctl-tune</td>\n<td>scripts/sk-sysctl-tune.sh</td>\n<td>no</td>\n<td>Show live vs target for a PERFORMANCE profile (throughput/web/balanced), read-only by default; with --apply writes a <code>/etc/sysctl.d/</code> drop-in and runs <code>sysctl --system</code> after confirmation. Dry-run-aware; verifies BBR availability. Both families.</td>\n</tr>\n</tbody>\n</table>\n\n<h2>References</h2>\n<ul>\n<li><a href=\"references/sysctl-tuning-reference.md\"><code>references/sysctl-tuning-reference.md</code></a></li>\n</ul>\n","files":[{"path":"LICENSE","sizeBytes":1073,"isText":false},{"path":"references/sysctl-tuning-reference.md","sizeBytes":11012,"isText":true},{"path":"SKILL.md","sizeBytes":10881,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:53:29.924809Z","sha256":"A8918012D9FB588C79805D87B4A9D2775F4DD6CDE3C6F7EF50657C1183BD7498","sizeBytes":10305},"review":null,"source":{"repositoryUrl":"https://github.com/beginwithu/agent-skills","path":"skills/linux-sysctl-tuning","license":"MIT","commit":"a960304c52212f2e845067047f5cefc0c594d787","subtreeSha":"A82014EA0A3CD76E0472EB479C2016DC1027DA8D49A5231584ABF389A10DF947","lastSyncedAt":"2026-12-02T16:52:59.20206Z"},"reviewedAt":"2026-12-02T16:54:15.60271Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/beginwithu/agent-skills/tree/main/skills/linux-sysctl-tuning"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install beginwithu-agent-skills@llmmart"},{"target":"git","command":"git clone https://github.com/beginwithu/agent-skills.git"}]}