Skip to content

libbladeRF: reject stream configs that exceed the usbfs memory budget - #1075

Open
wormuz wants to merge 2 commits into
Nuand:masterfrom
wormuz:fix/usbfs-budget
Open

libbladeRF: reject stream configs that exceed the usbfs memory budget#1075
wormuz wants to merge 2 commits into
Nuand:masterfrom
wormuz:fix/usbfs-budget

Conversation

@wormuz

@wormuz wormuz commented Aug 18, 2026

Copy link
Copy Markdown

Every in-flight USB transfer is pinned by the kernel, so a stream needs num_transfers * buffer_size_bytes of usbfs memory simultaneously. The default limit is 16 MiB.

Exceeding it fails far from its cause: bladerf_sync_config() returns success, submit_transfer() then fails asynchronously with LIBUSB_ERROR_NO_MEM, and the caller only sees BLADERF_ERR_MEM from the first bladerf_sync_rx() — with nothing pointing at the transfer count.

Measured on a bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0), SC16_Q11_META at 61.44 Msps with buffer_size=131072 samples:

num_transfers=31  ->  ok
num_transfers=32  ->  ERR_MEM from the first sync_rx

32 × 512 KiB is exactly the 16 MiB limit. The larger GPIF buffers in FX3 2.6.0 make this much easier to hit than before.

The check runs in async_init_stream() and returns BLADERF_ERR_INVAL with the numbers and the maximum transfer count that fits:

Stream needs 16 MiB of in-flight USB buffers (32 transfers x 524288 bytes),
but usbfs_memory_mb is 16. Use at most 28 transfers, or raise the limit with
'echo <MiB> > /sys/module/usbcore/parameters/usbfs_memory_mb'.

The limit is read from sysfs on Linux and falls back to the kernel default of 16 MiB elsewhere. A second commit documents the constraint on the num_transfers parameter.

@CLAassistant

CLAassistant commented Aug 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

wormuz added 2 commits August 18, 2026 03:43
Every in-flight USB transfer is pinned by the kernel, so a stream needs
num_transfers * buffer_size_bytes of usbfs memory simultaneously. The
default limit is 16 MiB.

Exceeding it fails far from its cause: bladerf_sync_config() returns
success, submit_transfer() then fails asynchronously with
LIBUSB_ERROR_NO_MEM, and the caller only sees BLADERF_ERR_MEM from the
first bladerf_sync_rx() - with nothing pointing at the transfer count.

Measured on bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0), SC16_Q11_META
at 61.44 Msps with buffer_size=131072 samples:

  num_transfers=31  ->  ok
  num_transfers=32  ->  ERR_MEM from the first sync_rx

32 * 512 KiB is exactly the 16 MiB limit. The larger GPIF buffers in FX3
2.6.0 make this easier to hit than before.

Now checked up front: bladerf_sync_config() returns BLADERF_ERR_INVAL and
logs the numbers plus the maximum transfer count that fits.
The number of in-flight transfers is bounded by the kernel's usbfs memory
limit, not just by num_buffers. With the larger GPIF buffers in FX3 2.6.0
the default 16 MiB is easy to reach: 32 transfers of a 131072-sample
SC16_Q11 buffer is exactly 16 MiB.

Documents the limit and the error now returned for configurations that
exceed it.
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.

2 participants