Blog
Schedulers, syscalls, memória virtual, filesystems, containers internals, eBPF. O que Linux/macOS/Windows fazem por baixo do seu programa. Operating Systems: Three Easy Pieces (Remzi).
Remzi (OSTEP): SO tem 3 trabalhos. Virtualizar hardware (cada processo acha que tem o computador inteiro), gerenciar concorrência (threads, locks, deadlock), persistir dados (filesystem). Por que Windows/Linux/macOS resolvem diferente.
Você liga o computador. Power-On Self Test (POST), BIOS legado vs UEFI moderno, GPT vs MBR, bootloader (GRUB, systemd-boot, Windows Boot Manager), kernel init, initramfs, primeiro processo (init/systemd PID 1), getty + login.
Processo: instância isolada com memory space próprio. Thread: contexto leve dentro do processo, compartilha memória. fork() cria cópia (COW na prática), exec() substitui imagem. Por que Python tem GIL e Node não. Green threads (Go goroutines, Erlang processes).
Como o kernel decide qual thread roda na CPU. Linux: O(n) clássico → O(1) (kernel 2.6) → CFS (Completely Fair Scheduler, virtual runtime) → EEVDF (Earliest Eligible Virtual Deadline First, Linux 6.6 jun/2023). Realtime: SCHED_FIFO, SCHED_RR. Latency vs throughput.
Cada processo vê address space de 256TB (x86-64) — mentira do kernel. Page tables 4 níveis (PGD/PUD/PMD/PTE), TLB (Translation Lookaside Buffer) cache. Page fault, demand paging, swap, COW. Huge pages (2MB/1GB) pra DBs. Mmap como tudo.
Userland fala com kernel via syscalls (open, read, write, mmap). Custa ~1000 cycles (entrada no kernel mode, salvar registers, validar args). Context switch entre threads: ~2-5µs no Linux. io_uring (Linux 5.1) elimina syscalls por batch. Por que Redis single-thread vence multi-thread em throughput.
Como bits no disco viram /home/user/file.txt. Inodes, blocks, journaling. ext4 (Linux default), btrfs (snapshots, RAID, compression), ZFS (Sun, RAID-Z, dedup, COW), APFS (macOS, snapshots, encryption), NTFS (Windows). Por que Postgres performa diferente em cada um.
Pacote chega na NIC → DMA pro RAM → IRQ → sk_buff → IP stack → TCP/UDP → socket → app. Cada hop custa tempo. Netfilter (iptables/nftables), conntrack, NAT. Kernel bypass: DPDK, AF_XDP (zero-copy 10Gbps+). Por que Cloudflare escreveu o próprio TCP stack.
Container ≠ VM. NAMESPACES (pid, net, mnt, uts, ipc, user, cgroup) isolam visão do kernel. CGROUPS limitam recursos (CPU, memory, io). runc (OCI runtime) implementa spec. Docker é só CLI/UX em cima de runc. containerd, CRI-O, gVisor (Google sandbox).
eBPF roda código sandboxed dentro do kernel SEM patches. Revolucionou observabilidade (tracing, profiling, monitoring), networking (Cilium substitui iptables), security (Tetragon). Ferramentas: bpftrace (one-liners), BCC, bpftool. Por que Meta, Netflix, Cloudflare migraram.
Carregando…