Wifi memory use

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Wifi memory use

Postby PeterR » Sun Feb 16, 2020 12:13 pm

I am struggling to understand/predict Wifi memory requirements.

Wifi has static and dynamic memory buffers. Static buffers are 1600 bytes, dynamic buffers are sized according to need.
menuconfig allows you to select the type of TX buffer that will be used.
Static is recommended if PSRAM available. I assume then that the dynamic options will not fail if there is insufficient memory but just drop the frame? Not sure how helpful that is if the application has other dynamic memory needs.

Even with TX static selected my boot up code shows:

Code: Select all

I (4793) wifi: Init dynamic tx buffer num: 32


Q) How do I prevent dynamic TX buffers (I have selected static option_
Q) Will dynamic TX buffers be allocated in PSRAM?
Q) Can either static or dynamic RX buffers be allocated in PSRAM?
Q) Why should the dynamic RX buffer limit be at least the static RX limit?
& I also believe that IDF CAN should be fixed.

liuzhifu
Posts: 39
Joined: Tue Dec 13, 2016 2:18 am

Re: Wifi memory use

Postby liuzhifu » Fri Feb 21, 2020 5:07 am

Q) How do I prevent dynamic TX buffers (I have selected static option_

If PSRAM is not supported, we'd better configure the buffer type to dynamic TX buffer to save memory because the memory is very limited.

Q) Will dynamic TX buffers be allocated in PSRAM?
No, it won't.

Q) Can either static or dynamic RX buffers be allocated in PSRAM?
WiFi Static TX/RX Buffer can be considered as WiFi DMA TX/RX buffer, it can only be allocated from internal memory because it's used by WiFi hardware for packet transmitting and receiving.

Q) Why should the dynamic RX buffer limit be at least the static RX limit?

When WiFi hardware receives a packet from air, it puts the packet into WiFi Static RX Buffer and notifies the WiFi software to receive the packet. In WiFi software, it allocates a WiFi Dynamic RX Buffer and copies the packet from WiFi Static RX Buffer to WiFi Dynamic RX Buffer, then returns the WiFi Static RX Buffer for hardware to receive new packet. Then WiFi software processes the WiFi packet and delivers it to LWIP. After LWIP processes the packet, it returns it to WiFi driver to receive new packets. Notified that the WiFi static RX buffer is delivered to LWIP by reference, it means the WiFi Dynamic RX Buffer can be reused until both WiFi Driver and LWIP completely processing it. Generally speaking, the speed of WiFi/LWIP processing is slower than the speed of hardware receiving, so we need to set WiFi Dynamic RX buffer a bigger value than WiFi Static RX Buffer to receive more burst packets.

Moreover, when PSRAM is supported, the WiFi Dynamic RX Buffer is allocated from PSRAM, PSRAM has bigger space than internal memory, we should set a bigger enough value for WiFi Dynamic RX Buffer.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: Wifi memory use

Postby PeterR » Sat Feb 22, 2020 12:53 am

Cool, thanks. That really helped.
Ok, yes, I now see in menuconfig that TX is always DRAM. That makes sense if static is realy about DMA.
I understand now, a DMA 'pbuf' cache with a (PSRAM or DRAM) backing store.
One confirming question is - if we don't have PSRAM then why bother with dynamic buffers option? Is this just a help text 'issue' ?
So dynamic RX buffers will be PSRAM, great. I will have to profile the CPU/cache hit I suppose.
Thanks.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: No registered users and 106 guests