/proc, /sys and tuning with sysctl
The kernel's /proc and /sys as a live interface, how sysctl reads and writes /proc/sys, how sysctl.d makes changes stick, and a few knobs worth knowing.
/proc, /sys and tuning with sysctl
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- /proc and /sys are not on disk. Every read asks the kernel for a value at that moment, and some files accept writes that change kernel behaviour immediately.
- /proc holds per-process directories and older system-wide files; its /proc/sys subtree is the tunable kernel parameters. /sys is the structured device and driver model, one value per file.
- sysctl is a front end to /proc/sys: the key net.ipv4.ip_forward is the file /proc/sys/net/ipv4/ip_forward. sysctl -w changes it now and the change is lost at reboot.
- Persistent settings go in /etc/sysctl.d/*.conf. At boot systemd-sysctl applies all files from /usr/lib, /run and /etc in filename order; the lexically last setting wins and /etc overrides a same-named vendor file.
- Change a knob for a stated reason, record it in a file with a comment, and check the kernel documentation for its meaning and default first.
Asking the kernel questions
How much memory is free? Which modules are loaded? What is this process’s parent? Is IP forwarding on? A kernel could offer a separate system call for each question, and a separate tool to call it. Linux mostly does something simpler: it exposes the answers as files.
Two pseudo-filesystems do this. Nothing in them is stored on a disk. When you read a file, the kernel generates its contents on the spot; when you write one, the kernel parses what you wrote and acts on it. cat, grep and shell redirection become a control panel for the running kernel.
/proc
The proc(5) man page calls procfs “a pseudo-filesystem which provides an interface to kernel data structures”, where “most of the files … are read-only, but some files are writable, allowing kernel variables to be changed”.
It holds two kinds of thing. There is a numbered directory per process, /proc/<pid>/, with its command line, open files, memory map and status. That is the subject of the later lesson on processes through /proc. And there are system-wide files from before /sys existed, such as /proc/meminfo, /proc/cpuinfo, /proc/modules (what lsmod prints) and /proc/cmdline from the command line lesson.
The part this lesson cares about is /proc/sys: the tunable kernel parameters. The kernel’s own sysctl documentation sums it up: “the /proc/sys/ directory is there so that you don’t even need special tools” to configure the kernel at run time.
/sys
/sys is newer and stricter. sysfs(5) says it provides “a view of the kobject structures defined internally within the kernel”: the device model. Devices appear under /sys/devices in their physical hierarchy, with symlinks from /sys/block, /sys/class/net and /sys/bus for other ways of looking at them. The convention is one value per file. Module parameters show up in /sys/module/<name>/parameters/, and udev, from the previous lesson, matches its rules against these attributes.
A rule of thumb: /proc/sys is for kernel-wide policy knobs, /sys is for properties of a particular device or driver.
sysctl
sysctl is a front end to /proc/sys. Its man page says the parameters available “are those listed under /proc/sys/”, and the key is the path with dots: vm.swappiness is /proc/sys/vm/swappiness, and slashes are accepted too. Written from the man pages; I did not run these:
sysctl vm.swappiness # read one key
sysctl -a | grep ip_forward # find keys
sudo sysctl -w net.ipv4.ip_forward=1 # change it now
cat /proc/sys/net/ipv4/ip_forward # the same value, as a file
A change made this way is live immediately and gone at the next boot.
Making it stick: sysctl.d
Persistent settings are .conf files of key = value lines. sysctl.d(5) says that “at boot, systemd-sysctl.service(8) reads configuration files” from /etc/sysctl.d/, /run/sysctl.d/, /usr/local/lib/sysctl.d/ and /usr/lib/sysctl.d/. All files are sorted together by name; “if multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence”, and a file in /etc replaces a vendor file of the same name. Apply them without rebooting with sudo sysctl --system.
Distributions ship their own defaults this way. I read the files in the official Ubuntu 24.04 and Alpine 3.24 container images, downloaded and unpacked on a Mac. Ubuntu has nine files in /etc/sysctl.d/ plus one in /usr/lib/sysctl.d/. Some lines from them:
# ubuntu: /etc/sysctl.d/10-map-count.conf
vm.max_map_count=1048576
# ubuntu: /etc/sysctl.d/10-bufferbloat.conf
-net.core.default_qdisc = fq_codel
# ubuntu: /usr/lib/sysctl.d/99-protect-links.conf
fs.protected_regular = 2
# alpine: /usr/lib/sysctl.d/00-alpine.conf
net.ipv4.tcp_syncookies = 1
kernel.panic = 120
The leading - on Ubuntu’s qdisc line is documented in sysctl.d(5): it means do not fail if the key cannot be set.
One trap the man page spells out: keys that belong to a module only exist once the module is loaded, and systemd-sysctl “will not configure such parameters if they become available after it has run”. Its example is br_netfilter, which container hosts need. The fix it recommends is a udev rule that applies the setting when the module appears.
A few knobs and why
Read the kernel’s documentation for any key before changing it. These four show the range:
net.ipv4.ip_forward: route packets between interfaces. Off on a normal host, on for routers, VPN gateways and container hosts. The networking docs warn this one is special: changing it “resets all configuration parameters to their default state”.vm.swappiness: the docs define it as “the rough relative IO cost of swapping and filesystem paging, as a value between 0 and 200”, default 60. The memory lesson explains when to move it.vm.max_map_count: the “maximum number of memory map areas a process may have”, default 65530. Search engines and some games need far more, which is why Ubuntu’s file above raises it to 1048576 and links the bug report that motivated it.fs.protected_regular: a security setting. At 2 it refusesO_CREATopens of files you do not own in world-writable or group-writable sticky directories like/tmp, closing a class of race attacks. Ubuntu ships 2.
Treat sysctl changes like code: one file per purpose, a comment saying why, and the source of the advice. “Kernel tuning” copied from a blog without a reason is a common source of strange production problems.
About the video
The embed is DJ Ware’s “Linux Internals: SysFS, Proc and Udev”, August 2022, clipped to its SysFS and Proc chapters (about 7 minutes). He explains what the two pseudo-filesystems expose and walks through them on a live system. I judged it from the chapters and description, and English from the original English audio track. The clip does not cover sysctl or sysctl.d; Low Orbit Flux’s ten-minute sysctl video in deeper does. The udev chapter of the same video is linked from the udev lesson.
What was run: reading the sysctl files in the downloaded Ubuntu and Alpine images on a Mac. Everything else is from proc(5), sysfs(5), sysctl(8), sysctl.d(5) and the kernel’s sysctl, vm, fs and ip-sysctl documentation, checked 2026-11-28.
Check yourself
You enable IP forwarding with sysctl -w net.ipv4.ip_forward=1 and it works until the next reboot. How do you make it permanent?
Put net.ipv4.ip_forward = 1 in a file such as /etc/sysctl.d/90-forwarding.conf, then apply it with sysctl --system or reboot.
Which file does the sysctl key vm.swappiness correspond to?
/proc/sys/vm/swappiness. The dots in the key map to directories under /proc/sys.
A setting for net.bridge.bridge-nf-call-iptables in /etc/sysctl.d is ignored at boot. What is a likely reason?
The key only exists after the br_netfilter module loads. systemd-sysctl runs early, before the module is loaded, so the setting has nowhere to go. Load the module earlier or apply the setting from a udev rule.
Two files set the same key: 10-tuning.conf and 99-local.conf. Which value applies?
The one in 99-local.conf, because files are processed in lexicographic order of their names and the last setting of a key wins.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.