Netflix Deploys FreeBSD Trunk in CDN Fleet to Catch Regressions Early

Why We Run FreeBSD current at Netflix – Drew Gallatin — OpenFest Bulgaria

OpenFest Bulgaria

Tracking bleeding-edge development code in production eliminates multi-year upgrade debt and enables rapid detection of upstream regressions that degrade server performance.

AI-assisted summary of Why We Run FreeBSD current at Netflix – Drew Gallatin — original source. Check the original for full context.

Source published:

Key ideas

  • Netflix tracks FreeBSD-CURRENT directly in production across its Open Connect CDN, merging upstream code every three to four weeks to catch regressions immediately and eliminate multi-month upgrade debacles. (8:10)
  • By co-designing hardware with FreeBSD kernel optimizations—including async sendfile, unmapped mbufs, and NIC TLS offload—Netflix scaled single-server CDN throughput from 100 Gbps in 2017 to 800 Gbps in 2022. (21:20)
  • An experimental sub-100-watt, 100 Gbps edge server prototype runs FreeBSD directly on an Nvidia BlueField DPU, bypassing traditional server motherboards and host CPUs entirely to stream video to tens of thousands of subscribers. (22:56)
  • A famous upstream boot-time sort optimization exposed a decade-old driver ordering flaw, where an inverted alphabetical tie-break caused an obsolete Pentium 4 thermal driver to attach over Intel SpeedStep and degrade CPU performance by 20%. (27:00)

Detailed notes

## Background Published by OpenFest Bulgaria on YouTube on February 18, 2024, this presentation features veteran FreeBSD committer and Netflix engineer Drew Gallatin discussing Netflix's Content Delivery Network (Open Connect). The talk details why Netflix tracks the development branch FreeBSD-CURRENT in production, outlines their major upstream contributions and bandwidth milestones, and dissects a specific upstream bug that triggered a 20% performance regression.

## TL;DR Drew Gallatin details how Netflix uses FreeBSD to power its global fleet of Open Connect Appliances, pushing bandwidth as high as 800 Gbps per server for static streaming workloads. The team transitioned from tracking FreeBSD-STABLE to running FreeBSD-CURRENT directly in production, enabling rapid upstream collaboration and preventing multi-month upgrade ordeals. Gallatin reviews core architectural enhancements engineered for FreeBSD—including asynchronous sendfile, unmapped mbufs, and Kernel TLS with NIC offload—before walking through the 'Magical Mystery Merge,' a case study where a widely praised boot-time sorting optimization inverted subsystem initialization and caused competing CPU frequency drivers to throttle production machines by 20%.

## Atmosphere & style The presentation carries the warm, unpretentious tone of an experienced systems engineer swapping war stories with peers. Gallatin speaks with understated humor and dry pragmatism, turning what could be dense kernel plumbing into an engaging technical mystery. It feels like an authentic insider's look into high-stakes production engineering, balancing pride in engineering milestones with candid reflections on the operational perils of bisection loops and buggy hardware firmware.

## Bulletin - [08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) Netflix tracks FreeBSD-CURRENT directly in production across its Open Connect CDN, merging upstream code every three to four weeks to catch regressions immediately and eliminate multi-month upgrade debacles. - [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) By co-designing hardware with FreeBSD kernel optimizations—including async sendfile, unmapped mbufs, and NIC TLS offload—Netflix scaled single-server CDN throughput from 100 Gbps in 2017 to 800 Gbps in 2022. - [22:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1376s) An experimental sub-100-watt, 100 Gbps edge server prototype runs FreeBSD directly on an Nvidia BlueField DPU, bypassing traditional server motherboards and host CPUs entirely to stream video to tens of thousands of subscribers. - [27:00](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1620s) A famous upstream boot-time sort optimization exposed a decade-old driver ordering flaw, where an inverted alphabetical tie-break caused an obsolete Pentium 4 thermal driver to attach over Intel SpeedStep and degrade CPU performance by 20%.

## Key takeaways - [00:18](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=18s) Netflix Open Connect Appliances function as single-purpose network appliances using dual A/B partition schemes for robust failover during operating system updates. - [03:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=200s) Netflix formats video storage partitions with UFS rather than ZFS because UFS integrates directly with the kernel page cache, avoiding the double-copy overhead of ZFS ARC. - [03:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=200s) Edge streaming workloads are strictly static and pre-encoded into dozens of display variants, eliminating runtime transcoding and focusing server resources entirely on network and disk I/O. - [08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) Tracking FreeBSD -STABLE releases led to massive merge friction, upstream divergence, and multi-month upgrade efforts, driving Netflix to track the development trunk (-CURRENT) directly. - [11:02](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=662s) Developing against -CURRENT allows Netflix engineers to submit bug fixes directly upstream for community review rather than maintaining internal forks, shrinking internal tree divergence. - [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) Asynchronous sendfile enables the web server to return immediately to its event loop while the storage controller's interrupt completion handler directly hands disk blocks to the network stack. - [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) Unmapped mbufs allow kernel buffers to hold references to multiple physical pages without updating page tables, substantially reducing socket-buffer pointer-chasing and CPU cache misses. - [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) Hardware-level NIC TLS offload executes payload encryption directly on the network adapter during transmission, reducing CPU crypto overhead to virtually zero. - [16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) Custom TCP stacks like RACK paired with high-precision TCP pacing prevent intermediate residential router buffer bloat, prioritizing subscriber streaming smoothness over raw benchmark speeds. - [16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) Physical memory pointer (PMP) hooks allow early firewall packet inspection and immediate buffer recycling, dropping tens of millions of DDoS packets per second without kernel allocation overhead. - [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) Single-server streaming capacity evolved from 100 Gbps via Kernel TLS in 2017 to 400 Gbps on single-socket AMD Rome with NIC offload in 2021, reaching 800 Gbps on dual-socket systems in 2022. - [27:00](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1620s) Replacing an $O(n^2)$ selection sort with an unstable quicksort during SYSINIT kernel initialization inadvertently reversed the boot-time registration order of tied subsystems. - [29:46](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1786s) Because CPU frequency drivers used binary return codes instead of graded probe scores, reverse-alphabetical sorting allowed an obsolete P4 thermal driver to attach first and improperly throttle Intel Xeon cores. - [33:19](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1999s) Running upstream trunk code allowed Netflix to identify the subtle frequency control bug immediately, report it directly to the patch author on IRC, and verify an upstream fix within 24 hours. - [36:30](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2190s) Operating tens of thousands of edge appliances requires staggered weekly rollouts and cautious validation of hardware firmware after past NIC firmware bugs caused unrecoverable I2C timeouts. - [38:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2320s) Netflix's continued reliance on FreeBSD is driven entirely by pragmatic engineering performance and stability requirements rather than ideological attachment.

## Detailed walkthrough ### [00:18](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=18s) Introduction and Overview of Netflix's CDN

Drew Gallatin, introduced at OpenFest Bulgaria, has worked at Netflix for about eight years specializing in FreeBSD kernel optimizations, and has been a FreeBSD committer for more than twenty-five years. He explains that his presentation will cover how Netflix uses FreeBSD, why the company tracks the `FreeBSD-CURRENT` development branch on its content delivery network (CDN), and an instructive case study titled the "Magical Mystery Merge," which illustrates the real-world advantages of running `-CURRENT`.

Netflix calls its CDN Open Connect, and the specialized edge servers deployed across the network are termed Open Connect Appliances (OCAs). Gallatin points out that in operational design, an OCA behaves much more like an appliance—such as a home router—than a traditional office or enterprise server. System software updates are delivered via a dual-partition scheme: the B-side is freshly imaged, and if a boot or update fails, the machine falls back automatically to the A-side partition. Every OCA runs identical base software with no one-off custom packages installed on individual boxes.

```mermaid flowchart LR accTitle: Open Connect Appliance Partition Update Flow accDescr: Diagram showing the A/B image update mechanism used on Netflix Open Connect Appliances. subgraph Update["OCA Storage Partitions"] A["Active Partition (A-Side)"] B["Target Partition (B-Side)"] end Image["New Image Deployment"] -->|"writes to"| B B -->|"boot failure fallback"| A ```

- OCAs can push immense bandwidth, with top-tier units capable of serving up to 400 Gbps. - Netflix deploys three distinct OCA server profiles: - **All-Flash OCAs:** Equipped with NVMe or older SATA SSDs; deployed at internet interchange points and data centers to serve the most popular content. - **Storage OCAs:** Pack hundreds of terabytes of disk capacity to store long-tail assets (from rarely viewed titles to full library catalogs). - **Global OCAs:** Placed directly inside smaller ISP networks to localize streaming traffic, offloading the ISP's upstream transit links when users stream movies.

---

[03:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=200s) Storage Architecture, Filesystems, and Static Workloads

Gallatin addresses one of the most common questions he receives: whether Netflix uses ZFS on its content appliances. The answer is yes, but strictly for the root filesystem. Netflix avoids using ZFS for video content partitions because of caching architecture: ZFS relies on its own Adaptive Replacement Cache (ARC), which sits separately from the operating system kernel's page cache. Serving content directly out of ZFS requires data to be copied from the ARC into the page cache, introducing memory copying overhead and degrading streaming throughput. Consequently, Netflix formats all content partitions with UFS (Unix File System), which integrates directly with the kernel's native page cache.

Netflix pairs UFS with the nginx web server and intentionally runs without software or hardware RAID on its content drives. Drives are simply allowed to fail in place. Gallatin highlights that managing replacement drives through third-party ISPs or dispatching field technicians to remote data centers is operationally expensive and unnecessary; because appliances house enormous aggregate storage, losing one or two drives leaves the machine entirely viable and capable of continuing service.

The appliance workload consists strictly of serving static pre-encoded files. Before any title reaches the CDN, Netflix encodes it into dozens of variants covering different display targets (smart TVs, mobile phones, computers) and varying bitrates. Because every variant is pre-computed to maximize video quality, the CDN edge servers execute zero runtime compute or transcoding, leaving the workload cleanly focused on raw network and disk I/O.

---

[05:26](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=326s) FreeBSD Lineage and the OCA Dev Team

Gallatin contextualizes FreeBSD's design by comparing it to Linux. While Linux was written from scratch, FreeBSD traces its lineage directly back to the original BSD releases that underpinned 1980s systems like SunOS. FreeBSD emerged from 386BSD, which had fallen into maintenance neglect. Two developer groups maintaining patch kits ultimately diverged: NetBSD formed with an emphasis on code correctness, portability, and multi-architecture support, while FreeBSD prioritized pure performance on x86 32-bit hardware. Gallatin notes that his own involvement as a FreeBSD committer began in the late 1990s while working on FreeBSD's first 64-bit port, the DEC Alpha, which was eventually sunsetted once the vendor discontinued the architecture.

Unlike standard Linux distributions where virtually all software is broken into modular binary packages, standard FreeBSD maintains a traditional separation: the kernel, core utilities (`ls`, `mv`, `cp`), standard shells, and base compilers live unpackaged in the base system root. Third-party utilities (like nginx and Firefox) are handled via packages. Netflix maintains a proprietary, stripped-down distribution that eliminates unneeded compilers, manuals, and packages from the OCAs.

The OCA Dev team responsible for this software stack is a focused group of roughly ten engineers, most of whom are longtime FreeBSD committers or contributors. Gallatin expresses great personal enthusiasm for the group, noting:

> “there's roughly 10 of us and it's a great place to work and it's the best job I've ever had”

---

[08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) The Pitfalls of Tracking Stable Branches

Historically, Netflix followed the conventional enterprise strategy: tracking a FreeBSD `-STABLE` branch. In FreeBSD terminology, `FreeBSD-CURRENT` is the active development trunk where all changes land first (analogous to the Linus tree in Linux), while `-STABLE` branches act as release and Long-Term Support (LTS) maintenance tracks. FreeBSD targets a major release every two years, though Gallatin observes it often stretches to every three or four years in practice.

Initially, the team tracked a `-STABLE` branch, merging security and bug fixes every few weeks and building internal OCA images. While this cadence functioned smoothly during the lifetime of a single release, upgrading from one major `-STABLE` branch to the next was punishing:

> “what was terrible was when we move from one stable Branch to another and that would take sometimes in the best case the weeks most most times it would take months you know up to six months because you could encounter a problem uh you know either in code that we never managed to Upstream uh being compatible with the new interfaces in the new in the new version or there could be uh some kind of regression introduced Upstream in the new version that was hard to track down and so these these merges every time we updated between stable branches were just awful”

Tracking `-STABLE` also crippled upstream open-source collaboration. Because internal code diverged from `-CURRENT`, contributing a fix or optimization required backporting it to `-CURRENT`, figuring out how to test it without running `-CURRENT` in production, and shepherding it through review—only to wait years to consume it in the next stable branch. This friction led Netflix to hoard internal changes, generating massive technical debt and horrific merge conflicts with every upgrade cycle. Around five to six years prior, the team decided to invert the model entirely and track `FreeBSD-CURRENT` directly in production. Gallatin acknowledges that this initially sounds reckless because FreeBSD operates without subsystem maintainers: any committer with a commit bit has direct commit access across the tree, guided by internal cultural expectations of review, freedom, and responsibility.

[11:02](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=662s) Tracking FreeBSD-CURRENT and Upstreaming Fast

Drew Gallatin explains that running FreeBSD-CURRENT inside Netflix's Open Connect content delivery network might sound reckless at first glance, but in practice, it is completely transformative. By sticking to a tight merge cadence of every three to four weeks, the team pulls in upstream FreeBSD code constantly. This prevents the traditional two-to-three-year lag where a bug or regression sits buried in a code base until an enterprise finally migrates to a newer release. Instead, regressions are caught immediately. Furthermore, developing directly against CURRENT removes the friction of having to backport features across widely divergent OS versions, allowing Netflix engineers to collaborate seamlessly with the wider open-source community.

Over the years, this dynamic has caused Netflix's internal delta against upstream to steadily shrink. Because their private tree is nearly identical to upstream FreeBSD, Netflix engineers rarely implement small features or minor bug fixes internally first. Instead, they write them directly in the upstream FreeBSD tree, put them through upstream code review, commit them, and simply let them flow back into Netflix on the next three-week merge cycle. This workflow drastically minimizes internal technical debt. Critical security patches or crash fixes are cherry-picked into Netflix's deployment immediately rather than waiting for the cycle. The rare exceptions are massive structural undertakings, like Kernel TLS (kTLS): Drew Gallatin notes that “that was a very large very invasive change and so we kept that to ourselves for close to 5 years,” not out of a desire for proprietary secrecy, but because it took that long to architect it cleanly so that it would be genuinely useful to the broader community rather than just solving Netflix's narrow internal use case.

```mermaid flowchart TD accTitle: Netflix FreeBSD Merge and Contribution Loop accDescr: Diagram showing how Netflix develops features upstream or pulls changes via a three-week merge cycle.

subgraph Upstream ["FreeBSD Upstream (CURRENT)"] UP_REPO["FreeBSD Tree"] UP_REV["Code Review & Commit"] end

subgraph Internal ["Netflix Open Connect Environment"] NF_DEV["Small Feature / Bugfix"] NF_TREE["Netflix Internal Branch"] NF_CHERRY["Critical / Emergency Fixes"] LARGE_DEV["Long-Term Projects (e.g., kTLS ~5 yrs)"] end

NF_DEV -->|"Submit directly upstream"| UP_REV UP_REV --> UP_REPO UP_REPO -->|"Every 3-4 week merge cycle"| NF_TREE UP_REPO -->|"Cherry-pick immediately (security/crashes)"| NF_CHERRY NF_CHERRY --> NF_TREE LARGE_DEV -->|"Refactor for community & upstream"| UP_REPO ```

- A Jenkins job triggers an automated build and test run on every branch push. - Netflix targets two primary server architectures: amd64 (noted humorously as what Microsoft calls amd64 while the rest of the world calls it x86-64) and arm64. - Smoke tests run almost nightly on a dedicated cluster with full kernel debugging enabled: memory corruption detection, use-after-free checking, and lock-order reversal (WITNESS) verification. - Release-candidate testing runs on a broader set of hardware with all debugging checks disabled, focusing strictly on throughput, latency, and performance regressions.

---

[13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) Major Upstream Contributions: Async Sendfile, Unmapped mbufs, and kTLS

Looking back at Netflix's legacy of contributions to FreeBSD, Drew Gallatin singles out asynchronous `sendfile`—developed by his colleague Gleb Smirnoff in collaboration with NGINX—as the single most impactful architectural advancement for their CDN. Normally, `sendfile` blocks the calling thread while data is fetched from disk into memory before passing it to a network socket. Async `sendfile` completely restructures this interaction: the web server issues the system call and immediately returns to its event loop. The kernel pulls the requested data from storage in the background, and the disk controller's interrupt completion handler directly hands the data off to the network stack. Drew Gallatin emphasizes that “that allows us to avoid having thread pool tools or using async iio or doing any any any sort of thing like that and that's that one thing has is the fundamental optimization it's enabled everything else.”

To build toward kernel-level TLS, the team also revamped FreeBSD's core networking memory buffers by creating unmapped mbufs (modeled similarly to Linux's `skb_frag_t`). Instead of mapping every chunk of memory and pointing to single data blocks, an unmapped mbuf holds references to multiple physical pages without touching the kernel page tables. A single mbuf can encapsulate an entire TLS record containing four or five 4KB pages alongside headers and cryptographic signatures, eliminating socket-buffer pointer-chasing and drastically slashing CPU cache misses even when TLS is unused.

Building atop unmapped mbufs, Netflix implemented Kernel TLS (kTLS), shifting bulk payload encryption out of user-space libraries like OpenSSL and into the kernel itself. This eliminates the expensive double trip across the user-kernel boundary where encrypted data had to be read into user memory and written back down to the kernel. Taking this a step further, modern network adapters—such as Mellanox ConnectX-6 Dx (or newer) and Chelsio T6—support NIC TLS offload. Under this architecture, the network interface card executes the crypto operations autonomously in hardware on transmit. Data travels from storage straight onto the wire while the kernel never maps or reads the payload memory at all, rendering the performance overhead of encryption virtually zero from the host CPU's perspective.

---

[16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) Storage Scheduling, Custom TCP Stacks, and DoS Mitigation

Beyond socket primitives, Netflix contributed the CAM I/O scheduler to optimize disk behavior. Under FreeBSD, CAM handles the storage subsystem; Netflix needed a mechanism to fill local Open Connect appliances (OCAs) with fresh catalog titles from peer nodes at the exact same time the server was actively streaming video to users. Heavy write workloads severely degraded read latency on solid-state drives, so the CAM scheduler modulates read and write bandwidth to guarantee playback streams remain fluid without storage-induced jitter.

In networking, Randall Stewart ported Google's BBR congestion control algorithm to FreeBSD and authored RACK entirely from scratch at Netflix. While BBR is famous for its role in HTTP/3 and QUIC, Netflix primarily relies on RACK for its streaming workloads. Alongside RACK, Netflix introduced hardware/software pacing subsystems (such as high-precision timer-based TCP pacing). As Gallatin illustrates, blasting a burst at 100 Gbps toward a residential customer whose cable modem buffer only holds 32KB would instantly overflow the intermediate buffer, dropping packets and triggering cascading TCP retransmissions. Pacing trickles data out smoothly at the exact delivery rate the subscriber connection can sustain.

```mermaid flowchart LR accTitle: Packet Drop via Physical Memory Pointer Hooks accDescr: Flow comparison between standard firewall drops and fast-path recycling via physical memory pointer hooks.

subgraph FastPath ["PMP Hooks (Netflix/XDP-style Fast Path)"] direction TB RX1["NIC Driver receives packet"] --> PMP["Firewall inspects via PMP pointer"] PMP -->|"Drop verdict"| RECYCLE["Driver immediately recycles buffer"] end

subgraph SlowPath ["Traditional Network Stack Drop"] direction TB RX2["NIC Driver allocates new buffer"] --> MAP["Map new DMA / Unmap old"] MAP --> CHAIN["Traverse network stack (Cache misses)"] CHAIN --> FW["Firewall inspects & drops"] FW --> FREE["Free memory pages"] end ```

To counter distributed denial-of-service (DDoS) attacks, Netflix introduced physical memory pointer (PMP) hooks, directly inspired by Linux's XDP (eXpress Data Path). Instead of letting malicious packets flow through standard kernel allocation paths—where the driver must allocate replacement buffers, reprogram DMA descriptors, and pass the data up the stack while burning CPU cache lines—PMP hooks give the firewall an immediate pointer to the packet fresh off the wire. If the packet matches an attack signature, the driver drops it on the spot and immediately recycles the underlying buffer without touching DMA mappings or allocating new memory. This mechanism allows Netflix appliances to discard tens of millions of attack packets per second without stealing a single cycle from legitimate video delivery.

- Scalability improvements upstreamed over the years are so numerous Gallatin remarks they are “probably more than I can remember.” - Warner Losh ported `kboot` (which originally originated on PowerPC 64) to amd64 and arm64, enabling servers running LinuxBIOS without standard UEFI firmware to `kexec` directly into FreeBSD. - Netflix uses its purchasing power to expand hardware support: when acquiring new enterprise hardware that only ships with Linux or Windows drivers, Netflix actively pairs with vendors and provides resources to write and upstream production-grade FreeBSD drivers. - Both Netflix as an organization and the engineers individually contribute financial support to the FreeBSD Foundation. - In his day-to-day role driving performance, Gallatin warns that naive speedups can be counterproductive: stripping out RACK and TCP pacing would theoretically yield higher local throughput benchmarks, but Drew Gallatin emphasizes that “that would make our members quality of experience terrible,” completely violating Netflix's core mission of eliminating video buffering stalls.

[21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) Trade-offs in Performance and Hardware Milestones

Drew Gallatin explains the delicate balancing act required when tuning FreeBSD for Netflix’s Content Delivery Network (CDN). Features like TCP pacing consume noticeable CPU cycles, but disabling them comes at a direct cost to user experience: “like if I got rid of the TCP pacing, well CPU would go way down, but our members would see a lot more of the little spinning wheels for rebuffering.” Consequently, performance tuning is not merely about minimizing raw CPU utilization. Instead, the team’s core objectives are maximizing bandwidth output per machine and lowering overall power consumption so identical traffic volumes can be served from smaller footprints.

```mermaid flowchart LR accTitle: Netflix CDN Hardware Performance Milestones accDescr: Timeline of Netflix CDN single-server bandwidth throughput milestones from 2017 to 2022. Y2017["2017: 100 Gb/s<br/>(Kernel TLS)"] Y2020["2020: 200–240 Gb/s<br/>(AMD Rome)"] Y2021["2021: 400 Gb/s<br/>(NIC TLS Offload)"] Y2022["2022: 800 Gb/s<br/>(Dual Socket AMD)"]

Y2017 --> Y2020 --> Y2021 --> Y2022 ```

Gallatin highlights several historical CDN milestones achieved through continuous kernel and hardware co-design:

- **2017 (100 Gb/s):** Believed to be the world's first production 100 Gb/s CDN server, enabled by the introduction of Kernel TLS (kTLS). - **2020 (200 Gb/s):** Deployed AMD Rome-based single-socket systems capable of delivering approximately 240 Gb/s. - **2021 (400 Gb/s):** The same 2020 hardware reached 400 Gb/s once NIC TLS offload was supported in software and enabled across the fleet, moving the cryptographic operations out of the host CPU directly down into the network card. - **2022 (800 Gb/s):** Achieved on a dual-socket system configured with twice the NICs and twice the NVMe storage of the 2020 design.

[22:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1376s) The Sub-100-Watt 100 Gb/s Server Prototype

Looking toward future efficiency, Gallatin presents an ongoing experimental prototype: delivering 100 Gb/s of traffic under a 100-watt power envelope. The objective is remarkable in perspective: “for the power that you used to have for a light bulb, you can serve 20, 30,000 customers video.” This design bypasses standard server motherboards entirely by running FreeBSD on an Nvidia BlueField DPU (Data Processing Unit).

The system consists of a 100-gigabit BlueField card housing 16 ARM cores and roughly 48 GB of DDR5 memory, plugged into a PCIe expansion backplane alongside NVMe flash storage without any traditional host CPU. While wall power currently measures around 125 watts, Gallatin explains that two factors artificially inflate this number: the lab testbed is powered by an oversized 1200-watt power supply running well below its peak efficiency curve, and the chassis holds excess NVMe drives added to quickly draw traffic during tests. Swapping to an appropriately sized power supply and removing redundant drives is expected to drop system draw below the targeted 100-watt mark.

[24:28](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1468s) The Mystery 20% Performance Regression and Git Bisection

Turning to the talk's main case study, Gallatin outlines why tracking upstream FreeBSD-CURRENT is vital by detailing an incident from August. After pulling in an upstream merge that seemed remarkably straightforward—bearing only two trivial merge conflicts—testing on Netflix's baseline 100 Gb/s reference machine revealed an immediate problem. At standard throughput of around 92 Gb/s, CPU consumption jumped roughly 20%, drifting from its typical low-40% baseline up into an erratic, jagged 50%-plus profile. Standard profiling tools revealed no obvious culprits: no single function showed up excessively hot, and no lock contention explained the overhead.

```mermaid flowchart TD accTitle: Git Bisect Process Across Upstream and Netflix Subtree accDescr: The four-hour verification loop used to bisect FreeBSD-CURRENT commits into Netflix's tree. subgraph BisectLoop["Bisection Loop (~4 Hours per Step)"] A["Pick Upstream Git Commit"] --> B["Merge Commit into Netflix FreeBSD Subtree"] B --> C["Resolve Subtree Conflicts & Build Image"] C --> D["Deploy & Run 92 Gb/s Production Load Test"] D --> E{"CPU Normal or 20% High?"} end E -->|"Bad"| F["Mark Bad, Bisect Backward"] E -->|"Good"| G["Mark Good, Bisect Forward"] F --> A G --> A ```

With no clear lead from profiling, Gallatin turned to git bisect to isolate the fault. Because Netflix maintains its operating system source inside a subtree of a larger internal repository, every single bisection step required finding an upstream hash, merging it into the subtree, manually resolving repeated merge conflicts, compiling a full bootable image, deploying it to hardware, and running validation traffic tests. The entire feedback loop took approximately four hours per step, dragging out into what Gallatin jokes was “one eternity later” before finally isolating the offending commit.

[27:00](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1620s) Colin Percival’s Famous Boot Sort Optimization

The commit isolated by git bisect appeared completely unrelated to network performance or runtime CPU utilization. Authored by FreeBSD committer and Tarsnap founder Colin Percival, the patch had gained wide attention across the FreeBSD community and Hacker News for dramatically speeding up boot times in cloud environments like Amazon AWS:

> “The funny thing is this is like the most famous FreeBSD commit that I can remember.”

Percival had discovered that kernel initialization spent substantial boot time running an inefficient $O(n^2)$ sorting routine across `SYSINIT` entries, which he initially identified as a bubble sort. In FreeBSD, every kernel subsystem uses the `SYSINIT` macro to register initialization hooks. The linker compiles these into an alphabetical list, which the kernel then sorts at boot time across 79 subsystem tiers and roughly eight sub-priorities per tier (e.g., run first, run second, run last, or don't care). Items with matching subsystem and priority keys are considered tied and intended to execute in arbitrary order.

However, the legacy sorting implementation had actually been an unstable selection sort rather than a bubble sort. As a result, tied entries that historically retained their initial linker alphabetical order were inverted into reverse-alphabetical order under the new quicksort implementation. Percival and Gallatin confirmed this behavior using Percival’s `tslog` boot-profiling utility. Flipping the sort order in the new algorithm immediately restored Netflix's normal runtime CPU performance, yet the core question remained: why would reversing the initialization order of tied subsystems cause an active 20% CPU spike during steady-state network delivery?

[29:46](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1786s) Isolating the Driver Subsystem and Frequency Control

To uncover the underlying mechanism, Gallatin modified the kernel to manually steer subsystem ordering through boot arguments rather than rebuilding full kernel images every time. He first bisected across high-level subsystems, which swiftly identified the driver subsystem as the source of the regression. Within the driver subsystem, a second layer of bisection pinpointed the true culprit: competing CPU frequency control drivers attaching to the Intel Xeon processor.

FreeBSD's driver model relies on a probe score mechanism where drivers inspect target hardware and report their suitability:

> “The way drivers are supposed to work in FreeBSD is they're supposed to be a probe score, so every driver kind of gets to look and see, 'Oh yeah yeah, I know what that hardware is, and that's exactly what I was made for and I want that 100%,' or, 'You know, I think maybe I can handle this hardware, but I'm not sure, and if somebody else, you know, better comes along you should give it to them.'”

Instead of utilizing graded probe scores, multiple competing CPU frequency drivers were returning a coarse, binary success status (1 or 0). Consequently, driver attachment defaulted entirely to a first-come, first-served basis, leaving hardware binding dependent on the linker's initial ordering and the subsequent sort behavior.

### [31:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1900s) Uncovering the Driver Conflict Drew explains that the performance regression was caused by a subtle ordering issue in how drivers attach to the kernel. A newer Intel EST (Enhanced SpeedStep) driver and an older Pentium 4 thermal control driver were both present; alphabetically, the newer driver attached first, suppressing the older one. When the ordering was reversed, the older, less capable driver attached first, effectively blocking the newer one from functioning correctly.

This oversight persisted for nearly a decade because the system "worked accidentally." To prevent such occurrences, his colleague, Warner Losh, is currently implementing explicit "probe scoring" for drivers to ensure ties are broken predictably. The bug was identified because the P4 thermal driver provided nonsensical frequency and power data, causing the CPU to run at an incorrectly throttled, slower speed.

### [33:19](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1999s) Community Interaction and Fixes Drew highlights how the collaboration with the FreeBSD community was seamless. After identifying the problematic commit, he reached out to the developer, Colin, via an internal IRC channel. Because the code was fresh, Colin remembered the context, verified the issue, and provided a fix that was merged into FreeBSD-current the following day. Drew immediately cherry-picked the fix into their branch.

He notes that this incident showcases the strategic value of running "current" code. By running server-class hardware at scale, Netflix often acts as an early warning system for the community. Had the bug remained undiscovered for years, it would have been much harder to diagnose or argue for a fix, as developers might have dismissed the report as user error or misconfiguration.

### [36:30](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2190s) Deployment and Fleet Operations Responding to an audience question about the time required to upgrade their massive fleet of tens of thousands of servers, Drew explains that they use a staggered rollout. Upgrades are performed in waves by their operations team to mitigate the risk of unforeseen bugs, typically taking about a week to complete.

He shares a cautionary tale regarding the dangers of firmware updates. Years ago, a new firmware blob for a network interface card (NIC) caused rare, one-in-ten-million I2C read timeouts during routine temperature monitoring. This would cause the NIC to reset and go offline. Because this happened at locations without IPMI (Intelligent Platform Management Interface) access, it created a severe operational crisis. This experience led Netflix to be much more conservative, often maintaining their own validated copies of firmware rather than blindly adopting upstream versions.

### [38:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2320s) FreeBSD vs. Linux and Closing Thoughts Addressing a question about why Netflix chooses FreeBSD over Linux, Drew avoids a "flame war" but emphasizes that the decision is purely pragmatic. He points out that he has extensive experience across various operating systems—including Linux, Solaris, macOS, and VMware—and is not dogmatic about the technology.

“We're not stupid and we wouldn't be running FreeBSD if it didn't work better in this application for us,” he says. He notes that while the initial historical decision may have been influenced by the FreeBSD license, the current choice is driven by the fact that it remains the best tool for their specific needs. The session concludes with the moderator thanking him for sharing his work and presenting him with a token of appreciation from the organizers.

## Notable quotes > [38:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2320s) We're not stupid and we wouldn't be running FreeBSD if it didn't work better in this application for us — Drew Gallatin

> [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) if I got rid of the TCP pacing, well CPU would go way down, but our members would see a lot more of the little spinning wheels for rebuffering. — Drew Gallatin

## Mentioned Drew Gallatin, Colin Percival, Gleb Smirnoff, Randall Stewart, Warner Losh, Netflix, Open Connect, Open Connect Appliances, FreeBSD, FreeBSD-CURRENT, FreeBSD-STABLE, FreeBSD Foundation, Linux, NetBSD, 386BSD, SunOS, Solaris, macOS, VMware, NGINX, ZFS, UFS, kTLS, CAM I/O scheduler, BBR, RACK, XDP, kboot, Jenkins, Intel Xeon, Intel EST, Pentium 4, Nvidia BlueField DPU, AMD Rome, Mellanox ConnectX-6 Dx, Chelsio T6, Tarsnap, tslog

## Video description We run FreeBSD-current on our CDN at Netflix. By running FreeBSD-current, we can find and fix bugs far more effectively than by running an older FreeBSD-stable branch. This talk describes our team, how we track FreeBSD-current, our contributions to FreeBSD, and some of the performance milestones we've hit. It will end with a description of a finding and fixing very interesting bug in upstream FreeBSD that caused a 20% performance regression.

#OpenFest 2023 I Share Therefore I Am

Website: https://openfest.org/ Facebook: https://www.facebook.com/OpenFestBulgaria Linkedin: https://linkedin.com/company/openfest-bulgaria/ (X) Twitter: https://twitter.com/OpenFestBG Instagram: https://www.instagram.com/OpenFestBulgaria Mastodon: https://mastodon.social/@openfest

[Source](https://www.youtube.com/watch?v=q4TZxj-Dq7s)

中文简报

Netflix在CDN集群中部署FreeBSD主干代码以尽早捕获性能衰退 在生产环境中跟进前沿开发代码,既消除了长达数年的升级技术债,又能快速发现导致服务器性能下降的上游回退。 Drew Gallatin详细介绍了Netflix如何使用FreeBSD为其全球Open Connect Appliance集群提供支持,在静态流媒体工作负载下,单台服务器的带宽可高达800 Gbps。该团队从跟踪FreeBSD-STABLE转变为直接在生产环境中运行FreeBSD-CURRENT,从而实现了与上游的快速协作,并避免了耗时数月的漫长升级痛苦。Gallatin回顾了为FreeBSD设计的核心架构增强功能——包括异步sendfile、未映射mbuf以及带网卡卸载的内核TLS——随后详细分析了名为“神奇神秘合并”的案例研究:一项备受好评的启动时间排序优化反转了子系统的初始化顺序,导致出现竞争的CPU频率驱动程序使生产机器降速20%。 Netflix在其Open Connect CDN的生产环境中直接跟踪FreeBSD-CURRENT,每三到四周围绕上游代码进行一次合并,以便立即捕获性能回退并消除长达数月的升级困境。 (8:10) 通过将硬件与FreeBSD内核优化(包括异步sendfile、未映射mbuf和网卡TLS卸载)进行协同设计,Netflix在2017年至2022年间将单服务器CDN吞吐量从100 Gbps提升至800 Gbps。 (21:20) 一款功耗低于100瓦、吞吐量达100 Gbps的实验性边缘服务器原型直接在Nvidia BlueField DPU上运行FreeBSD,完全绕过了传统服务器主板和主CPU,向数万名订阅者流式传输视频。 (22:56) 上游一项著名的启动时间排序优化暴露了一个存在十年的驱动程序顺序缺陷:按字母倒序决胜导致过时的Pentium 4散热驱动程序抢先于Intel SpeedStep加载,从而使CPU性能下降了20%。 (27:00)

Reading summary

Drew Gallatin explains that Netflix runs the development branch FreeBSD-CURRENT across its Open Connect content delivery network to eliminate debilitating multi-month upgrade cycles, catch regressions immediately, and maintain minimal divergence from upstream code. Appliance Storage and Hardware Architecture (0:18) Open Connect Appliances (OCAs) function similarly to embedded network devices, relying on an A/B dual-partition update model and serving static, pre-encoded video files without runtime transcoding. Gallatin notes that Netflix uses ZFS strictly on root partitions, formatting video content storage with UFS to eliminate data-copying overhead between ZFS's Adaptive Replacement Cache and the kernel page cache. Disks operate without software or hardware RAID and are allowed to fail in place, avoiding expensive field technician dispatches to remote data centers. Through deliberate hardware and kernel co-design, single-server appliance capacity grew from 100 Gb/s in 2017 to 800 Gb/s on dual-socket systems by 2022. For future deployments, Netflix is experimenting with an Nvidia BlueField DPU prototype that runs FreeBSD on 16 ARM cores without a host CPU, aiming to deliver 100 Gb/s of throughput within a sub-100-watt power envelope. Abandoning Stable for Upstream FreeBSD-CURRENT (8:10) Netflix historically tracked FreeBSD -STABLE releases, but upgrading between major versions produced painful multi-month project delays caused by interface drift, upstream regressions, and accumulated internal code hoarding. Around five to six years prior, the team inverted this strategy by tracking FreeBSD-CURRENT directly in production on a tight three-to-four-week merge cadence. This frequent synchronization shrank Netflix's private delta against upstream FreeBSD, allowing its team of roughly ten engineers to write minor features and fixes directly upstream first. Automated Jenkins pipelines build and test every branch push, running nightly smoke tests with memory-corruption and lock-order checking enabled, followed by release-candidate testing on production hardware with debugging disabled. While critical security patches are cherry-picked immediately, large architectural shifts like Kernel TLS (kTLS) were retained internally for nearly five years to refine the interfaces for general community use. Core Upstream Contributions and Transport Optimizations (13:56) Gallatin highlights asynchronous sendfile, developed alongside NGINX, as Netflix's most foundational optimization: disk interrupt handlers pass storage data directly to the network stack, freeing web server event loops without thread pools. To facilitate in-kernel cryptography, the team developed unmapped mbufs to reference physical pages without page-table overhead, enabling kTLS and hardware NIC TLS offload that shifts bulk encryption down to network adapters with near-zero host CPU cost. Additional Netflix contributions include the CAM I/O scheduler to balance background catalog writes against latency-sensitive streaming reads, as well as TCP pacing combined with the RACK congestion control algorithm to prevent residential modem bufferbloat. To repel distributed denial-of-service traffic, Netflix introduced physical memory pointer (PMP) hooks—inspired by Linux XDP—allowing firewalls to drop attack packets at line rate and recycle underlying buffers without triggering memory reallocation or cache misses. The Boot-Sort Regression and Fleet Reliability (24:28) The practical benefits of running -CURRENT were demonstrated when a routine merge caused a 20% steady-state CPU spike on reference 92 Gb/s testing hardware. A four-hour-per-step git bisection traced the regression to an optimization by Colin Percival intended to speed up AWS cloud boot times by replacing an O(n^2) SYSINIT sorting algorithm. The change accidentally inverted the order of tied subsystems. Because FreeBSD's CPU frequency drivers lacked graded probe scores and attached on a first-come, first-served basis, this inversion caused an older Pentium 4 thermal driver to attach ahead of the Intel Enhanced SpeedStep driver, running the processor in an incorrectly throttled state. Direct collaboration with Percival produced an upstream fix within 24 hours, proving how Netflix acts as an early-warning validation system by exercising -CURRENT on enterprise hardware at scale. Gallatin emphasizes that adopting FreeBSD over Linux is a pragmatic engineering decision driven by application performance rather than dogmatism. While running the development trunk enables rapid upstream collaboration, fleet operations remain deliberately guarded: software updates roll out in staggered weekly waves, and validated hardware firmware is frozen internally after experiences with buggy vendor firmware causing catastrophic edge resets.

精炼阅读摘要

Netflix 工程师 Drew Gallatin 指出,Netflix 在其内容分发网络(CDN)中全面部署 FreeBSD-CURRENT 主干开发分支,通过紧凑的合并周期消除技术债务并赋能内核级性能创新;这种策略不仅让大规模生产环境成为开源社区的早期预警系统,更证明了前沿跟踪在工业级基础设施中的实际可行性。 定制化 CDN 架构与专用存储设计 (0:18) Netflix 的 Open Connect CDN 由专用的 Open Connect 节点(OCA)组成,其运行逻辑类似于网络家用路由器而非传统通用服务器。全网 OCA 运行完全统一的基础软件镜像,并采用 A/B 双分区更新机制;若新版本引导失败,系统将自动回退至原有分区。顶级 OCA 的单机网络带宽输出可达 400 Gbps,硬件形态涵盖配备 NVMe/SATA SSD 的全闪存机型、数百 TB 级的长尾存储机型,以及嵌入小型 ISP 内网以降低上行传输压力的全球嵌入式机型。所有边缘工作负载严格聚焦于静态文件的分发,视频在入库前已被预先编码为适配各种设备与码率的数十个版本,因此边缘服务器完全省去了运行时转码开销,专注于纯粹的网络与磁盘 I/O。 页缓存优化与无 RAID 容错策略 (3:20) 针对广泛关注的文件系统选型,Gallatin 解释 Netflix 仅在根分区使用 ZFS,而所有视频内容分区均采用 UFS 并搭配 NGINX。这一架构选择的核心在于缓存效率:ZFS 依赖独立的自适应替换缓存(ARC),内容分发时必须将数据从 ARC 复制到操作系统的页面缓存,这会带来内存复制损耗并降低流媒体吞吐量;UFS 则能与内核的原生页面缓存直接无缝集成。在存储可靠性方面,内容磁盘完全不使用硬件或软件 RAID,而是允许驱动器在槽位上直接损坏下线。由于整机聚合容量极大,单块或少量硬盘故障不会破坏服务器的持续服务能力,这避免了派遣现场技术人员前往第三方 ISP 或偏远数据中心进行高成本更换的运维开销。 放弃稳定分支与跟进 CURRENT 的工程红利 (8:10) Netflix 早期遵循传统企业模式跟踪 FreeBSD-STABLE 维护分支,但跨大版本的升级极具破坏性,往往耗费数周甚至长达六个月来排查接口不兼容与上游回归缺陷。这种摩擦导致内部代码难以向上游回馈,形成了巨大的私有技术债务。约在五至六年前,团队彻底转变为直接跟踪 FreeBSD-CURRENT,维持每三至四周从上游合并一次的节奏。由于私有分支与主干几乎一致,Netflix 工程师通常直接将日常缺陷修复与功能提交至上游 FreeBSD 仓库,随后在下一次合并周期自动吸纳回内部,极大地降低了代码分歧;仅有类似耗时近五年架构的 Kernel TLS(kTLS)等深层次重构,才会在内部打磨成熟后再提交社区。 内核级网络栈重塑与硬件协同演进 (13:56) 在内核底层优化方面,Netflix 联合 NGINX 推动了异步 sendfile 机制,允许 Web 服务器在发起系统调用后立即重回事件循环,数据从磁盘拉取后直接由中断处理程序移交网络栈,省去了线程池和异步 I/O 的抽象层负担。此外,团队引入未映射 mbuf(unmapped mbufs)来管理物理页引用,从而支撑 kTLS 将加密工作下放至内核,甚至通过 Mellanox ConnectX-6 Dx 和 Chelsio T6 等网卡实现 NIC TLS 硬件卸载,将主机 CPU 的加密负载降至接近零。网络层面上,Netflix 引入了 RACK 拥塞控制和高精度定时器 TCP pacing,平滑输出流量以避免因突发数据包打翻家庭宽带调制解调器的 32KB 浅缓冲区。针对 DDoS 攻击,基于物理内存指针(PMP)的钩子技术允许防火墙在网卡驱动接收即刻丢弃攻击包并复用底层缓冲区,每秒可丢弃数千万数据包且不消耗常规内存分配开销。 20% 性能衰退溯源与驱动仲裁启示 (24:28) 在一次仅包含两处轻微冲突的常规上游合并后,Netflix 的 100 Gb/s 基准机型在 92 Gb/s 负载下的 CPU 占用率意外飙升约 20%,且常规性能剖析工具未显示明显的锁竞争或热点函数。由于源码存放在内部大型仓库的子树中,工程师通过耗时漫长(每步约四小时)的 git bisect 最终定位到 Colin Percival 为加速云环境引导而提交的 SYSINIT 排序优化补丁。该补丁将低效的冒泡排序替换为快速排序,导致优先级并列的初始化项从默认正序变为反序。进一步排查发现,FreeBSD 的驱动探测评分机制在该场景下退化为粗糙的布尔状态,导致初始化的顺序反转让古老的奔腾 4 热控制驱动抢占了新的 Intel EST 变频驱动,使 CPU 运行在受限的降频状态。由于直接跟踪 CURRENT,团队当天即通过 IRC 与原作者协同复现并在次日向上游推送了修复,避免了缺陷在稳定版中长期沉睡。 Drew Gallatin 强调,Netflix 选用 FreeBSD 是基于吞吐效能与能耗比的纯粹务实抉择,而非出于技术意识形态。尽管跟踪 CURRENT 分支需要完备的自动化测试体系以及对固件和驱动更新的保守风控,但其带来的上游协同效率和性能收益,使其成为支撑超大规模单机吞吐演进的关键战略支柱。

Detailed notes — zh

## Background 本内容由 OpenFest Bulgaria 于 2024 年 2 月 18 日发布在 YouTube 平台上。页面简介显示,Netflix 在其 CDN 网络中直接运行 FreeBSD-CURRENT 主线分支,演讲者 Drew Gallatin 详细介绍了团队的运作模式、跟进主线的原因、向 FreeBSD 社区的技术回馈与性能里程碑,并以一次定位并修复导致 20% 性能衰退的经典 Bug 为例展开深度剖析。 ## TL;DR Drew Gallatin 系统分享了 Netflix CDN(Open Connect)放弃传统的 FreeBSD-STABLE 分支、全面转向生产环境跟踪 FreeBSD-CURRENT 的工程实践。团队通过 3 至 4 周一次的高频合并循环与严密的 CI 验证,极大消除了私有技术债务,并向上游贡献了 Async Sendfile、Unmapped Mbufs、Kernel TLS 硬件卸载及 RACK TCP 等核心架构。演讲重点复盘了 2023 年一次上游引导排序重构意外颠倒 CPU 变频驱动加载顺序、导致系统静默降频 20% 的排查过程,生动证明了紧跟上游开发主线对于快速捕获并修复深层性能回归的不可替代性。 ## Atmosphere & style 现场氛围专业务实而充满极客式的幽默感。Drew Gallatin 以资深系统程序员特有的松弛与坦诚,把原本极其枯燥的内核代码二分排查、驱动评分竞争和固件崩溃事故,讲得像是一场引人入胜的底层探案故事。整场演讲不仅洋溢着对极致吞吐与低功耗架构的技术自豪感,更通过调侃阵营偏见展现出纯粹以工程实效为准绳的务实大家风范。 ## Bulletin - [08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) Netflix 改变了跟踪 FreeBSD-STABLE 的传统做法,改为每三至四周直接将主线开发分支 FreeBSD-CURRENT 合并入内部生产代码库,以避免跨大版本升级时积累的严重技术债务和隐蔽性能回归。 - [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) Netflix CDN 通过异步 sendfile、Unmapped Mbufs 及 Kernel TLS 网卡硬件卸载等内核级深度改造,单机吞吐从 2017 年的 100 Gbps 跃升至 2022 年双路系统的 800 Gbps。 - [28:05](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1685s) 一次上游引导排序优化改变了平局元素的字母排序,导致老旧的 p4tcc 驱动抢先占用 CPU 频率控制权,使 Intel Xeon 处理器在内核毫无察觉的情况下降频,引发生产测试中高达 20% 的性能断崖。 - [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) 借助 NVIDIA BlueField DPU 原型,Netflix 正在探索在低于 100 瓦的功耗下提供 100 Gbps 视频推流服务,相当于以往一个灯泡的能耗即可支撑数万名用户观影。 ## Key takeaways - [03:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=200s) Netflix Open Connect Appliance (OCA) 采用类家用路由器的 A/B 分区整机镜像刷写与故障就地废弃(Fail in place)策略,根分区运行 ZFS,而内容分区采用 UFS 以直接集成内核 Page Cache 消除内存拷贝开销。 - [08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) 跟踪 FreeBSD-STABLE 会导致私有补丁与社区 API 漂移严重,大版本升级动辄耗费数月排查冲突,直接切入 FreeBSD-CURRENT 反而将缺陷捕获周期从数年缩短至三到四周。 - [11:02](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=662s) Netflix 在内部推行小特性直接上游提交、大改动经过长期抽象打磨后再回馈的原则,将本地私有补丁规模压缩到极致。 - [12:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=776s) 通过 Jenkins 并行覆盖 amd64 与 arm64 架构,并在测试集群中运行全开内存破坏、Use-After-Free 和锁逆序检测的内核,确保开发分支在边缘节点的稳定性。 - [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) 异步 sendfile(Async Sendfile)将磁盘 I/O 调入与网络发送通过中断完成处理程序解耦,使 Web 服务器完全免去线程池或异步 I/O 的复杂调度。 - [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) Unmapped Mbufs 聚合跨页物理数据并减少指针追逐,配合 Mellanox 与 Chelsio 网卡实现 KTLS 硬件线速加密,内核全程无需触碰内存数据。 - [16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) 定制的 CAM I/O 调度器有效隔离了突发写入对视频读取流的干扰,RACK TCP 协议栈与硬件/内核级 Pacing(HBTS)则消除了毫秒级微突发引发的网络调制解调器溢出丢包。 - [16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) 基于网卡驱动层指针挂钩的 PMP 技术可在线速状态下实现每秒数千万数据包的就地快速丢弃,彻底化解超大规模 DDoS 泛洪攻击对流媒体服务的干扰。 - [20:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1220s) 性能调优的核心红线是保障最终用户的播放体验(QoE),盲目关闭 TCP Pacing 虽然能降低 CPU 占用,但会引发客户端大量重缓冲卡顿。 - [28:05](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1685s) Colin Percival 对引导期 SYSINIT 排序算法的优化改变了并列元素的稳定性,将原本偶然维持了十年的字母正序变成了字母逆序。 - [31:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1900s) Intel 变频驱动缺乏探测评分(probe score)权重机制,使得老旧的 p4tcc 驱动凭先到先得抢先注册,排挤了现代的 est 驱动,导致 CPU 实质处于降频状态。 - [33:16](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1996s) 跟进 CURRENT 主线使二分查找能够锁定在三周的时间窗口内,并促成上游开发者在数小时内快速定位、修复并合并该内核回归。 - [36:06](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2166s) 生产机群全量部署采用为期约一周的波浪式滚动升级,在经历过高频 I2C 遥测引发网卡固件死锁的惨痛事故后,Netflix 已经将核心固件与上游彻底解耦并单独冻结。 - [38:55](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2335s) 技术选型不带有任何操作系统信仰或意识形态偏见,选用 FreeBSD 纯粹是因为其在静态大流量分发的特定 CDN 负载下表现出最优的工程性能。 ## Detailed walkthrough ### [00:18](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=18s) 讲师介绍与 Open Connect 架构概述 主持人热情登台介绍本次演讲的主讲人 Drew Gallatin。Drew 在 Netflix 工作已有大约八年时间,专精于 FreeBSD-CURRENT 的性能优化,同时也是一位活跃了超过 25 年的资深 FreeBSD 代码提交者(committer)。Drew 开场说明,本次分享首先会介绍 Netflix 如何在其实际业务中使用 FreeBSD,随后重点阐述他们为什么选择直接跟进主线开发分支 FreeBSD-CURRENT,最后通过一个被他命名为“神奇神秘合并”(The Magical Mystery Merge)的真实性能回归案例,生动展现跟踪 CURRENT 分支的巨大价值。 ```mermaid flowchart TD accTitle: Netflix Open Connect CDN 架构与缓存节点类型 accDescr: 展示 Netflix Open Connect 节点的分类、硬件特征与部署位置 subgraph CDN["Netflix Open Connect (CDN)"] direction TB subgraph OCA_Types["Open Connect Appliances (OCA 节点)"] Flash["全闪存 OCA (All-Flash)\n• NVMe / SATA SSD\n• 400 Gbps 吞吐\n• 存放最热门内容"] Storage["存储型 OCA (Storage)\n• 拥有数百 TB 容量\n• 冷门长尾至普通热门内容"] Global["全局型 OCA (Global)\n• 部署在小型 ISP 内部\n• 减轻 ISP 上行链路压力"] end end IXP["互联网交换中心 (IXP) / 核心数据中心"] --> Flash IXP --> Storage ISP["本地 ISP 网络 (内部直出)"] --> Global ``` Drew 供职于 Netflix 的 CDN 团队,该内容分发网络在内部被称为 Open Connect,其中的边缘服务器则统称为 Open Connect Appliances(简称 OCA)。Drew 解释道,之所以称它们为“Appliance(专有设备)”,是因为在架构行为上,这些机器与办公室内普通的服务器差异很大,反而更类似于家用的家用路由器。每台设备都具备 A/B 两个系统分区,更新机制采用严格的整机镜像刷写:当系统升级时,直接将完整镜像刷写入 B 分区,启动验证失败则自动回退至 A 分区。更重要的是,整个网络中所有机器的底层软件环境完全一致,绝不会出现某些软件包在某台机器上存在而在其他机器上缺失的情况。目前 Netflix 的 OCA 已经演化出可承载 400 Gbps 吞吐能力的硬件规格,并在生产中部署了三种主要形态: - **全闪存 OCA(All-Flash OCA)**:采用全 NVMe(或早期全 SATA SSD)构建,主要部署在互联网骨干交换中心(IXP)的核心数据中心,专门支撑全网最热门内容的极高并发分发。 - **存储型 OCA(Storage OCA)**:单机配备数百 TB 级别的海量存储,用来存放全量视频资产,涵盖从每周可能仅被点播一次的长尾低频影片,到主流流行节目的各种拷贝。 - **全局型 OCA(Global OCA)**:直接嵌入部署在规模较小或者偏远地区的互联网服务提供商(ISP)内网中,用户观影流量由内网直接下发,避免了占用 ISP 昂贵的跨网外网出口链路(Uplink)。 ### [03:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=200s) 存储架构选择与只读静态工作负载 在底层软件栈与文件系统的选择上,许多人最常问 Drew 的问题是:“你们跑不跑 ZFS?”Drew 给出了明确肯定的答案,但同时做出了关键技术限定:Netflix 仅将 ZFS 用于服务器的根分区(Root Partition),而所有承载庞大媒体视频的数据内容分区(Content Partitions)则全部采用传统的 UFS。这一架构决策背后的核心技术权衡在于缓存架构:ZFS 依赖自身的 ARC(自适应替换缓存,Adaptive Replacement Cache),它是独立于操作系统内核 Page Cache(页面缓存)之外的一套内存系统;如果通过 ZFS 传输大文件内容,数据必须经历从 ARC 拷贝到内核 Page Cache 的中间步骤,这在高吞吐场景下带来了巨大的内存复制开销与效率损失,因此 UFS 凭借与内核 Page Cache 的直接集成成为了视频流分发的高效底座。 在 Web 服务器层面,Netflix 全面运行 NGINX。在硬件容错策略上,Netflix 与多数部署复杂 RAID 或高冗余存储系统的 CDN 截然不同——他们不使用任何硬件或软件 RAID(仅根分区保留基本的镜像冗余),内容盘一律采用“故障就地保留”(Fail in place)策略。Drew 直言,让坏盘直接留在机架上挂掉,远比协调全球各地的 ISP 驻场人员或频繁派遣数据中心维护工程师去现场热拔插硬盘省心得多;况且每台 OCA 本身就拥有巨大的冗余存储容量,即使局部损坏一到两块硬盘,剩余的可用磁盘空间和硬件吞吐依然足以提供极高价值的服务能力。 整套 CDN 的业务负载高度专一,其本质就是极其纯粹的静态文件下发。所有媒体资源早在推送到 CDN 边缘之前,就已经完成了全套的预转码处理。为了追求极致画质,Netflix 投入了巨大的工程精力优化编码:同一部影视剧会根据手机端、智能电视端、桌面 PC 等不同终端平台及差异化网络带宽,预先烘焙出几十种不同分辨率、不同编解码器(Codec)和多码率的独立流文件。因此,边缘 CDN 节点在运行期间不需要介入任何动态编解码或复杂计算逻辑,极大地简化了内核与系统的负载压力。 - **根分区架构**:采用 ZFS,仅支撑基础系统的生命周期管理与回滚。 - **内容分区架构**:采用 UFS,直通内核 Page Cache,消除内存二次复制开销。 - **磁盘容灾理念**:完全摒弃 RAID 冗余,驱动器损坏即就地离线废弃(Fail in place)。 - **计算模型特性**:100% 静态预生成资源下发,边缘零实时转码运算。 ### [05:26](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=326s) FreeBSD 的历史演进与 Netflix OCA 团队 为了让熟悉 Linux 的开发者理解技术背景,Drew 回顾了 FreeBSD 的技术脉络与历史分化。Linux 诞生之初完全由 Linus Torvalds 从零起步编写,而 FreeBSD 则是 1980 年代加利福尼亚大学伯克利分校 BSD 系统的直系后裔(当年 SunOS 等 Unix 商业系统也是基于此衍生)。FreeBSD 的直接前身是 386BSD,旨在将 BSD 移植到 Intel 386 PC 架构上。在 386BSD 维护陷于停滞后,社区维护的一套核心补丁集(Patch Kit)分化为两个独立阵营: - **NetBSD 路线**:与 FreeBSD 大致同时期起步,核心设计目标是追求代码的绝对纯洁性、逻辑正确性以及对尽可能多硬件架构的超广泛跨平台移植兼容性。 - **FreeBSD 路线**:坚定聚焦于极致性能,初期全力榨干 32 位 x86 处理器的性能潜力。 Drew 回忆道,自己在 1990 年代末期以 FreeBSD committer 身份开启开源生涯时,参与的正是 FreeBSD 首个 64 位平台移植项目。FreeBSD 长期秉持服务主流高性能架构的设计理念;一旦芯片厂商淘汰某种硬件,FreeBSD 也会毫不犹豫地终结对其支持——例如曾经名噪一时的 DEC Alpha 架构在停产后,便成为了 FreeBSD 首个正式宣布退役支持的端口。 在发行模式上,FreeBSD 与现代 Linux 发行版有着根本差异。Linux 几乎把所有软件拆分为离散的 package(包管理单元);而 FreeBSD 至今依然保留了 Unix 经典的一体化传统:内核(Kernel)、底层基础库、以及日常 Shell 操作工具(如 `ls`、`mv`、`cp`)乃至编译器工具链等全部打包整合在同一套基本系统(Base System)中,安装至根文件系统;只有像 NGINX、Firefox 这类第三方应用软件,才会通过 Ports/Packages 系统以独立软件包方式安装。而在 Netflix 内部,OCA 节点运行的是一套经过极度精简裁剪的私有化定制发行版,所有不需要的编译器、开发文档以及杂项软件包均被完全剔除。负责这一切的是 Netflix 内部仅约 10 人构成的 OCA 研发团队(OCA Dev Team),团队成员绝大多数都是经验深厚的 FreeBSD committer 或长期贡献者;Drew 充满感情地评价道:“它是一个绝佳的工作环境,也是我经历过的最棒的一份工作。” ### [08:10](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=490s) 传统维护模式的痛点与向 FreeBSD-CURRENT 的跃迁 在基础设施演进的最初阶段,Netflix 的工程团队和业界绝大多数企业一样,理所当然地选择了跟进所谓安全的稳定版本分支(FreeBSD-STABLE)。FreeBSD 的分支模型与 Linux 高度相似:所有最新的特性和代码首先生效于名为 FreeBSD-CURRENT 的主干分支(等同于 Linux 的 Linus 主线分支);而每隔几年(官方设计规划为两年发布一次,但现实中通常拖延到三至四年),社区会从 CURRENT 中拉出长期维护的 STABLE 分支,概念完全对应 Linux 的 LTS(长期技术支持)版本。在早期,Netflix 的标准运维方式是锁定最新的 STABLE 分支,每隔数周把上游在该分支打上的安全修复与 Bug 修复代码回流(merge)合并到自家的内部仓库中,编译生成固件推送给全球节点。 这种工作流在单个稳定分支的周期内运转尚可,但一旦面临跨大版本升级——从一个 STABLE 分支迁移到下一个全新的 STABLE 分支——灾难便彻底爆发了。Drew 描述道,这种跨版本迁移在最乐观的情况下也要耗费数周时间,而绝大多数时候需要花费数月、甚至长达半年之久。原因主要来自两个维度的夹击: 1. **未合入上游的私有技术债务**:Netflix 团队内部积累了大量未推入社区主线的定制化优化代码,当社区在新分支中改动了底层驱动或内核接口时,私有代码与新接口发生严重冲突与断层。 2. **上游隐蔽的性能回退**:跨越三到四年的庞大版本变更中,上游代码不可避免地混入了难以排查的性能倒退(Regression)。在堆积如山的代码变更中定位 Bug 犹如大海捞针。 ```mermaid flowchart LR accTitle: 跟踪 STABLE 分支引发的技术债务死循环 accDescr: 展示旧有维护模式下代码回馈上游困难导致技术债务越积越多的恶性循环 subgraph DebtLoop["STABLE 维护模式下的技术债务恶性循环"] A["在 STABLE 分支开发\n私有优化特性"] --> B["上游 API/函数参数\n在 CURRENT 发生变更"] B --> C["回馈上游成本高昂\n(需移植到 CURRENT + 额外环境测试)"] C --> D["缺乏动力上推代码\n特性大量留存在内部"] D --> E["大版本升级合并\n(STABLE A -> STABLE B)\n耗时数月排查冲突与回归"] E --> A end ``` 更痛苦的是与上游开源社区的协作割裂。由于两个分支的内核 API 往往存在漂移(例如同一个内核函数在 STABLE 接受 3 个入参,而在 CURRENT 中需要 4 个入参),Netflix 研发人员若想向社区回馈一项自研成果,必须先在完全不运行 CURRENT 的内网环境下将代码移植到 CURRENT 树上、设法找机器验证、提交上游审核通过,然后再苦等好几年直到这些代码随下一个 STABLE 分支落地。这一繁琐低效的流程彻底扑灭了工程师向主线推代码的动力,导致大量改动积压在内部分支。私有补丁越多,下一次跨版本升级的冲突就越惨烈,技术债务恶性循环滚雪球。 Drew 表示,正是因为看清了这种死局,团队在五六年前毅然做出了颠覆性决定:“停止跟踪 STABLE 分支,直接在生产边缘节点跟踪运行处于主线最新开发状态的 FreeBSD-CURRENT。”这在传统运维思维看来简直不可思议,因为 CURRENT 分支每天接收着全球开发者最新、最不稳定的代码;加之与 Linux 严格的子系统维护者(Subsystem Maintainers)梯队审核机制不同,在 FreeBSD 体系中,任何拥有 Commit Bit 的提交者都可以直接往代码库提交改动,全凭开发者的自由与责任感驱动。但正是这个极其大胆的选择,彻底重塑了 Netflix 驾驭底层内核技术迭代的能力。 - Drew 总结团队在旧流程下陷入的困境:“所以我们能看到,通过这种方式,我们实际上正在积累技术债务;大约在五六年前,我们意识到自己正在做的事情很愚蠢,我们真正应该做的,其实是去跟踪 FreeBSD-CURRENT。”(“So we could see that we we were kind of building up a technical debt by doing this and so about five six years ago we we decided what we were doing was silly and what we should do really is to track FreeBSD current…”) ### [11:02](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=662s) 紧跟 FreeBSD-CURRENT 的好处与上游合并循环 Drew Gallatin 谈到,尽管许多人认为运行处于开发前沿的 FreeBSD-CURRENT 是一件疯狂且不稳定的事情,但对 Netflix 而言这反而是最理想的选择。团队每隔三到四周就会执行一次合并周期,将上游 FreeBSD 的最新改动拉取到 Netflix 内部代码库中。这种高频拉取的最大优势在于能够极快地捕获性能退化或缺陷,根本不会出现社区提交了代码却在两三年后才被发现引发故障的情况。同时,这也极大地方便了将 Netflix 的优化快速推向上游,免去了针对不同操作系统版本进行繁琐移植的痛苦。Drew Gallatin 总结道:“current is sometimes somewhat unstable and so running current sounds crazy but it's actually the best thing in the world because when we run current we do the same every 3 four weeks merge cycle where we pull in the stuff from upstream and when we do that we catch things really fast.” 随着多年来的紧密协作,Netflix 内部保留的私有补丁数量越来越少。对于小功能或小 bug 修复,工程师甚至不再走“先内部修复再回馈”的老路,而是直接在上游官方 FreeBSD 代码库中提交、走审查流程并合入,随后等待三周一次的合并周期自动流回 Netflix 代码库中。这种策略极大地遏制了维护私有分支带来的技术债务。如果遇到严重的崩溃或安全漏洞,团队则会立即挑选该 commit 进行 cherry-pick。至于少数高度侵入性的大型改动(如 Kernel TLS),Netflix 曾在内部维护了接近五年,但这并非为了保留专有秘密,而是为了打磨架构,确保最终贡献给上游的代码具备通用性,而非仅仅适应 Netflix 的单一场景。 ```mermaid flowchart LR accTitle: Netflix 与 FreeBSD 代码同步与合并流程 accDescr: 展示 Netflix 工程师如何将小修补直接提交上游、定期拉取代码以及针对关键问题进行 Cherry-pick 的过程。 subgraph Upstream["FreeBSD 上游社区"] U_Repo["FreeBSD-CURRENT 仓库"] U_Review["代码审查与合并"] U_Repo --> U_Review end subgraph Netflix["Netflix 内部环境"] N_Repo["Netflix 内部代码分支"] N_Prod["CDN 生产部署"] N_Repo --> N_Prod end Netflix -.->|"小功能 / Bug 修复直接提交"| U_Review U_Review -->|"三至四周自动合并周期"| N_Repo U_Repo ==>|"紧急修复 / CVE 快速 Cherry-pick"| N_Repo ``` - **三至四周合并周期**:定期从 FreeBSD-CURRENT 主线合并代码,将上游缺陷排查周期从数年缩短至几周。 - **技术债务持续减少**:直接在上游开发小特性,等待常规同步回流,最大程度减少本地私有补丁。 - **大型项目打磨周期**:Kernel TLS 等重大架构改造在内部经过长达近 5 年的重构与验证,最终以最通用、健壮的形式回馈社区。 --- ### [12:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=776s) CI 自动化测试流水线与内核健全性检查 为了在 FreeBSD-CURRENT 上保证高可靠性,Netflix 建立了严格的 CI/CD 测试流程。只要有代码推送到内部代码分支,Jenkins 任务就会立即被触发执行。由于 Netflix 的 CDN 节点同时跑在 amd64(微软也称 amd64,业界广泛称为 x86_64)和 arm64 架构上,自动化流水线会在两种硬件架构上并行跑完基础的回归测试套件(Regression Suite)。 除了常规的提交级验证,团队每晚(或几乎每晚)都会在一组专用小型服务器集群上执行“冒烟测试”(Smoke Test)。这些测试机器启动的内核会打开所有能开的调试检查开关,以穷尽一切手段捕获隐藏缺陷。当进行发布验证(Release Testing)时,系统则会切换到一个更大规模的机器集群上,关掉所有高开销的调试断言,专门用于监测吞吐性能波动和细微的系统级退化。 - **多架构支持覆盖**:amd64 和 arm64 双平台均有自动化测试任务覆盖。 - **冒烟测试全量调试项**:包含内核内存破坏检查(Memory Corruption Checking)、释放后使用检查(Use-After-Free Checking)以及锁逆序/死锁检测(Lock Ordering / Lock Reversal Checking)。 - **发布级性能基准测试**:在关闭调试开关的集群上压测真实性能指标,精准定位是否有性能倒退。 --- ### [13:56](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=836s) 内核核心优化:Async Sendfile、Unmapped Mbufs 与 KTLS 回顾 Netflix 多年来的技术积累,Drew Gallatin 最引以为傲的是团队对 FreeBSD 内核做出的一系列奠基性改造。其中最关键的突破是同事 Gleb Smirnoff 与 Nginx 社区合作打造的“异步 sendfile”(Async Sendfile)。传统的 `sendfile` 系统调用虽然避免了内核态与用户态之间的数据来回拷贝,但通常会在从磁盘调入数据时产生阻塞。异步 sendfile 允许 Web 服务器发出 sendfile 请求后立即返回事件循环,由内核在后台完成磁盘 I/O 调入;一旦磁盘控制器产生中断通知数据就绪,磁盘中断完成处理程序(Interrupt Completion Handler)便会直接将数据推送到网络协议栈中。Drew Gallatin 高度评价这一特性:“and that allows us to avoid having thread pools or using async io or doing any any sort of thing like that and that's that one thing has is the fundamental optimization it's enabled everything else.” 紧随其后的是为了支撑 Kernel TLS(KTLS)而设计的非映射网络缓冲区(Unmapped Mbufs)。传统 FreeBSD 的 mbuf 指向单一数据对象,而 Unmapped Mbufs 类似于 Linux 的 `skb_frag` 结构,单个 mbuf 就能聚合引用多个物理页面(如 4 到 5 个 4KB 页面)并容纳头部和 TLS 签名信息。即便脱离 TLS 单独看,它也减少了套接字缓冲区遍历时的指针追逐(Pointer Chasing),大幅降低了 CPU 的缓存未命中(Cache Misses)。在此基础上,Kernel TLS 将 OpenSSL 在用户态进行的大规模数据加解密卸载到内核空间,消除了“从磁盘读到用户态加密再写入内核态”的双重上下文切换。更进一步,配合 Mellanox ConnectX-6 Dx(或更新型号)以及 Chelsio T6 网卡,KTLS 可以实现纯硬件网卡卸载(NIC TLS Offload):数据由存储直接送往网络,内核甚至全程无须触碰内存数据。 ```mermaid flowchart TD accTitle: 数据传输与 TLS 优化路径对比 accDescr: 对比传统用户态加密传输与 KTLS 配合网卡硬件卸载后的数据零拷贝路径。 subgraph Legacy["传统加密数据流(多次内存拷贝与切换)"] L_Disk["磁盘存储"] -->|"读取 I/O"| L_Kernel1["内核空间"] L_Kernel1 -->|"拷贝数据"| L_User["用户态 (OpenSSL 加密)"] L_User -->|"写入 Socket"| L_Kernel2["内核 TCP 协议栈"] L_Kernel2 -->|"网络发送"| L_NIC["物理网卡"] end subgraph Optimized["Netflix 异步 Sendfile + KTLS + 硬件卸载"] O_Disk["磁盘存储"] -->|"异步 Sendfile 读取"| O_Mbuf["Unmapped Mbuf (聚合多个物理页)"] O_Mbuf -->|"Direct DMA"| O_NIC["网卡硬件 (ConnectX-6 Dx / Chelsio T6)"] O_NIC -.->|"硬件自主完成 TLS 加密并推向光口"| O_Out["网络出口"] end ``` - **Async Sendfile**:解耦 Web 服务器与存储阻塞,无需复杂的用户态线程池或 AIO 框架,通过磁盘中断直连网络发送。 - **Unmapped Mbufs**:采用类似 Linux SKB 分片的方式持有跨页连续数据,避免构造复杂 mbuf 链表,削减 CPU 缓存未命中。 - **硬件 TLS 卸载**:支持 Mellanox ConnectX-6 Dx/更高版本及 Chelsio T6 网卡,从内核角度实现零 CPU 负载的纯硬件线速加密。 --- ### [16:48](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1008s) 传输控制与 I/O 调度革新:CAM、RACK/BBR、HBTS 与抗 DDoS 在存储与传输领域,Netflix 同样做出了核心模块改进。为了在提供高并发视频推流的同时从其他缓存服务器(OCA)拉取新内容进行本地填充,团队开发了 CAM I/O 调度器(CAM IO Scheduler,CAM 为 FreeBSD 存储子系统缩写)。它通过动态微调读写优先级和速率,有效防止了突发写入 I/O 拖垮关键的视频读取吞吐。在 TCP 层面,同事 Randall Stewart 将 Google 在 Linux 上研发的 BBR 算法移植到了 FreeBSD,并在此基础上从零设计了更贴合 Netflix 业务特性的 RACK TCP 协议栈;此外,团队还引入了高精度 TCP Pacing 系统(HBTS,Hardware/Kernel-based Pacing)。Drew 举例说明,若直接向家庭 Cable Modem 瞬间倾泻 100Gbps 的突发大块数据(如 64KB 或 128KB 块),而调制解调器缓冲区仅有 32KB,必然造成灾难性的丢包与重传。Pacing 机制平滑了数据发包节奏,彻底化解了因网络拥塞引发的重传风暴。 为了应对日益严重的分布式拒绝服务攻击(DDoS),Netflix 借鉴 Linux XTP/eBPF 的思想,研发了 Page Memory Pointer 挂钩(PMP Hooks)。当遭遇海量攻击流量时,网卡驱动在收到数据包的瞬间将指针直接交给防火墙判定,如果判定丢弃,驱动能以极低成本立即回收该硬件描述符和缓冲区。这完全绕开了传统流程中耗费高昂的步骤——分配新缓冲区、映射/解映射 DMA、向上传递协议栈并在多层解析中引发大量 Cache Misses。借助此项技术,节点能够在遭受每秒数千万包(Tens of millions of pps)的超大规模泛洪攻击时完成线速丢包,同时不让前台流媒体服务受到丝毫性能抖动。 - **CAM I/O 调度器**:平滑磁盘重写入对读取吞吐的冲击,保证后台缓存同步与前台推流平稳共存。 - **RACK 与 HBTS Pacing**:削峰填谷,消除毫秒级微突发引发的网络调制解调器溢出丢包。 - **PMP Hooks 抗 DDoS**:利用网卡驱动层指针钩子实现每秒数千万数据包的就地快速丢弃,无需遍历完整内核协议栈。 - **Kboot 引导方案**:由同事 Warner Losh 推动,将系统从 PPC64 逐步移植到 ARM64 和 amd64,实现在 Linux BIOS/无 UEFI 环境下直接通过 Linux `kexec` 引导进入 FreeBSD。 --- ### [20:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1220s) 推动生态与硬件协作:平衡吞吐极限与用户播放体验 除了纯代码提交,Netflix 还扮演着 FreeBSD 硬件生态强力推进者的角色。由于 Netflix 在全球采购体量巨大,众多硬件供应商急切希望向其供货。当厂商带着性能出众但仅有 Linux 或 Windows 驱动的新产品上门时,Netflix 会与该厂商深度协同,牵头为其寻找工程资源,协助将驱动开发并移植至 FreeBSD 并推向上游主线。许多现存于 FreeBSD 官方源码树中的重要设备驱动,正是依托这种商业与技术驱动力才得以问世。同时,Netflix 公司层面及其工程师个人也是 FreeBSD 基金会(FreeBSD Foundation)的重要长期捐助者。 谈到自己的工作职责,Drew Gallatin 强调性能调优绝非孤立地去刷高某个基准吞吐数字。从纯技术手段上看,要想换取更高的绝对带宽,最简单的方法其实是直接干掉 RACK TCP 协议栈和 TCP Pacing 系统以大幅减少计算与定时器开销,但这会导致客户端网络体验彻底崩溃。Drew Gallatin 直言:“My job is to improve performance um but it's not I can't just improve performance because the easiest thing I could do to improve performance would be to get rid of rack DCP and to get rid of the TCP pacing system but that would make our members quality of experience terrible.” 因此,所有的内核调优与性能攻坚,其最终红线都是保证 Netflix 最终用户能够丝滑播放,彻底减少甚至消灭加载缓冲画面的出现。 - **推动厂商上游化**:利用采购影响力促成硬件厂商投入工程资源,将闭源或 Linux 专有驱动重写并合并至 FreeBSD 主线。 - **开源基金会支持**:公司与团队成员个人长期为 FreeBSD Foundation 提供资金与技术双重支持。 - **QoE(用户体验质量)为先**:拒绝以牺牲发包质量、加剧丢包率为代价的盲目提速,性能架构全面服务于流畅度与减少卡顿缓冲。 ### [21:20](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1280s) 性能优化的取舍与 Netflix CDN 的吞吐量里程碑 Drew Gallatin 深入探讨了性能调优中面临的微妙权衡。以 TCP pacing 为例,如果关闭该特性,CPU 占用率确实会大幅下降,但这会导致播放端出现大量由于重新缓冲(rebuffering)而产生的缓冲菊花图标,极大地破坏用户体验。因此,他的核心目标是在相同的硬件上尽可能提升带宽,并通过更精简的机器提供同等流量来降低功耗。随后,他自豪地回顾了 Netflix 在 FreeBSD 平台上达成的一系列行业领先的性能纪录: ```mermaid flowchart LR accTitle: Netflix CDN 吞吐量演进历程 accDescr: 展示 Netflix CDN 从 2017 年的 100Gbps 到 2022 年 800Gbps 及未来低功耗 DPU 的演进路线 subgraph Timeline["性能演进路线"] direction LR Y2017["2017: 100 Gbps<br/>(Kernel TLS)"] Y2020["2020: 200+ Gbps<br/>(AMD Rome, ~240G)"] Y2021["2021: 400 Gbps<br/>(NIC TLS Offload)"] Y2022["2022: 800 Gbps<br/>(双路系统, 双倍 NIC/NVMe)"] DPU["未来: 100 Gbps @ <100W<br/>(NVIDIA BlueField DPU)"] Y2017 --> Y2020 --> Y2021 --> Y2022 -.-> DPU end ``` - **2017 年(100 Gbps)**:借助 kTLS(Kernel TLS),Netflix 打造了全球首台达到 100 Gbps 吞吐量的生产级 CDN 服务器。 - **2020 年(200 Gbps+)**:基于 AMD EPYC Rome 架构单路系统,实际达到了约 240 Gbps 的吞吐量。 - **2021 年(400 Gbps)**:在完全相同的 AMD Rome 硬件上,通过启用 NIC TLS 硬件卸载(将加解密工作从内核转移到网卡本身),并在软件生态就绪后全量上线,吞吐翻倍至 400 Gbps。 - **2022 年(800 Gbps)**:采用与前代类似的双路(dual-socket)系统,配备翻倍的网卡和 NVMe 存储,实现了单机 800 Gbps 的吞吐量。 - **极致能效探索(<100W 提供 100 Gbps)**:Drew 特别兴奋地展示了基于 NVIDIA BlueField DPU 的原型方案。该卡集成 16 核 ARM CPU、约 48GB DDR5 内存以及 100G 网卡,无需传统主机主板,只需插在 PCIe 扩展背板上并挂载 NVMe 盘即可工作。他评价这种低功耗的高效性时表示:“meaning that you know you for the power that you used to have for a light bulb you can serve 20 30,000 customers video”。目前实验室实测插座端功耗约 125 瓦,主要原因是搭配了冗余且低效的 1200W 电源(负载率太低导致转换效率极差),且为了快速拉取流量插了过多 NVMe 盘。待换装小功率高效电源并拔掉多余磁盘后,功耗有望压到 100 瓦以内。 --- ### [24:28](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1468s) 上游代码合并引发的 20% 性能衰退 Drew 切入演讲的核心案例:Netflix 团队在 2023 年 8 月进行了一次看似平常的 FreeBSD-current 上游代码合并。这次合并非常顺利,几乎没有遇到冲突(仅有两处细微合并冲突)。然而,当 Drew 按照惯例在专用的 100G 测试机上进行性能回归测试时,异常发生了。 在原本稳定的测试负载下,服务器向外发送约 92 Gbps 流量时,正常的 CPU 使用率应处于 40% 出头的低位。但合并后的内核在相同带宽下,CPU 使用率直接飙升了约 20%,不仅波动剧烈,且持续在 50% 以上徘徊。常规的性能诊断手段(如火焰图排查热点函数、分析内核锁竞争 lock contention 等)全部失效,从 Profiler 表面根本看不出 CPU 周期究竟被什么消耗了。面对毫无头绪的黑盒问题,团队只能诉诸代码二分查找(git bisect)。 --- ### [25:44](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1544s) 漫长痛苦的二分查找与“最知名 Commit” 由于 Netflix 是将 FreeBSD 代码作为其整个私有代码仓库的一个子树(subtree)来维护的,二分过程异常繁琐而折磨: 1. 先在上游 FreeBSD 仓库定位 git commit hash; 2. 再将该提交拉取并合入本地子树,手工反复解决中间状态的冲突; 3. 为每次选定的 commit 完整构建系统镜像,烧录到测试机,重启并压测收集指标。 每执行一次二分测试迭代就要耗费大约 4 个小时。经历漫长的排查后,最终定位到的提交让人大跌眼镜——它竟然是 Colin Percival(FreeBSD 知名 committer、TarSnap 备份服务创始人)不久前引起轰动的一次引导优化提交。 Colin 为了让 AWS 上的 FreeBSD 实例能以极速启动,深入剖析了内核引导耗时,发现内核引导时对初始化例程的排序居然使用了极其低效的“冒泡排序”(bubble sort),导致系统在开机阶段浪费了大量 CPU 周期。Colin 对此进行了优化,重构了排序算法,该改动不仅在社交媒体上引发热烈讨论,还登上了 Hacker News 首页。然而,正是这个备受好评的启动加速补丁,引发了 Netflix 生产环境 20% 的性能断崖。 --- ### [28:05](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1685s) 解密 SYSINIT 机制与排序稳定性隐患 Drew 详细剖析了 FreeBSD 内核的核心启动机制 `SYSINIT`。内核中几乎每个子系统都需要在引导时初始化自身,这是通过 `SYSINIT` 宏来注册的: ```mermaid flowchart TD accTitle: SYSINIT 机制与排序对比 accDescr: 解释内核链接期按字母排序,引导期按子系统和优先级二次排序,以及算法改变后导致平局元素倒序的现象 Linker["链接器 (Linker)<br/>输出符号按字母表升序排序"] --> BootSort["内核引导阶段排序<br/>依据 79 个子系统顺序 + 8 个级别优先级"] subgraph OldBehavior["原算法 (选择排序 Selection Sort)"] OldTie["相同子系统 & 相同优先级<br/>(Tie 平局)"] --> OldOrder["保持字母表正序输出<br/>(A -> B)"] end subgraph NewBehavior["新算法 (优化排序)"] NewTie["相同子系统 & 相同优先级<br/>(Tie 平局)"] --> NewOrder["变成字母表逆序输出<br/>(B -> A)"] end BootSort --> OldBehavior BootSort --> NewBehavior ``` 链接器在编译内核时,会将所有的 `SYSINIT` 按照符号名称放入一个按字母顺序排列的列表中。但真正的硬件与子系统初始化必须遵循特定逻辑,因此 FreeBSD 将其划分为 79 个子系统,并在每个子系统内定义了约 8 个不同的执行级别(如最高优先级、普通、最低优先级等)。在引导阶段,内核会对这些项目执行排序。 理论上,具有完全相同子系统级别和相同排序提示(ordering hint)的两个 `SYSINIT` 属于“平局(tie)”,它们本应具备独立性,能以任意顺序执行。然而代码演进揭示了残酷的现实: - 原有的排序算法其实不是冒泡排序,而是**选择排序(selection sort)**;在处理并列项时,它恰好保留了链接器最初生成的**字母正序**。 - Colin 的新排序算法改变了平局的处理行为,使得所有优先级并列的项目全部变成了**字母逆序**。 - Drew 与 Colin 通过 `tslog`(Colin 编写的引导耗时跟踪工具)独立证实了这一执行序列的颠倒。 Drew 在本地测试时,直接将新排序算法的输出顺序翻转过来,原本飙升的 20% CPU 占用立刻恢复正常。然而,这只是治标,“为什么仅仅因为引导初始化项逆序,就会导致持续的 CPU 性能暴跌?”这个问题依然悬而未决。 --- ### [29:50](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1790s) 顺藤摸瓜:驱动竞争与频率控制失效 为了揪出深藏在内核里的真正元凶,Drew 修改了内核引导代码,通过引导参数(boot loader arguments)来人为控制子系统初始化的排列组合。他先按子系统范围进行二分,将系统一半的子系统初始化逆序,另一半保持正序;在圈定目标子系统是**驱动子系统(driver subsystem)**之后,又对该子系统内部的所有驱动加载顺序进行了第二轮二分查找。 最终,谜底揭晓:问题的核心在于 Intel Xeon 处理器上的 **CPU 频率控制驱动(CPU frequency control drivers)**。 在 FreeBSD 完善的架构设计中,驱动探测本应使用“探测评分(probe score)”机制:每个驱动探针在检测硬件后返回匹配度分值(比如“我完全是为此硬件设计的,返回 100% 绝对匹配”或“我只是通用兜底驱动,若有更匹配的硬件驱动请优先选用它”)。然而,当时适配 Intel 平台的两个 CPU 变频驱动均没有遵循这一打分规范,两者在探针阶段都直接返回简单的成功标志,表明自己能够接管该硬件。 在评分相同的情况下,FreeBSD 会直接采用“先到先得(first come, first served)”的原则。当启动项保持原本的字母正序时,优秀的那个变频驱动率先注册成功;而当引导排序变成字母逆序后,较差且不兼容的驱动抢先上位夺取了 CPU 频率控制权,导致 CPU 无法工作在预期的性能状态下,最终引发了高达 20% 的运行时 CPU 负载激增。 - `SYSINIT` 结构:包含 79 个子系统,每个子系统包含约 8 个内部优先级级别。 - 问题核心:驱动探针未规范使用探测优先级(probe score),导致并列时完全依赖引导初始化的注册次序。 - 排查技巧:通过内核参数动态干预引导阶段初始化队列,免去了重新编译和制作镜像的繁琐周期。 ### [31:40](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1900s) 驱动排序反转引发的“降速陷阱” Drew Gallatin 详细拆解了导致 20% 性能回退的根本机制。在之前的驱动挂载顺序中,依照字母排序,较新的现代驱动 `est`(Enhanced SpeedStep)会优先挂载(attach),而老旧的奔腾4温控驱动 `p4tcc`(Pentium 4 Thermal Control Circuit)排在第二位,由于位置被占而挂载失败。然而,当 Colin Percival 提交的链接器集合排序改动将顺序反转后,老旧且落后得多的驱动抢先挂载成功;当正确的现代驱动随后赶到时,发现设备已被占用,便直接放弃挂载。这一机制阴差阳错地凭着字母排序正常工作了近十年。为此,Drew 的同事 Warner Losh 正在为这些驱动添加恰当的探测评分(probe scoring)机制,以确保未来能通过明确的优先级来打破平局。 ```mermaid flowchart TD accTitle: CPU Driver Attachment Order Flip accDescr: 驱动加载顺序改变导致现代EST驱动被老旧P4TCC驱动排挤并引发CPU降频 subgraph Before["之前:字母正序(偶然正常工作近十年)"] A1["est 驱动率先挂载"] --> B1["成功接管 CPU 频率调节"] C1["p4tcc 驱动随后到达"] --> D1["设备已被占用,挂载失败"] end subgraph After["之后:排序反转(引入性能回退)"] A2["p4tcc 驱动率先挂载"] --> B2["接管失败/回退至假频率与未知功耗"] C2["est 驱动随后到达"] --> D2["检测到已被占用,直接跳过挂载"] end B2 --> E["CPU 实质以低频运行,内核误以为正常"] ``` 更令 Drew 懊恼的是,排查线索其实早就摆在眼前。FreeBSD 提供了展示支持频率等信息的 `sysctl` 节点;当 `p4tcc` 挂载时,该节点输出的全是乱码般的无效数据,其中列出的频率根本不受该处理器支持,斜杠后的预估功耗数字也表明系统对实际能耗一无所知。相反,`est` 驱动能准确读取所有真实的物理频率以及对应的能耗档位。这意味着实际代码并没有出现什么效率变差的真正回退,纯粹是操作系统内核在毫无察觉的情况下,让处理器在远低于应有主频的降速状态下运行。 - 缺陷机制:抢占 CPU 变频控制权的驱动由现代的 `est` 沦为老旧的 `p4tcc`。 - 观测特征:`sysctl` 频率节点充斥着不被 CPU 支持的荒谬频率数值和完全失准的功耗读数。 - 最终根因:系统并没有变慢的代码劣化,仅仅是处理器运行在低频状态而内核浑然不知。 - 长期修复方案:由 Warner Losh 为驱动探针引入明确的评分权重机制,替代脆弱的符号链接排序。 ### [33:16](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=1996s) 上游社区即时协作与快速二分的价值 在查明问题与提交记录后,Drew 在 FreeBSD 内部 IRC 聊天室中联系了提交者 Colin Percival。Colin 在几分钟内就作出了回应,两人各自独立验证了排序规则确实发生反转。得益于改动才过去几周,Colin 对上下文记忆犹新且非常乐意协助,当天便提交了修复审查,次日便合入 FreeBSD-current 主干;Drew 随后在几分钟内便将其挑选(cherry-pick)回 Netflix 的合并分支。Drew 感慨道,这就是开源社区健康互动的典范。 Drew 对比了跟进最新开发分支与长期停留在稳定分支的巨大差异。Netflix 的服务器级硬件规模让他们成了最先捕获该性能回退的团队,否则许多用户可能只会归咎于“新版 FreeBSD 变慢了”却找不到由头;随后他们还发现该改动在 AMD 温度驱动中引发了一起内核崩溃(kernel crash)。从排查成本来看,Git 二分查找(git bisect)虽然呈对数复杂度,但每一步测试都需要近 4 个小时;二分三周的代码改动已经极其折磨,如果是累积了三年的代码库,那样的排查足以让人发疯。更关键的是开发者的心理防御机制,如果去质问别人一处存在了三年的代码,对方很可能会下意识反驳:“代码放那三年都没人抱怨,肯定是你自己搞错了”。 > Drew Gallatin: “If it was one of my changes I would definitely be like what are you talking about I did that change three years ago I barely even remember why I did it like why are you talking to me about it now like it's been nobody's complained about it obviously you're doing something wrong just go away.” - 响应与合入时效:IRC 沟通后数分钟确认,当天提交评审,次日合入 upstream current,Netflix 数分钟内完成拣选。 - 附带关联缺陷:除 CPU 降频外,该排序改动还诱发了 AMD 温度驱动相关的内核崩溃问题。 - 二分查找成本:单次测试验证需耗时约 4 小时,追溯 3 周跨度尚能承受,追溯 3 年跨度在工程上不可想象。 ### [36:06](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2166s) 问答环节:机群分批上线与惨痛的网卡固件事故 演讲进入提问环节后,现场观众询问 Netflix 将新系统升级覆盖到全部服务器需要多长时间。Drew 解释称,Netflix 的机群规模在数万台级别,升级工作由专门的运维团队负责。为了防止测试遗漏的缺陷酿成全局灾难,全量服务器采取波浪式分批上线(upgraded in waves),整个周期大致需要一周左右。在被追问驱动排序修复后的表现时,Drew 证实机器性能恢复如初,完全达到了预期中 40% 出头的吞吐利用率基准。 谈及渐进式升级的必要性,Drew 分享了团队遭遇过“最糟糕的 Bug”。大约五六年前,他们采纳了一版新的网卡固件(firmware blob)。由于监控系统会对光模块的光功率和温度进行极高频的遥测,重度压榨了收发器上的 I2C($I^2C$)总线。该固件潜藏着一个几百万至上千万分之一概率的读取超时缺陷,一旦触发就会直接重置网卡并导致其彻底离线。这一问题在灰度推向全网一天后浮现,约千分之一的机器失联。更致命的是,Netflix 在互联网交换中心(IXP)的机器配备有 IPMI 带外管理接口,但在部署于 ISP 数据中心内的机柜则没有 IPMI 权限。幸运的是问题在波及 ISP 机房前被截获并完成了重启挽回。经此一役,Netflix 对上游固件更新变得极为谨慎,宁愿自行保留一套经受住考验的已知稳定固件,直接忽略上游的驱动固件捆绑。 > Drew Gallatin: “And that was and that was like the worst that was the worst bug that we ever had because when a machine's not responsive it's really hard to deal with especially if it's at a if it's at a site where we don't have IPMI access to it.” - 机群规模与发布周期:数万台规模服务器,采用分批滚动推送,全量升级大约持续一周。 - 致命固件缺陷机制:高频 I2C 读取引发千万分之一概率超时,导致 NIC 硬件直接死锁重置。 - 硬件运维边界:IXP 节点具备带外 IPMI 管理能力,ISP 嵌入式节点不具备带外管理控制。 - 固件管理策略变更:核心硬件固件与上游解耦,全面冻结并使用内部验证过的专用稳定固件。 ### [38:55](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2335s) 问答环节:为何是 FreeBSD 而非 Linux 有观众提出了经典的平台选型问题:“为什么选择 FreeBSD 而不是 Linux 或其他发行版?”Drew 幽默地回应称,这是一个极易引发阵营论战(flame war)的问题,管理层也曾叮嘱他不要卷入这类争议。但他明确强调,工程决策绝非盲目或出于宗教般的偏执——如果在该特定 CDN 应用场景下 FreeBSD 无法提供更出色的性能与表现,团队绝不会固执地坚持使用它。 为了打消大家的阵营偏见,Drew 列举了自己的职业履历:他曾效力于研发跨平台 Unix 设备驱动的公司,深入编写过 Linux、Solaris、FreeBSD、macOS 以及 VMware ESX 等多种复杂操作系统的底层驱动,在供职于 Google 期间也是核心的 Linux 开发者。因此他不带有任何操作系统信仰,当前的选择单纯是因为 FreeBSD 恰好是解决当下工程目标最锋利的工具。他推测 Netflix 最初做出技术选型时或许考虑了软件许可证(BSD License vs GPL)的因素,但就目前的生产实践而言,驱动团队持续推进的理由唯有切实的工程表现。随后提问环节在主持人的致谢与全场掌声中落下帷幕。 > Drew Gallatin: “We're not stupid and we wouldn't run we wouldn't be running FreeBSD if it didn't work better in this application for us like we're not religious I'm not religious.” - 跨平台工程履历:涵盖 Linux、Solaris、FreeBSD、macOS、VMware ESX,包括在 Google 维护 Linux 的技术经历。 - 选型基石:脱离操作系统意识形态,纯粹以在目标流媒体 CDN 工作负载下的实际吞吐表现为转移。 - 历史成因推测:早期架构选型可能部分受开源许可协议考量驱动,而后期维护完全由工程性能优势主导。 ## Notable quotes > [38:55](https://www.youtube.com/watch?v=q4TZxj-Dq7s&t=2335s) We're not stupid and we wouldn't run we wouldn't be running FreeBSD if it didn't work better in this application for us like we're not religious I'm not religious. — Drew Gallatin ## Mentioned Drew Gallatin, Colin Percival, Gleb Smirnoff, Randall Stewart, Warner Losh, Linus Torvalds, Netflix, FreeBSD, FreeBSD Foundation, Open Connect, NGINX, ZFS, UFS, Linux, NetBSD, 386BSD, Kernel TLS, Intel Xeon, AMD EPYC Rome, NVIDIA BlueField DPU, Mellanox ConnectX-6 Dx, Chelsio T6, Hacker News, Jenkins ## Video description We run FreeBSD-current on our CDN at Netflix. By running FreeBSD-current, we can find and fix bugs far more effectively than by running an older FreeBSD-stable branch. This talk describes our team, how we track FreeBSD-current, our contributions to FreeBSD, and some of the performance milestones we've hit. It will end with a description of a finding and fixing very interesting bug in upstream FreeBSD that caused a 20% performance regression. #OpenFest 2023 I Share Therefore I Am Website: https://openfest.org/ Facebook: https://www.facebook.com/OpenFestBulgaria Linkedin: https://linkedin.com/company/openfest-bulgaria/ (X) Twitter: https://twitter.com/OpenFestBG Instagram: https://www.instagram.com/OpenFestBulgaria Mastodon: https://mastodon.social/@openfest [Source](https://www.youtube.com/watch?v=q4TZxj-Dq7s)

Source quotes

[38:55] Drew Gallatin: We're not stupid and we wouldn't run we wouldn't be running FreeBSD if it didn't work better in this application for us like we're not religious I'm not religious.

Source quotes

[38:40] Drew Gallatin: We're not stupid and we wouldn't be running FreeBSD if it didn't work better in this application for us [21:20] Drew Gallatin: if I got rid of the TCP pacing, well CPU would go way down, but our members would see a lot more of the little spinning wheels for rebuffering.

Original transcript

[0:18] can you oh great amazing um hello again [0:22] we are ready to start to continue with [0:24] our next talk um I'm very happy and [0:27] excited uh uh to introduce you drew [0:31] Gallatin who is here on the stage with [0:34] me at the moment uh Drew has been [0:36] working for Netflix uh for eight eight [0:40] years maybe something like that yes and [0:42] uh his specialty is free BSD Cur [0:45] optimizations and he's been uh [0:47] committing to the FreeBSD for more than [0:50] 25 years so let's uh give uh drew a [0:56] round of applauses and welcome him on [0:58] the stage and let's hear more about the [1:00] Magical Mystery [1:07] merch hey so I'm here to talk a little [1:10] bit about first about how we use FreeBSD [1:13] at Netflix and then to talk about why we [1:17] run FreeBSD current and to give a nice [1:19] little case study which I call the [1:20] Magical Mystery merge which kind of [1:22] exemplifies why it's good to run [1:25] current so I work on um our CDN and a [1:30] CDN is basically a Content distribution [1:32] Network a lot of companies use that to [1:34] distribute you know operating system [1:37] updates or video games or movies like to [1:39] their customers all over the [1:41] world uh we call our CDN open connect [1:45] and we call our CDN servers open connect [1:48] appliances um and we call them [1:50] appliances mostly because in a lot of [1:53] ways there are a little bit they have a [1:54] little bit more in common with like your [1:55] home router than they do with the server [1:57] at your office and what I mean by that [1:59] is we we have like an a partition and [2:02] you know we re reimage them every time [2:04] we update them so we image the B side [2:08] and then if that fails that falls back [2:10] to the aside the software is completely [2:12] identical on every single machine [2:14] there's no package and some machine [2:16] that's not on other [2:18] machines this is an example of uh one of [2:21] our ocas that can serve 400 gigabits a [2:24] second uh we currently have three [2:27] different types of ocas we have a all [2:30] flash OCA meaning all nvme or the older [2:33] ones are all SATA ssds they serve the [2:36] very most popular content and those are [2:38] mostly located in our uh data in in our [2:41] data centers at internet interchange [2:43] points where the internet comes together [2:45] uh we also have storage ocas which hold [2:48] you know hundreds of terabytes of video [2:51] assets and that that could be you know [2:53] anything from a really unpopular title [2:56] that you know somebody only watches once [2:57] a week to even the very most popular [3:00] things and we also have what we call a [3:02] global OCA which is given to uh smaller [3:06] isps uh to help them offload um the [3:10] traffic that's coming to their Network [3:11] so for example if you're watching a [3:13] movie it's coming from inside your IPS [3:15] Network and their Uplink isn't affected [3:18] by that [3:20] traffic so a little bit about the ocas [3:23] um we run FreeBSD current and I'll get [3:26] into why we run current and one of the [3:29] most fre questions I could asked is do [3:30] you run ZFS and yes we do run ZFS but we [3:34] only run it for root we don't run it for [3:36] um our content partitions and that's [3:39] because ZFS has its own cache called The [3:42] Arc or the Adaptive replacement cache [3:45] which is separate from the kernel page [3:46] cache which means in order to serve [3:48] anything out of ZFS things need to be [3:51] copied from The Arc to the page cach [3:54] which is inefficient so we run ufs uh [3:57] for all of our content partitions uh we [4:00] run ngex as our web server and the other [4:04] thing I wanted to mention about our file [4:06] systems and stuff is that unlike a lot [4:08] of CDN we just let drives fail in place [4:11] we don't run any raid there's no there's [4:13] no redundancy except for the the root [4:16] partitions um but for the content [4:18] partitions we just let drives fail in [4:20] place it's a lot easier to just let it [4:22] fail in place than to try to get isps to [4:24] replace a drive or to send technicians [4:26] to to Data Centers and the machines are [4:29] the mostly have so much storage that [4:31] they lose one or two drives they're [4:32] still very useful as they [4:35] are so our our workload is basically [4:39] serving static files um everything is [4:42] pre uh encoded uh before it even hits [4:46] our CDN so we have you know if you're [4:49] watching a video um there'll be a [4:51] different codec for maybe what's on your [4:53] phone versus what's on your smart TV [4:55] versus what's on your computer and [4:56] there'll be all the different bit rates [4:58] so like one [5:00] one particular TV show or movie could [5:02] have dozens of different downloadables [5:04] for [5:04] it uh and we do this because video [5:07] quality is like of the utmost importance [5:09] and we spend a lot of time and effort on [5:12] making each encoding as good as it can [5:13] possibly be and so the nice thing is [5:16] that having everything static simplifies [5:18] our workload since there's no compute [5:20] involved on the CDN [5:23] server and so a little bit about FreeBSD [5:26] I think most people here are familiar [5:27] with Linux um FreeBSD got it start [5:30] around the same time that Linux did but [5:32] in a much different way whereas Linux [5:34] was written from scratch FreeBSD is [5:36] directly descended from the bsds that [5:39] were the basis of you know sunos and and [5:41] things like that in in the [5:42] 80s um FreeBSD came out of 386 BSD which [5:46] was a port of the old the old BSD to x86 [5:50] you know 386 boxes that sort of that 386 [5:56] kind of fell into a little bit of [5:57] disrepair and there was a patch kit that [5:59] was maintained and there were two groups [6:01] of people that were maintaining the [6:03] patch kit that sort of forked net BSD [6:06] came out at the same roughly the same [6:08] time they focused on uh compatibility [6:10] and correctness and running on as many [6:12] architectures as they could whereas [6:14] FreeBSD focused on just performance on [6:17] at the time x86 32bit our first uh [6:21] 64-bit Port was in the late 90s that's [6:23] how I actually got my started as a [6:25] FreeBSD committer I worked on that on [6:27] that Port um but FreeBSD likes to [6:30] basically really support the current [6:33] high performance architectures and so [6:35] once uh an architecture is sunsetted by [6:37] the vendor we Sunset it as well so the [6:40] alpha Port was the first Port we ever [6:41] retired because you know Alpha sadly [6:44] Alpha died [6:46] um so FreeBSD is a little bit different [6:49] than a Linux drro because in Linux [6:51] everything is packaged in FreeBSD we [6:53] still have this Legacy thing where we [6:55] have the kernel and all of the basic [6:58] utilities you know like the you would [6:59] expect on a shell like the actual shell [7:01] itself like LS move copy that kind of [7:04] thing the compilers all that stuff is [7:06] unpackaged and belongs in the root file [7:09] system and we also package we also give [7:13] uh we also believe in packaging [7:15] thirdparty [7:17] software the things like uh the Firefox [7:19] web browser or the engine X web server [7:22] or you know things like that come come [7:23] in packages and so when you install [7:25] FreeBSD you get all that plus all the [7:27] source and the Man pages and [7:31] documentation at Netflix we have our own [7:34] strip down distribution that we run on [7:35] our ocas and that you know obviously [7:38] doesn't include compilers or [7:40] documentation or most packages just [7:43] because we don't need those [7:46] things and so the team I work on in at [7:49] Netflix is called the OCA Dev team and [7:51] our responsibility is to maintain the [7:53] software that runs on the ocas uh most [7:56] of us are FreeBSD committers or [7:58] contributors um there's roughly 10 of us [8:02] and uh it's a great place to work and [8:05] it's the best job I've ever [8:06] [Music] [8:07] had so I want to talk a little bit about [8:10] how we do FreeBSD uh development at [8:12] Netflix when we first started off we [8:15] made the choice that everybody makes [8:16] which was to track a stable branch and [8:18] to to back up a little bit the way [8:21] FreeBSD works is in some ways it's if [8:23] you're familiar with Linux it's similar [8:25] to Linux um there's what we call FreeBSD [8:28] current which in many ways is Sim [8:30] similar to like the Lin tree uh where [8:33] everything goes in there first [8:35] um and then there are stable branches [8:38] which are what in Linux most people call [8:40] long-term support or LTS branches and so [8:44] in FreeBSD there's a new release [8:46] supposedly every two years it really [8:47] works out in practice to be every three [8:49] or four and so every time there's a new [8:51] release a new long-term support or [8:53] stable branch is created and so what we [8:55] used to do is we used to track um the [8:58] latest a stable branch and then every [9:01] few weeks we would merge all the [9:02] security fixes and Bug fixes that made [9:04] it into the stable [9:05] branch and we would then you know make [9:08] an internal release that would go out to [9:09] our ocas and that worked really well for [9:13] the period we were doing that but what [9:15] was terrible was when we move from one [9:17] stable Branch to another and that would [9:19] take sometimes in the best case the [9:22] weeks most most times it would take [9:24] months you know up to six months because [9:26] you could encounter a problem uh you [9:28] know either in code that we never [9:31] managed to Upstream uh being compatible [9:34] with the new interfaces in the new in [9:36] the new version or there could be uh [9:38] some kind of regression introduced [9:39] Upstream in the new version that was [9:42] hard to track down and so these these [9:44] merges every time we updated between [9:47] stable branches were just awful and when [9:50] we ran stable it was also very hard for [9:52] us to collaborate with Upstream because [9:55] the stable branches you know the apis [9:57] might be different like some function [9:59] may take three arguments in stable and [10:00] four arguments in current or something [10:02] like that and so if we wanted to [10:04] contribute some change we made we would [10:06] first have to Port it to current then [10:09] somehow test it because we weren't [10:11] running running current on our machines [10:13] and then submitt it for review get it [10:15] accepted and then it would finally be [10:17] there when we went and moved to the next [10:19] branch and so there's very little [10:20] motivation to do it which meant we were [10:22] keeping a lot of things back which made [10:25] each successive merge harder because we [10:27] run into more and more conflicts the [10:28] more and more stuff we had so we could [10:30] see that we we were kind of building up [10:32] a technical debt by doing this and so [10:35] about five six years ago we we decided [10:37] what we were doing was silly and what we [10:39] should do really is [10:40] to uh track FreeBSD current and that [10:44] sounds crazy in the face of it because [10:46] that's where everybody pushes all their [10:48] stuff and unlike unlike Linux there's no [10:50] subsystem maintainers in FreeBSD when [10:53] you have a commit bit you're allowed to [10:55] commit uh you know whatever you want [10:57] you're encouraged to get reviews but [10:58] it's it's you know treated with freedom [11:00] and responsibility but at any rate [11:02] current is sometimes somewhat unstable [11:05] and so running current sounds crazy but [11:07] it's actually the best thing in the [11:08] world because when we run current we do [11:11] the same every 3 four weeks uh merge [11:14] cycle [11:16] where we pull in the stuff from upstream [11:19] and when we do that um we catch things [11:22] really fast if there's some regression [11:24] we catch it right away uh there's no you [11:27] know 2 three year delay between somebody [11:29] committing something and US finding it's [11:32] a problem and it also allows us to [11:35] Upstream things much more quickly [11:37] because we no longer have to Port it to [11:39] basically a different version of the [11:40] operating system so it allows us to [11:42] collaborate with Upstream developers and [11:45] get our changes in to FreeBSD quickly [11:47] and over the years the amount of things [11:49] we've held back has decreased and [11:50] decreased and [11:53] decreased So speaking of upstreaming [11:56] code to FreeBSD basically since we run [12:00] current our tree is almost identical to [12:02] the up Upstream previous D Tree and so [12:05] if we want to make a small feature or if [12:07] we want to make this small bug fix what [12:09] we often do is rather than doing it an [12:11] archery we actually do it in the actual [12:13] FreeBSD tree itself get it reviewed and [12:15] committed and then that will just [12:18] naturally come back in our every 3-week [12:19] merge cycle uh so that greatly reduces [12:23] the amount of technical debt we [12:25] accumulate by keeping our own patches um [12:28] and if there's something critical like a [12:29] security fix or a bug fix for you know a [12:31] crashing issue or something we'll cherry [12:33] pick it immediately and rather than [12:34] waiting for the merge cycle but for [12:37] larger changes like when we did Colonel [12:39] TLS that was a very large very invasive [12:41] change and so we kept that to ourselves [12:43] for close to 5 years uh not because we [12:46] were trying to be secretive proprietary [12:49] but just because we wanted to get it in [12:50] the form that it actually needed to be [12:52] in to be useful upstream and not just to [12:56] us so we do testing uh you know every [12:59] time we push to a branch uh Jenkins job [13:02] gets gets kicked off uh at Netflix we [13:05] run on both amd64 which Microsoft also [13:08] calls it amd64 everybody else calls it [13:10] x86 64 and arm 64 and so we run a small [13:16] regression Suite on that and then every [13:19] night or close to every night we run uh [13:22] what we call a smoke test where we run [13:24] with all debugging enabl on the kernels [13:26] meaning like memory corruption checking [13:28] use after free [13:29] checking uh you know lock reversal lock [13:32] lock ordering checking all the all the [13:34] checking we can check is running uh [13:37] close to every night on a small cluster [13:38] of machines looking for any bugs that [13:41] we've introduced and then when we when [13:43] we do release testing we running on a [13:45] slightly wider set of machines at uh you [13:49] know with all the all the bug checks off [13:51] just looking for any performance [13:52] differences or any other regressions [13:54] that we can [13:56] find so we've contributed did a lot to [13:59] FreeBSD over the years which I'm very [14:00] proud of probably the most important [14:03] like most fundamental thing we've we've [14:04] contributed is something we call async s [14:07] file that was done by my colleague GB [14:09] schof um in collaboration with engin X [14:13] and the the gist of that is that when [14:16] send file is a system call which [14:18] basically says if you have a file here [14:21] and a socket there like you don't have [14:23] to read from the file into user space [14:26] and then push things back into kernel it [14:29] tells the kernel take data from this [14:30] file and put it on this socket and the [14:33] problem with sun file in most operating [14:34] systems is that it blocks because you [14:36] have to wait for the stuff to come in [14:37] from disk and so asynchronous send file [14:40] basically allows the web server to just [14:43] say do this send file and then return [14:45] immediately and then the operating [14:47] system in the background brings the data [14:49] in and then the the interrupt completion [14:51] Handler from the for the disc drive then [14:54] pushes things out to the network and [14:57] that allows us to avoid having thread [14:58] pool tools or using async iio or doing [15:01] any any any sort of thing like that and [15:03] that's that one thing has is the [15:05] fundamental optimization it's enabled [15:07] everything else um something else we [15:11] do is what we call Un unmapped uffs and [15:14] that was done to prepare for colel TLS [15:17] basically it's uffs are the fundamental [15:19] uh network uh buffer and [15:22] FreeBSD and unmapped uffs essentially [15:27] use it's very much like Linux SKB frag [15:29] structure where rather than pointing to [15:32] one data object they can point to many [15:33] data objects and so one single uff can [15:36] carry an entire TLS record with you know [15:38] four 4K Pages or five 4K pages and [15:42] header and uh TLS signature information [15:44] and that is just by itself even without [15:47] TLS is a big optimization because it [15:49] saves a lot of cach Misses when you're [15:51] Point doing pointer chasing and things [15:52] like socket [15:53] buffers uh there's colel TLS uh which [15:56] basically moves bulk data encryption [15:58] from open SSL in user space to the [16:01] kernel and the reason why that's Val [16:03] valuable is it again avoids lot doing [16:05] lots of boundary Crossing because you [16:07] without kernel TLS you need to read data [16:09] from the file into your user space [16:11] application do the crypto then push it [16:13] back into the kernel this allows you to [16:15] avoid that detour do the crypto in the [16:17] kernel and have things go right out and [16:19] even better if you have a network card [16:21] like a melanox connectx uh 6dx or or [16:24] newer or chelot T6 then you can do [16:27] kernel TLS [16:29] um actually Nick TLS offload which lets [16:32] the Nick do itself do the encryption [16:34] which so it makes it essentially from [16:35] the Colonel's perspective like there's [16:37] no crypto at all stuff just comes in [16:39] from the in from Storage goes out in the [16:41] network colel never even touches the [16:43] memory that's why the uffs are [16:46] unmapped we've also contributed [16:48] something we call the cam IO scheduler [16:50] uh cam is a FreeBSD acronym for its [16:54] storage system and the idea behind that [16:56] is that we like to U be able to fill [17:00] from other ocas content that's needed on [17:02] at a particular site at the same time [17:04] we're serving traffic and we found that [17:06] a lot of storage devices if you're doing [17:08] a lot of Rights uh the read performance [17:10] suffers and so cam the io scheduler sort [17:14] of mitigates the speed at which wrs [17:15] happen or reads happen in order to keep [17:18] everything nice and smooth uh We've [17:21] contributed the rack and bbrr TCP Stacks [17:23] you may have heard of bbrr it's the it [17:26] was done by Google uh initially in Linux [17:28] and reported to FreeBSD by my colleague [17:29] Randle Stewart it's also the congestion [17:32] control algorithm that's used in quick [17:34] um we actually don't use it much uh we [17:36] used something called rack which is [17:38] similar in spirit and that's was [17:41] completely written uh at Netflix by [17:42] Randall [17:43] Stewart uh We've also contributed the [17:45] TCP pacing system uh [17:48] hbts um and the point of that is that if [17:52] we wanted to send data as fast as [17:55] possible I could send data at 100 gbits [17:57] a second to your cable modem in you know [18:00] a 64k or 128k chunk and your cable modem [18:03] buffer might only be 32k long and so you [18:06] would drop most of it and we would end [18:07] up having lots of TCP retransmits [18:09] because we'd just be shoving data at you [18:11] and you and it would be dropped all the [18:13] time so the pasting system basically [18:14] allows us to uh again deliver data more [18:18] smoothly and avoid uh packet loss uh [18:21] we've given we've also contributed some [18:23] performance enhancements for Numa I've [18:24] given a lecture about that you can find [18:26] it on my page at freebsd.org [18:30] uh we contributed something called pill [18:31] memory pointer hooks which to be honest [18:34] was inspired by linux's xtp and the idea [18:37] behind that is that if we're under a [18:39] denial service attack and we need to [18:41] drop a lot of traffic we want to do it [18:43] as efficiently as possible and what this [18:45] does is this allows the uh this allows [18:47] the the firewall to basically get a [18:50] pointer from the device driver to the [18:52] packet that was just received and the [18:54] firewall can essentially say you know [18:56] hey that's good go go to normal way or [18:59] drop it immediately and and by doing [19:01] that the network driver can simply [19:04] recycle that buffer pretty much for free [19:07] whereas if we went through the normal [19:08] path to the firewall the driver would [19:10] have to you know allocate a new buffer [19:12] map it for dma the fire unmap the old [19:15] unmap the old buffer for dma pass the [19:17] buffer up the chain of the network Jack [19:19] where everybody's looking at it and [19:20] taking cash misses and then finally the [19:23] with the firewall said no we can't have [19:25] this packet then the firewall would have [19:27] to free the packet and so with this we [19:29] can drop tens of millions of packets per [19:32] second and still serve without any [19:33] impact to our [19:35] serving uh we've done many too many [19:37] scalability fixes uh to to mention [19:39] probably more than I can [19:40] remember and most recently uh my [19:43] colleague Warner L pred this thing [19:45] called K booot which started off on [19:47] power PC 64 to arm and to arm 64 and [19:51] amd64 and it's a way to run FreeBSD [19:54] directly from Linux so when you know in [19:56] Linux you can K exac another l Linux [19:58] kernel or some linuxes use it to to do [20:00] crash dumps well we we use this to boot [20:03] on systems that use Linux Linux bias [20:06] where there's no UEFI so we can K EXA [20:09] directly from from Linux into [20:13] FreeBSD [20:15] oops so whoops so [20:20] um we also uh contribute in other ways [20:24] than code we have great relationships [20:26] with a lot of Hardware vendors like [20:28] people really like us and they want to [20:29] sell us stuff and so if somebody comes [20:31] to us with a product that we are really [20:33] interested in that only has a Linux [20:35] drive or only has a Windows driver you [20:37] know we we collaborate with them and [20:39] help them to you know find resources to [20:41] put their driver to FreeBSD and to [20:44] Upstream it and there's I mean I can't [20:46] mention which but there's a lot of [20:48] drivers in FreeBSD that wouldn't exist [20:49] if it wasn't for this and we also uh [20:53] Netflix as a company and also us [20:55] personally most of us contribute to the [20:57] previous D Foundation [21:00] so my job is to improve performance um [21:04] but it's not I can't just improve [21:05] performance because the easiest thing I [21:06] could do to improve performance would be [21:08] to get rid of rack DCP and to get rid of [21:10] the TCP pacing system but that would [21:12] make our members quality of experience [21:14] terrible if one of the things we really [21:16] pride ourselves on at Netflix is [21:19] reducing the number of times you see the [21:20] little Spinning Wheel where things are [21:22] rebuffering and so like if I got rid of [21:24] the tcv pacing well CPU would go way [21:28] down but our members would see a lot [21:30] more of the little spinning wheels for [21:32] rebuffering and so it's not so it's [21:36] a it's a fine line to walk on on how we [21:39] can improve performance but my goal is [21:42] basically to improve bandwidth uh for on [21:44] the same hardware and to also reduce [21:46] power consumption by being able to [21:48] deliver the same amount of traffic with [21:50] a smaller [21:52] machine and here are some things that [21:54] I'm particularly proud of um in 2017 we [21:57] had the first what I believe is the [21:58] first 100 gabit per second like [22:01] production CDN server in the [22:04] world and that was due to Colonel TLS um [22:08] in 2020 we had the first 200 gbit per [22:11] second uh CDN server that's an AMD Rome [22:14] based system and it was more like 240 [22:18] gigabits um in 2021 those that same [22:21] Hardware is was now now became capable [22:23] of doing 400 gigabits because we were we [22:26] enabled um the Nick TLS offload so we [22:29] moved the crypto from the kernel down to [22:32] the nick uh and there were some sof we [22:34] had those machines deployed for a while [22:35] and there was some software support that [22:37] needed to be done before we could [22:38] actually enable that in the [22:40] fleet and 20 2022 we did the first 800 [22:45] gabit a second CDN server which is [22:48] basically a very similar to the first [22:50] one except it's a dual the previous one [22:52] is if it's a dual socket system with [22:53] twice as many Nicks and twice as much [22:56] storage and the thing that I'm [22:57] particularly proud of which isn't quite [23:00] there yet but I include it in the [23:01] presentation because I'm so excited [23:03] about it is that we should have the [23:05] first server that can do 100 gbits a [23:07] second uh for less than 100 Watts [23:10] meaning that you know you for the power [23:13] that you used to have for a light bulb [23:14] you can serve 20 30,000 customers video [23:18] um and that's based on an Nvidia uh [23:22] Bluefield dpu this is basically a 100 [23:25] Gig Mick that has 16 arm cores on it and [23:28] you know I think something like 48 gigs [23:30] of of ddr5 memory and the cool thing is [23:34] it doesn't need a host you plug it into [23:36] a PCI expansion chassis plug in some [23:38] nvme and you have a system that uses [23:40] very little power that is that can serve [23:44] a lot of traffic and it's not quite [23:46] there yet because the Prototype we have [23:48] in the lab is using a 1200 wat power [23:50] supply and we're getting about we're [23:53] measuring at the wall we're getting [23:54] about 125 watts and we're we ordered [23:57] ordered a power supply that's smaller [23:59] because if you have a power supply [24:01] that's 1,200 watts and you're only [24:02] pulling 100 Watts the efficiency is [24:04] terrible and it also has more nvme [24:06] drives than it needs because I'm lazy [24:08] and I want to ramp machines up quickly [24:11] and the more the more storage I have the [24:12] more clients will come and find stuff [24:14] that they want so the more traffic I get [24:16] quickly and [24:18] so once once I pull a couple of nvme [24:20] drives and move to a better power supply [24:22] I'm hoping it'll drop from 125 watts to [24:25] below [24:26] 100 [24:28] all right now here's the the title of [24:30] the talk and this is this is basically [24:32] why we run uh FreeBSD current [24:36] so we did an upstream merge in August [24:39] and it was a and as things start out it [24:41] was a very easy merge like almost no [24:43] like only two merge conflicts everything [24:45] looked great and then I went to test it [24:48] on my original 100 Gig machine which I [24:50] test every merge there for performance [24:53] and I noticed that the performance in [24:55] the CPU use increased by roughly 20% [24:58] and I did you know everything that I [25:00] normally do when I'm looking for [25:01] performance problems I looked to see you [25:03] know if there was some function that was [25:04] super hot maybe there's lock and tension [25:07] and I spent you know a long time looking [25:09] over profilers and I just couldn't [25:10] figure out why the CPUs the CPU use had [25:13] gotten so [25:15] high so this is an internal uh graph of [25:19] ours that shows like the bandwidth being [25:20] served that's roughly 92 gigs which is [25:23] what we serve on our 100 on our 100 Gig [25:26] machines and this is what the uh this is [25:29] what the CPU should look like in the in [25:30] the low 40% range and this is what it [25:33] looks like after the merge like kind of [25:35] jagged and janky and like 50% or [25:39] above and so when you don't know what [25:40] you're doing and you have no idea what [25:42] happened what you do is you bisect um [25:44] and I not sure how many people here are [25:47] developers has anybody here ever done a [25:49] get bisect when I raise your hand all [25:51] right so I'll try to explain it then so [25:53] basically a get bisect you take the last [25:56] point you knew everything was good and [25:58] then you take where you are where it's [26:00] bad [26:02] and and you check out a tree that's [26:04] halfway in between and if that tree is [26:08] good then you know that everything [26:10] before it was good and so you check out [26:12] a tree halfway in between the bad point [26:14] and and the good point and you just keep [26:16] narrowing things down like that until [26:18] you figure out which commit is the [26:19] problem and since we run uh we run freey [26:23] in a sub in a sub tree of our entire [26:26] tree it was kind of painful because I [26:28] did the bisect Upstream looked at the [26:30] gith has and then did the did the merge [26:32] on that giash in the subtree and you [26:35] know redid the merge conflicts over and [26:37] over and again which was really boring [26:39] um so the process was basically to do [26:42] that build an image uh and you know [26:44] install it and test it and that whole [26:47] process uh took about four hours per [26:50] bisection [26:51] step and it was quite slow and painful [26:55] and as SpongeBob would say like one [26:56] eternity later [26:58] um we found I found the commit and of [27:01] course it still didn't make any sense [27:03] usually when when you do this you look [27:04] at the commit and you're like oh and now [27:06] I understand what happened in this case [27:08] it still made absolutely no sense this [27:11] and the funny thing is this is like the [27:13] most famous FreeBSD commit that I can [27:15] remember um there was there's a guy [27:17] Colin pel who's a FreeBSD committer he [27:19] also runs tar snap if you've ever heard [27:21] of that it's a backup service and he [27:24] likes he he runs it in AWS and he wants [27:26] to be able to boot aw instances as quick [27:28] as possible so he's been working on [27:30] optimizing this this the boot speed of [27:32] FreeBSD and he discovered that there's [27:34] this sorting routine that runs with [27:35] FreeBSD boots that was using what he [27:37] said was a bubble sort which is like you [27:40] know horribly inefficient sort and [27:42] FreeBSD spent a lot of his time booting [27:45] just running this sort and he fixed that [27:47] and the commit that broke everything for [27:49] us is is that commit where he fix the [27:51] Sorting time so you can see like that's [27:54] a fairly popular tweet at least for [27:56] something related to FreeBSD he was on [27:58] on the front page of Hacker News for a [28:01] while and so to detour into what's it [28:05] into what's assisting it so basically [28:07] like every kernel subsystem needs to [28:09] initialize itself at boot um and and [28:12] that's done using the sisit macro um and [28:16] the the Linker when you build the kernel [28:18] sorts every sisit into this [28:20] alphabetically ordered list and but you [28:23] don't really want an alphabetical order [28:25] you want it in the order that you need [28:26] to initialize a substance in so that's [28:28] that's where the sort comes in there's [28:30] 79 subsystems and within each of those [28:32] sub subsystems there's something like [28:33] eight different levels like you know I [28:35] want to go first I want to go second I [28:38] you know I want to go last I don't [28:39] really care when I want to [28:40] go and [28:42] so they're sorted at boot by first [28:45] subsystems and the subsystems have an [28:47] order that they're initialized in and [28:48] then within those subsystems that order [28:50] those order and hints are [28:51] applied and so the key is that the cets [28:54] with the same that that are tied that [28:56] have the same subset system and have the [28:58] same ordering hint they should be able [28:59] to run in any [29:01] order so but it turns out the original [29:03] sort uh wasn't a bubble sort it was a [29:05] selection sort and that meant that ties [29:07] were handled differently and so we went [29:10] from having everything still in [29:12] alphabetical order within all the ties [29:14] were kept in alphabetical order to [29:16] having all the ties in Reverse [29:19] alphabetical [29:20] order and uh I and Colin and I both [29:24] verified that independently using this [29:26] thing he made called TS log which logs [29:28] like what's running at boot and how long [29:29] it [29:31] takes um and so the easy fix uh for this [29:35] was to reverse his reverse the order [29:37] that his new sort was using and once we [29:40] did that everything worked but still [29:43] made no sense like why did that matter [29:46] um and [29:48] [Music] [29:50] so excuse me a very dry [29:53] mouth um and so basically I wanted to [29:57] figure out why it mattered so I hacked [29:58] the kernel to control the order that [30:02] things were sorted in and so first I I [30:05] reversed entire subsystems and I did [30:08] another bsection where I took the first [30:10] half of the subsystems and the you know [30:13] and then you know reversed them and saw [30:15] if that worked and then and did a [30:16] bisection that way and then once I found [30:19] the the subsystem that was at fault [30:20] which was the driver subsystem I then [30:23] disected you know all the things in that [30:26] just [30:28] one you know essentially you know a [30:30] second [30:32] bsection and that took a long time too [30:35] it was faster because I didn't need to [30:36] recompile and reimage anything because I [30:37] could just use boot you know boot [30:39] arguments to do it but eventually I [30:41] figured out what the real problem was [30:44] and so essentially there were multiple [30:46] uh CPU frequency control drivers that [30:49] thought that they wanted to attach to [30:52] the CPU frequency control Hardware on [30:56] our uh on our Intel [30:58] Zeon [30:59] and this happened because the way [31:01] drivers are supposed to work in FreeBSD [31:04] is they're supposed to be a probe score [31:06] so every driver kind of gets to look and [31:08] see oh yeah yeah I know what that [31:10] Hardware is and that's exactly what I'm [31:11] what I was made for and I want that 100% [31:14] or you know I think maybe I can handle [31:16] this Hardware but I'm not sure and if [31:18] somebody else you know better comes [31:19] along you should give it to them [31:21] unfortunately these drivers weren't [31:23] doing that and they were either [31:24] returning like a like a one or a zero [31:26] saying yeah I can I can I can handle it [31:27] or no I can't and both of these drivers [31:30] were saying yeah I can handle it and so [31:32] when that happens the first guy to get [31:34] there wins and so that meant that uh [31:37] when the order was was in the [31:40] alphabetical order the new and more [31:42] modern Intel EST driver attached first [31:46] and the older Pentium 4 thermal control [31:49] something or other driver attached [31:51] second and and got there and and and [31:55] lost because it was second when the [31:57] order was reversed the older much worse [32:00] driver attached first and the newer [32:03] appropriate driver got there and found [32:04] somebody else was there and didn't [32:07] attach um so things had work worked [32:10] accidentally for you know years close to [32:12] a decade I think just because of that [32:14] alphabetic L ordering uh my colleague [32:16] Warner L is actually working to add [32:19] appropriate probe scoring to all these [32:20] drivers so that that you know the ties [32:24] will be broken [32:26] appropriately [32:27] so and I was kicking myself because [32:29] freeb has a cist control node which [32:32] tells you the frequencies that are [32:33] supported and stuff and when the P4 TCC [32:36] driver attached uh you saw basically [32:39] garbage there were frequencies that [32:40] weren't supported by the processor and [32:42] that number behind the slash is like how [32:44] much power it thinks it's supposed to [32:46] use which meant that it had no idea [32:48] whereas the EST driver it saw all the [32:50] actual frequencies and it knew all the [32:52] actual power consumption levels for the [32:54] different frequencies and it was just it [32:55] was correct and so what was happening [32:57] was basically the CPU was just running [33:00] at a it's a slower speed than it should [33:02] have been running at and so everything [33:04] was fine there was no actual like [33:05] regression because something got worse [33:07] in terms of things actually getting less [33:09] efficient it's just that the colonel was [33:11] running this the processor at a slower [33:13] Speed without even realizing [33:16] it and so this is like you know an [33:19] example of [33:21] um Community intera this is a this is a [33:24] basically an example of like great [33:26] Community interaction [33:27] I reached out to Colin after I figured [33:29] out that that commit was the problem uh [33:31] on an internal FreeBSD IRC chat room and [33:35] within you know minutes he responded and [33:38] we both independently verified that the [33:40] Sorting order was different um and the [33:43] key thing is that he remembered the [33:44] change because he had just done it a few [33:46] weeks ago he remembered the change and [33:48] he was super happy to help um and he [33:50] posted a fix for review that same day it [33:53] landed in freeus dcurrent the next day [33:55] and I Cherry Picked it down into merge [33:57] Branch you know within a few minutes of [33:58] it Landing [34:01] um so our benefit the benefits to us is [34:06] sorry the benefits to to the community [34:08] rather is that we noticed this bug [34:11] almost immediately uh because we run a [34:13] lot of server class Hardware other [34:15] people might see some kind of problem [34:17] like this and might just say oh the new [34:18] version of FreeBSD is slower I don't [34:20] know why um but we were the first to [34:22] notice the regression [34:24] and we were the first to be able [34:27] attributed to this change and later we [34:29] realized that there was one other bug [34:30] that popped up around the same time uh [34:33] there some kind of Kernel crash and an [34:34] AMD temperature driver that was due to [34:37] the same [34:39] issue [34:40] um and our the benefit to us to Netflix [34:43] from this is that this was a crazy bug [34:47] that required bisection um bisecting [34:50] like three weeks of changes was terrible [34:53] because each bisection Tech step takes [34:55] like 4 hours and so I you know bisection [34:58] it's like a you know kind of a log log [35:00] log type thing where if you have twice [35:03] as many changes it's only one more [35:04] bisection step but it we're talking if [35:07] we're talking three years worth of [35:08] changes I can't imagine even doing that [35:10] bsection it would have driven driven me [35:14] insane um and the other benefit to us is [35:18] that since we found it so quickly Colin [35:21] was like very responsive um and it got [35:23] fixed almost immediately if this had [35:26] been a that have been in FreeBSD for 3 [35:28] years it would have been perfectly [35:29] reasonable for him to say what you got [35:32] to be crazy this has been in the tree [35:33] for 3 years nobody's complained about it [35:35] like you guys have got to be doing [35:36] something wrong and be in denial I mean [35:39] and there nothing to say about him he [35:40] maybe he wouldn't he's a great guy but [35:42] if it was one of my changes I would [35:44] definitely be like what are you talking [35:45] about I did that change three years ago [35:47] I barely even remember why I did it like [35:49] why are you talking to me about it now [35:50] like it's been nobody's complained about [35:52] it obviously you're doing something [35:53] wrong just go away [35:55] and that would be a very easy thing for [35:58] somebody to say after after 3 [36:01] years and so that's basically uh all I [36:04] really had to talk about uh and looks [36:06] like we have about 10 minutes for [36:08] questions if anybody has [36:18] any [36:19] [Music] [36:21] no no [36:24] questions okay you can go to the [36:30] please how much time it takes [36:33] to upgrade all your servers how much [36:37] time does it take to upgrade all all of [36:38] your [36:39] servers um so essentially the servers [36:42] are upgraded In Waves uh we don't do [36:45] them all at once because there could be [36:47] some bug that we didn't catch in testing [36:50] so I think that I don't I don't do the [36:52] upgrade of all of our servers our Fleet [36:54] is on the order of tens of thousands of [36:56] machines we have an operations team that [36:57] does that I believe it takes [37:01] roughly roughly a week I think but don't [37:04] quote me on that because I'm not I'm not [37:06] certain um in fact one of the worst bugs [37:10] we ever had was due to a bug in a [37:12] network interface driver we took new [37:14] firmware for the a new firmware blob for [37:16] the network interface driver and we do a [37:19] lot of monitoring of temperature of uh [37:23] Optical transceivers of light levels of [37:26] everything and we we slam the IDC [37:29] interface that's on those transceivers [37:31] and there was a bug in their firmware [37:33] where like in one in a million one in 10 [37:36] million ID Toc reads would time out and [37:40] cause the Nick to reset and just [37:42] basically go dead uh and so this was [37:45] like five or six years ago we started [37:47] rolling a firmware out and we noticed [37:49] that you know maybe one and a thousand [37:51] machines was not responsive after you [37:54] know a day or so and that was and that [37:57] was like the worst that was the worst [37:58] bug that we ever had because when a [37:59] machine's not responsive it's really [38:02] hard to deal with especially if it's at [38:04] a if it's at a site where we don't have [38:06] um ipmi access to it so we have ipmi [38:09] access to everything that we have in an [38:10] internet interchange point but not we [38:13] don't have ipmi access to things that [38:14] are in ISP data centers and so [38:17] thankfully we found that before it hit [38:18] any ISP data centers so we could [38:20] actually rebou the machines but since [38:22] then we've been much more careful about [38:25] taking from our blubs [38:27] in fact we actually have our own copy of [38:30] some of the firmware that we know works [38:32] and just ignore the Upstream firmware [38:36] forits and after you fixed the driver [38:40] sorting book did the performance improve [38:42] or it was like before the update it was [38:45] yeah the performance was as we expected [38:47] it was it was the original performance [38:48] in the in the mid low 40% range that we [38:55] expected uh why a free BSD and not Linux [38:58] or some some other distribution um [39:02] that's a question that is likely to [39:05] start a flame War so it's the question [39:07] that my management has told me not to [39:08] get into um but we're not stupid and we [39:11] wouldn't run we we wouldn't be running [39:13] 3sp if it didn't work better in this [39:15] application for [39:18] us like we're not religious I'm not [39:21] religious I've in my past I've worked on [39:24] Linux I worked uh on Linux [39:27] uh for a company that I made that I [39:29] worked on Unix device drivers for Linux [39:32] and Solaris and previous and Ma OS and [39:34] ESX VMware and all kinds of crazy [39:37] operating systems and I worked on Linux [39:39] when I worked at Google so I'm I'm not [39:40] religious it's just right now it's just [39:43] seems like it's the best tool for the [39:45] job I think the the initial decision may [39:48] have been made based on the license I [39:50] wasn't there so I don't [39:54] know anything else [39:58] um D thank you very much for sharing [40:00] bits of your really challenging work [40:02] with us it was really interesting uh we [40:04] have prepared something for you oh well [40:06] thank [40:07] you okay um let's give him another round [40:11] of applauses and [40:18] thank