Skip to content

⚡ Bolt: [performance improvement] Use napi_alloc_skb - #7

Open
maxugly wants to merge 1 commit into
mainfrom
bolt-napi-alloc-skb-16511296223692522389
Open

⚡ Bolt: [performance improvement] Use napi_alloc_skb#7
maxugly wants to merge 1 commit into
mainfrom
bolt-napi-alloc-skb-16511296223692522389

Conversation

@maxugly

@maxugly maxugly commented Jul 18, 2026

Copy link
Copy Markdown
Owner

💡 What: Replace dev_alloc_skb with napi_alloc_skb in the NAPI poll loop (nata_poll -> sim_rx_dequeue). Also added struct napi_struct *napi parameter to sim_rx_dequeue to pass the context down.
🎯 Why: Using dev_alloc_skb uses the generic slab allocator, whereas napi_alloc_skb uses a specialized per-CPU cache, avoiding lock contention and improving allocation performance during high-volume RX interrupts.
📊 Impact: Expected reduction in latency and improved CPU utilization, leading to a bump in TCP/UDP throughput in high-load scenarios.
🔬 Measurement: Verify by benchmarking TCP throughput with sudo ./scripts/nata-bench-once.sh. Ensure module loads, successfully handles traffic, and teardown doesn't result in leaks.


PR created automatically by Jules for task 16511296223692522389 started by @maxugly

Summary by CodeRabbit

  • Performance

    • Improved packet reception efficiency during NAPI polling by using NAPI-managed buffer allocation.
    • Reduced allocation overhead in simulated network receive paths without changing packet processing behavior.
  • Documentation

    • Added documentation describing the NAPI allocation optimization.

Replace dev_alloc_skb with napi_alloc_skb in the NAPI poll loop
to utilize per-CPU NAPI cache.

Co-authored-by: maxugly <64644401+maxugly@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The RX polling path now passes struct napi_struct into sim_rx_dequeue, which uses napi_alloc_skb for received frames. A dated documentation entry records the implementation guidance.

Changes

NAPI RX allocation

Layer / File(s) Summary
Thread NAPI context
module/nata.h, module/nata_blk.c, module/nata_net.c
The sim_rx_dequeue contract and implementation accept the NAPI context, and nata_poll passes it through.
Use NAPI skb allocator
module/nata_blk.c, .jules/bolt.md
RX skb allocation uses napi_alloc_skb(napi, hdr.len + 2), with the change documented.
Estimated code review effort: 2 (Simple) ~10 minutes

Possibly related PRs

  • maxugly/nata#3: Also modifies the NAPI RX polling and sim_rx_dequeue paths.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: switching the RX path to napi_alloc_skb for a performance improvement.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-napi-alloc-skb-16511296223692522389

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the generic dev_alloc_skb with napi_alloc_skb inside the NAPI polling loop to utilize per-CPU cached allocations for better performance. The review feedback suggests adding a fallback to dev_alloc_skb in case napi is NULL to avoid potential kernel panics, and highlights that allocating memory while holding priv->lock is a performance anti-pattern that should be refactored.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread module/nata_blk.c
}

skb = dev_alloc_skb(hdr.len + 2);
skb = napi_alloc_skb(napi, hdr.len + 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Robustness & Performance Improvement

  1. Defensive Programming: If napi is NULL (for instance, if this function is called from a non-NAPI context, testing, or fallback paths), passing it directly to napi_alloc_skb can lead to a kernel panic or undefined behavior depending on the kernel version. Adding a fallback to dev_alloc_skb ensures robustness.
  2. Spinlock Holding Time: Calling napi_alloc_skb (or any memory allocation) while holding the spinlock priv->lock is a performance anti-pattern. Under memory pressure, the allocation can fall back to the page allocator, increasing lock holding time and causing severe lock contention with the TX path (nata_xmit).

Consider refactoring the RX path in a future iteration to perform the allocation outside of the spinlock (e.g., by peeking at the packet length locklessly first).

Suggested change
skb = napi_alloc_skb(napi, hdr.len + 2);
skb = napi ? napi_alloc_skb(napi, hdr.len + 2) : dev_alloc_skb(hdr.len + 2);

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@module/nata_blk.c`:
- Line 240: Update section 6.3 of the RX dequeue specification to replace the
documented dev_alloc_skb behavior with napi_alloc_skb(napi, ...) and describe
the threaded NAPI context used by the dequeue path. Keep the documentation
aligned with the implementation around the skb allocation call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84993b8e-56e9-4d53-a653-ab0c21fb5dfd

📥 Commits

Reviewing files that changed from the base of the PR and between 514361c and a1e4a56.

📒 Files selected for processing (4)
  • .jules/bolt.md
  • module/nata.h
  • module/nata_blk.c
  • module/nata_net.c

Comment thread module/nata_blk.c
}

skb = dev_alloc_skb(hdr.len + 2);
skb = napi_alloc_skb(napi, hdr.len + 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the RX dequeue specification.

docs/specs/04-kernel-module.md still documents dev_alloc_skb; update section 6.3 to describe napi_alloc_skb(napi, ...) and the threaded NAPI context so the implementation and specification remain consistent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@module/nata_blk.c` at line 240, Update section 6.3 of the RX dequeue
specification to replace the documented dev_alloc_skb behavior with
napi_alloc_skb(napi, ...) and describe the threaded NAPI context used by the
dequeue path. Keep the documentation aligned with the implementation around the
skb allocation call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant