]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
wifi: rtw88: usb: Preallocate and reuse the RX skbs
authorBitterblue Smith <rtl8821cerfe2@gmail.com>
Wed, 18 Dec 2024 22:35:49 +0000 (00:35 +0200)
committerPing-Ke Shih <pkshih@realtek.com>
Mon, 23 Dec 2024 08:06:02 +0000 (16:06 +0800)
commit3e3aa566dd1803f1697530de6c8489a8350765b3
tree184bb0e1a25146e019c0e4d4c02cb20de0430c67
parent13221be72034d1c34630ab124c43438aefe7e656
wifi: rtw88: usb: Preallocate and reuse the RX skbs

The USB driver uses four USB Request Blocks for RX. Before submitting
one, it allocates a 32768 byte skb for the RX data. This allocation can
fail, maybe due to temporary memory fragmentation. When the allocation
fails, the corresponding URB is never submitted again. After four such
allocation failures, all RX stops because the driver is not requesting
data from the device anymore.

Don't allocate a 32768 byte skb when submitting a USB Request Block
(which happens very often). Instead preallocate 8 such skbs, and reuse
them over and over. If all 8 are busy, allocate a new one. This is
pretty rare. If the allocation fails, use a work to try again later.
When there are enough free skbs again, free the excess skbs.

Also, use WQ_BH for the RX workqueue. With a normal or high priority
workqueue the skbs are processed too slowly when the system is even a
little busy, like when opening a new page in a browser, and the driver
runs out of free skbs and allocates a lot of new ones.

This is more or less what the out-of-tree Realtek drivers do, except
they use a tasklet instead of a BH workqueue.

Tested with RTL8723DU, RTL8821AU, RTL8812AU, RTL8812BU, RTL8822CU,
RTL8811CU.

Closes: https://lore.kernel.org/linux-wireless/6e7ecb47-7ea0-433a-a19f-05f88a2edf6b@gmail.com/
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/9cee7a34-c38d-4128-824d-0ec139ca5a4e@gmail.com
drivers/net/wireless/realtek/rtw88/usb.c
drivers/net/wireless/realtek/rtw88/usb.h