Page 1 of 1

WiFi Stack heap memory usage

Posted: Mon Aug 06, 2018 1:36 pm
by Ankit Siddhapura
Hi,

In my application, One RTOS task is continuously scanning AP records at delay of 1000 ms for RSSI value to be used for best parent choose.

After one or two hour STA got disconnected from connected AP duet to beacon time out and AP kicks off station.

i got below print before STA disconnect, seems out of memory.

I would like to know, how stack handles memory for beacon and probe response?

Code: Select all

[Fri Aug 03 20:14:02.074 2018] W (7450429) wifi: alloc eb len=196 type=2 fail
[Fri Aug 03 20:14:02.074 2018] 
[Fri Aug 03 20:14:02.074 2018] W (7450429) wifi: m f probe rsp l=169
[Fri Aug 03 20:14:02.074 2018] 
[Fri Aug 03 20:14:25.621 2018] I (7473979) wifi: bcn_timout,ap_probe_send_start
[Fri Aug 03 20:14:28.142 2018] I (7476479) wifi: ap_probe_send over, resett wifi status to disassoc
[Fri Aug 03 20:14:28.142 2018] I (7476479) wifi: state: run -> init (1)
[Fri Aug 03 20:14:28.142 2018] I (7476479) wifi: n:1 0, o:1 1, ap:1 1, sta:1 1, prof:1
[Fri Aug 03 20:14:28.142 2018] 
[Fri Aug 03 20:14:28.142 2018] STA disconnected
[Fri Aug 03 20:14:28.142 2018] 
[Fri Aug 03 20:14:28.142 2018] Reason code for STA disconnect :200
[Fri Aug 03 20:14:42.342 2018] STA disconnected
[Fri Aug 03 20:14:42.342 2018] 
[Fri Aug 03 20:14:42.342 2018] Reason code for STA disconnect :201
[Fri Aug 03 20:14:43.144 2018] 
[Fri Aug 03 20:14:43.144 2018] Number of access points found: 0
[Fri Aug 03 20:14:43.144 2018] 
[Fri Aug 03 20:14:43.144 2018] No AP available for this scan config, Start Scan Again

Re: WiFi Stack heap memory usage

Posted: Mon Aug 06, 2018 5:02 pm
by kolban
Howdy. What are you seeing in the trace that leads you to believe memory utilization might be an issue?

Re: WiFi Stack heap memory usage

Posted: Mon Aug 06, 2018 7:48 pm
by WiFive
This

Code: Select all

[Fri Aug 03 20:14:02.074 2018] W (7450429) wifi: alloc eb len=196 type=2 fail

Re: WiFi Stack heap memory usage

Posted: Tue Aug 07, 2018 1:31 am
by ESP_Angus
Hi Ankit,

In the default configuration, the WiFi stack will allocate buffers as needed from heap. There are some configuration settings you can change to adjust the allocation that is done, but I wouldn't start with that quite yet.

Is it possible your app has a memory leak? There are a number of functions you can use to check the amount of free heap over time, and a leak checker feature for narrowing down which part of the program is leaking.

If you have a memory leak then you'll see the free heap starting relatively high and then gradually trending down, until suddenly some allocations somewhere fail.

Re: WiFi Stack heap memory usage

Posted: Tue Aug 07, 2018 4:49 am
by Ankit Siddhapura
Thank You ! I got the issue and able to trace heap memory.

Re: WiFi Stack heap memory usage

Posted: Wed Aug 08, 2018 11:12 am
by Ritesh
Ankit Siddhapura wrote:Thank You ! I got the issue and able to trace heap memory.
Hi Ankit,

Would you please describe issue like it is due to application or anything else so that other might know regarding this which might help in future?

Re: WiFi Stack heap memory usage

Posted: Wed Aug 08, 2018 1:11 pm
by Ankit Siddhapura
Hi Ankit,

Would you please describe issue like it is due to application or anything else so that other might know regarding this which might help in future?
Okay!

I was facing issue with beacon timeout and station disconnection with parent AP.
Among several reason for disconnection are if AP change its channel and switch to new channel at this time STA may get channel switch event. Another reason is Authentication mode change or STA miss N number of beacon then AP kicks off station from station list.

Here, I faced issue with memory leak, In my application missed to free dynamic allocated memory. So on every packet transmission heap memory decreased and when reached to <3000 bytes, stack generated beacon timeout because did not find sufficient memory to for probe response.

How I resolved the issue :
After several test I got doubt on memory leak. So, By tracing heap size using xPortGetFreeHeapSize() API i knew heap size is decreasing.
When it reached to less then around 3000 bytes issue reproduced. by fixing memory leak in application fixed this issue.

Thank You!

Re: WiFi Stack heap memory usage

Posted: Wed Aug 08, 2018 1:32 pm
by Ritesh
Ankit Siddhapura wrote:
Hi Ankit,

Would you please describe issue like it is due to application or anything else so that other might know regarding this which might help in future?
Okay!

I was facing issue with beacon timeout and station disconnection with parent AP.
Among several reason for disconnection are if AP change its channel and switch to new channel at this time STA may get channel switch event. Another reason is Authentication mode change or STA miss N number of beacon then AP kicks off station from station list.

Here, I faced issue with memory leak, In my application missed to free dynamic allocated memory. So on every packet transmission heap memory decreased and when reached to <3000 bytes, stack generated beacon timeout because did not find sufficient memory to for probe response.

How I resolved the issue :
After several test I got doubt on memory leak. So, By tracing heap size using xPortGetFreeHeapSize() API i knew heap size is decreasing.
When it reached to less then around 3000 bytes issue reproduced. by fixing memory leak in application fixed this issue.

Thank You!
Thanks for update.