libusb bulk 的最大传输大小是多少?

What is the maximum transfer size of libusb bulk?

最近我正在 Linux 上开发自定义 USB 接收器程序 运行。我选择使用libusb来开发。由于带宽更大,我需要更大的总传输大小。当时我提交超过15MB时(每次批量传输1MB,第16次提交失败)就会报错:

[INFO] submit transfer [0]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [1]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [2]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [3]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [4]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [5]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [6]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [7]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [8]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [9]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [10]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [11]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [12]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [13]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
[INFO] submit transfer [14]: [0] LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED
libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=12
[INFO] submit transfer [15]: [-1] LIBUSB_ERROR_IO
libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=12

这是在ubuntu18.04上的测试结果,

相关系统信息:

Linux xxx 5.4.0-77-generic #86~18.04.1-Ubuntu SMP Fri Jun 18 01:23:22 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

系统内存:20GB

我在Raspberry Pi4B上测试的时候也遇到了同样的问题。通过Google没有找到相关问题的答案(可能是关键字用错了?)

有一个很相似的问题,不过他说最大限制是一个int能表示的最大值,但是好像不是这样

任何建议或提示都会对我有很大帮助!

原来我用google很烂,开源真的很棒!!

我深入研究代码,发现内核源代码中的内存限制: https://github.com/torvalds/linux/blob/3d5895cd351757f69c9a66fb5fc8cf19f454d773/drivers/usb/core/devio.c#L133

现在我可以通过/sys/module/usbcore/parameters/usbfs_memory_mb

设置内存限制