Custom placement of memory pool

classic Classic list List threaded Threaded
6 messages Options
uaz
Reply | Threaded
Open this post in threaded view
|

Custom placement of memory pool

uaz
Hi all,

I'm currently running lwip v2.0.3 on LPC4357 platform.
I have some issue with pbuf mem_alloc(), which I believe is fragmentation
issue because after several packet transfers, I'm unable to allocate pbuf
anymore.

Right now I'm switching to custom memory pool approach, but I'm consuming
more SRAM than available, thus the project is not compiling.

Is there any way to manually place memory pool to a certain address?

Thanks,
UAZ



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Custom placement of memory pool

Giuseppe Modugno
Il 09/11/2018 04:05, uaz ha scritto:
> Hi all,
>
> I'm currently running lwip v2.0.3 on LPC4357 platform.
> I have some issue with pbuf mem_alloc(), which I believe is fragmentation
> issue because after several packet transfers, I'm unable to allocate pbuf
> anymore.

I don't know if it is the same problem I faced some months ago with the
MCU LPC1769.

I found a behaviour similar to the one you are describing. After some
HTTP requests (received and answered correctly), no more HTTP requests
are possible. Consider that the problem appeared only with HTTP requests
that needed custom file (as internal lwip http server nomenclature).

The solution I found is defining MEMP_MEM_MALLOC to *0/zero* (it was set
to 1/one). When set, this macro enables mem_malloc/mem_free for pools
management (so dynamic management instead of static management). In my
case, mem_malloc/mem_free are effectively malloc/free of newlib C
standard library (because I defined MEM_LIBC_MALLOC to 1).

Here[1] you read the definition of MEMP_MEM_MALLOC macro:

> MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool
> allocator. Especially useful with MEM_LIBC_MALLOC but handle with care
> regarding execution speed (heap alloc can be much slower than pool
> alloc) and usage from interrupts (especially if your netif driver
> allocates PBUF_POOL pbufs for received frames from interrupt)!
> ATTENTION: Currently, this uses the heap for ALL pools (also for
> private pools, not only for internal pools defined inmemp_std.h
> <http://www.nongnu.org/lwip/2_0_x/memp__std_8h.html>)!
I think the NXP Ethernet driver implementation isn't compatible with
MEMP_MEM_MALLOC. Anyway I'm not sure, because the problem happens only
for "custom file" http requests and not for every request.

[1]
http://www.nongnu.org/lwip/2_0_x/group__lwip__opts__mem.html#gae93af697d27bbcefa6a28052d90f2f38

>
> Right now I'm switching to custom memory pool approach, but I'm consuming
> more SRAM than available, thus the project is not compiling.
>
> Is there any way to manually place memory pool to a certain address?
>
> Thanks,
> UAZ
>
>
>
> --
> Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Custom placement of memory pool

Dirk Ziegelmeier-2
In reply to this post by uaz
To relocate a pool, see:


"To relocate a pool, declare it as extern in cc.h. Example for GCC: extern u8_t __attribute__((section(".onchip_mem"))) memp_memory_my_private_pool_base[];"

HTH
Dirk


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
uaz
Reply | Threaded
Open this post in threaded view
|

Re: Custom placement of memory pool

uaz
Hi Dirk,

Thanks for the heads up. I lost focus because I was drowning in the macros.

Ok, now I understand that I can define my own memory pool at custom address.

But how about pbuf buffers? Is it possible to relocate them to different
address?

Now I get confused with pbuf pool (PBUF_POOL_SIZE) with the memp custom pool
(MEMP_USE_CUSTOM_POOLS).
Does it mean that:
- if I set MEMP_USE_CUSTOM_POOLS to 1, I can set PBUF_POOL_SIZE to 0 because
memp_malloc() will look for available slot from the custom pool instead of
pbuf pool?

Regards,
UAZ



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Custom placement of memory pool

Dirk Ziegelmeier-2
Yes, in exactly the same way - just figure out the name of the PBUF pool (see linker map file) and add an external with appropriate GCC attribute to cc.h

Dirk


On Fri, Nov 9, 2018 at 3:14 PM uaz <[hidden email]> wrote:
Hi Dirk,

Thanks for the heads up. I lost focus because I was drowning in the macros.

Ok, now I understand that I can define my own memory pool at custom address.

But how about pbuf buffers? Is it possible to relocate them to different
address?

Now I get confused with pbuf pool (PBUF_POOL_SIZE) with the memp custom pool
(MEMP_USE_CUSTOM_POOLS).
Does it mean that:
- if I set MEMP_USE_CUSTOM_POOLS to 1, I can set PBUF_POOL_SIZE to 0 because
memp_malloc() will look for available slot from the custom pool instead of
pbuf pool?

Regards,
UAZ



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Custom placement of memory pool

Nathan Hartman
In reply to this post by uaz
On Thu, Nov 8, 2018 at 11:57 PM uaz <[hidden email]> wrote:
Hi all,

I'm currently running lwip v2.0.3 on LPC4357 platform.
I have some issue with pbuf mem_alloc(), which I believe is fragmentation
issue because after several packet transfers, I'm unable to allocate pbuf
anymore.

I once had a problem with lwIP not responding after a few packets which IIRC turned out to be caused by forgetting to deallocate pbufs. You might want to double check that you don't have a similar mistake.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users