Re: rtwn0: rtwn_rx_copy_to_mbuf: could not allocate RX mbuf

From: Nuno Teixeira <eduardo_at_freebsd.org>
Date: Sat, 26 Apr 2025 07:58:09 UTC
Hello!

> Ok, that is interesting. We're not keeping counters in m_get2() for when the buffer requested is too large; it only returns NULL.
> I guess it's bailing if it's above a page size (4kbytes.)
>
> Try changing the m_get2() call there to m_get3(); let's see if that improves things.
> (m_get3() will fail above 16kbytes; and if it can't allocate a buffer < 16kbytes then we should get some UMA error counted somehwere.)

iperf3 -R is happy, and git pull --rebase completed OK and fast:

Connecting to host hp, port 5201
Reverse mode, remote host hp is sending
[  5] local 192.168.1.82 port 39601 connected to 192.168.1.100 port 5201
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.06   sec  6.00 MBytes  47.4 Mbits/sec
[  5]   1.06-2.06   sec  15.9 MBytes   134 Mbits/sec
[  5]   2.06-3.06   sec  16.1 MBytes   135 Mbits/sec
[  5]   3.06-4.06   sec  16.4 MBytes   137 Mbits/sec
[  5]   4.06-5.00   sec  15.0 MBytes   134 Mbits/sec
[  5]   5.00-6.06   sec  16.4 MBytes   129 Mbits/sec
[  5]   6.06-7.06   sec  15.2 MBytes   128 Mbits/sec
[  5]   7.06-8.06   sec  14.8 MBytes   124 Mbits/sec
[  5]   8.06-9.06   sec  15.8 MBytes   132 Mbits/sec
[  5]   9.06-10.06  sec  16.1 MBytes   135 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.08  sec   148 MBytes   123 Mbits/sec    0            sender
[  5]   0.00-10.06  sec   148 MBytes   123 Mbits/sec                  receiver

iperf Done.

I will use this dongle on amd64 for further testing, I will patch aarch64 soon.

```
diff --git a/sys/dev/rtwn/usb/rtwn_usb_rx.c b/sys/dev/rtwn/usb/rtwn_usb_rx.c
index 657d6bdeb9e4..54869fe336bd 100644
--- a/sys/dev/rtwn/usb/rtwn_usb_rx.c
+++ b/sys/dev/rtwn/usb/rtwn_usb_rx.c
@@ -124,10 +124,10 @@ rtwn_rx_copy_to_mbuf(struct rtwn_softc *sc,
struct rtwn_rx_stat_common *stat,
        if (rtwn_rx_check_pre_alloc(sc, stat) != 0)
                goto fail;

-       m = m_get2(totlen, M_NOWAIT, MT_DATA, M_PKTHDR);
+       m = m_get3(totlen, M_NOWAIT, MT_DATA, M_PKTHDR);
        if (__predict_false(m == NULL)) {
-               device_printf(sc->sc_dev, "%s: could not allocate RX mbuf\n",
-                   __func__);
+               device_printf(sc->sc_dev, "%s: could not allocate RX
mbuf (%d bytes)\n",
+                   __func__, totlen);
                goto fail;
        }
```

Thanks!


-- 
Nuno Teixeira
FreeBSD UNIX:  <eduardo@FreeBSD.org>   Web:  https://FreeBSD.org