This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-af-xdp-umem-watermark-guardrail

AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant

Enforces strict kernel-level drop policies and user-space fill-ring capacity watermarks before zero-copy UMEM buffer exhaustion degrades ingress packet processing. Mandates lock-free ring balance monitoring and active BPF map backpressure signaling to guarantee deterministic zero-copy networking under ingress microbursts.

Prohibited Anti-Pattern: Unbounded AF_XDP Ingress Without Ring Watermark Enforcement Causing Silent UMEM Exhaustion

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant - Enforces strict kernel-level drop policies and user-space fill-ring capacity watermarks before zero-copy UMEM buffer exhaustion degrades ingress packet processing. Mandates lock-free ring balance monitoring and active BPF map backpressure signaling to guarantee deterministic zero-copy networking under ingress microbursts.
globs: src/**/*.{ts,tsx}, src/native/**/*.{c,h}, src/ebpf/**/*.{c,h}, k8s/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-af-xdp-umem-watermark-guardrail"
---

# AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded AF_XDP Ingress Without Ring Watermark Enforcement Causing Silent UMEM Exhaustion

## System Constraints
You are a Principal Engineer enforcing eBPF AF_XDP Zero-Copy Packet Ring Watermark Guardrails. Mandate kernel-level drop maps, UMEM fill-ring reserve boundaries, and deterministic backpressure invariants to prevent socket buffer starvations.

## Strict Guidelines
- Engineers MUST ALWAYS enforce a minimum 25% UMEM fill-ring headroom watermark in user-space before batch processing RX packets.
- Engineers MUST NOT decouple RX ring descriptor consumption from immediate UMEM fill ring replenishment within the same event-loop batch tick.
- Code SHOULD synchronize queue occupancy watermarks into an atomic eBPF array map (`bpf_map_update_elem`) so the XDP kernel hook can execute deterministic `XDP_DROP` backpressure before ring saturation occurs.
- Services MUST monitor fill-ring depleted events and emit immediate high-priority alerts before hardware NIC frame drops occur at driver zero-copy rings.
- Components NEVER execute blocking allocations or syscalls inside user-space ring descriptor polling routines.

## Bad vs Good Implementations
### AF_XDP UMEM Fill Ring Replenishment & Kernel Watermark Synchronization

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: User-space consumes RX descriptors without replenishing the UMEM fill ring or checking watermark levels. As ingress traffic bursts, the kernel's XDP driver runs out of fill-ring entries and drops packets indiscriminately, bypassing zero-copy buffer guarantees.
```typescript
// Flawed: Drains RX descriptors without tracking fill-ring watermark
// Starves kernel UMEM, causing uncoordinated NIC drops and descriptor leaks
export class AfXdpConsumer {
  private rxRing: BigUint64Array;
  private fillRing: BigUint64Array;

  constructor(rx: BigUint64Array, fill: BigUint64Array) {
    this.rxRing = rx;
    this.fillRing = fill;
  }

  public processBatch(batchSize: number): void {
    for (let i = 0; i < batchSize; i++) {
      const desc = this.rxRing[i];
      if (!desc) break;
      // Long asynchronous dispatch without replenishing fill ring
      this.dispatchPacket(desc);
    }
    // Fill ring is never proactively audited or replenished,
    // leading to silent kernel drop at XDP_REDIRECT
  }

  private dispatchPacket(desc: bigint): void {
    // Process packet payload
  }
}
```

#### Production Standard (Correct)
> **Standard**: Enforces a strict 25% minimum capacity reserve watermark on the UMEM fill ring. Uses atomic memory synchronization with an eBPF map to signal kernel-space XDP drivers to drop traffic gracefully before fill-ring starvation can trigger hard hardware packet corruption.
```typescript
// Production Guardrail: Continuous watermark monitoring and kernel backpressure map synchronization
export interface UmemWatermarkConfig {
  totalRingSize: number;
  minReservePercentage: number; // e.g. 25%
}

export class SafeAfXdpConsumer {
  private readonly minReserve: number;
  private freeUmemSlots: number;

  constructor(
    private readonly config: UmemWatermarkConfig,
    private readonly rxRing: BigUint64Array,
    private readonly fillRing: BigUint64Array,
    private readonly bpfWatermarkMap: Int32Array
  ) {
    this.minReserve = Math.floor((config.totalRingSize * config.minReservePercentage) / 100);
    this.freeUmemSlots = config.totalRingSize;
  }

  public processBatch(batchSize: number): void {
    const availableEntries = this.freeUmemSlots;
    
    // Invariant: Signal kernel XDP program to drop early if watermark is breached
    if (availableEntries <= this.minReserve) {
      Atomics.store(this.bpfWatermarkMap, 0, 1); // 1 = DROP_ON_WATERMARK
      return;
    } else {
      Atomics.store(this.bpfWatermarkMap, 0, 0); // 0 = FORWARD_TO_XSK
    }

    let processed = 0;
    for (let i = 0; i < batchSize; i++) {
      const desc = this.rxRing[i];
      if (!desc) break;

      this.dispatchPacket(desc);
      // Synchronous replenishment invariant: Immediately cycle descriptor back to fill ring
      this.fillRing[i] = desc;
      processed++;
    }

    // Watermark maintained: Free slots restored synchronously
    this.freeUmemSlots = this.config.totalRingSize - (batchSize - processed);
  }

  private dispatchPacket(desc: bigint): void {
    // Zero-copy processing within bound bounds
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant

AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces strict kernel-level drop policies and user-space fill-ring capacity watermarks before zero-copy UMEM buffer exhaustion degrades ingress packet processing. Mandates lock-free ring balance monitoring and active BPF map backpressure signaling to guarantee deterministic zero-copy networking under ingress microbursts. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unbounded AF_XDP Ingress Without Ring Watermark Enforcement Causing Silent UMEM Exhaustion Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnbounded AF_XDP Ingress Without Ring Watermark Enforcement Causing Silent UMEM ExhaustionCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enforce a minimum 25% UMEM fill-ring headroom watermark in user-space before batch processing RX packets.

Engineers MUST ALWAYS enforce a minimum 25% UMEM fill-ring headroom watermark in user-space before batch processing RX packets.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT decouple RX ring descriptor consumption from immediate UMEM fill ring replenishment within the same event-loop batch tick.

Engineers MUST NOT decouple RX ring descriptor consumption from immediate UMEM fill ring replenishment within the same event-loop batch tick.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code SHOULD synchronize queue occupancy watermarks into an atomic eBPF array map (`bpf_map_update_elem`) so the XDP kernel hook can execute deterministic `XDP_DROP` backpressure before ring saturation occurs.

Code SHOULD synchronize queue occupancy watermarks into an atomic eBPF array map (`bpf_map_update_elem`) so the XDP kernel hook can execute deterministic `XDP_DROP` backpressure before ring saturation occurs.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST monitor fill-ring depleted events and emit immediate high-priority alerts before hardware NIC frame drops occur at driver zero-copy rings.

Services MUST monitor fill-ring depleted events and emit immediate high-priority alerts before hardware NIC frame drops occur at driver zero-copy rings.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER execute blocking allocations or syscalls inside user-space ring descriptor polling routines.

Components NEVER execute blocking allocations or syscalls inside user-space ring descriptor polling routines.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is AF_XDP UMEM Fill Ring Watermark & Kernel Drop Invariant critical for AI coding assistants?

Enforces strict kernel-level drop policies and user-space fill-ring capacity watermarks before zero-copy UMEM buffer exhaustion degrades ingress packet processing. Mandates lock-free ring balance monitoring and active BPF map backpressure signaling to guarantee deterministic zero-copy networking under ingress microbursts. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unbounded AF_XDP Ingress Without Ring Watermark Enforcement Causing Silent UMEM Exhaustion) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

AF_XDP