[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] memory pools question

From: Artem Pisarenko
Subject: Re: [lwip-users] memory pools question
Date: Fri, 16 Nov 2012 19:11:32 +0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2


I need help again.
After I configured lwipopts.h in right way(I thought I did), it turned out that lwip need LWIP_MALLOC_MEMPOOLs. Furthermore, their sizes are unknown for me. I was able to count every regular pool (type-defined) but these ones somehow required by TCP windowing and retransmissions mechanisms. I have no idea what sizes they should be ?

Generally speaking, pools always imply that their sizes must be calculable by developer to make sure they will match memory usage pattern of application and fulfill memory constraints. Lwip pools are completely mysterious for developer not delved into the innards of lwip. Even for me, after I spent few months having analysis of lwip code from time to time. This makes pools unusable despite the fact they already implemented. I suggest most developers (including me) use random values at this moment. Pools purpose is that they should protect application from memory fragmentation which leads to failure. But lwip pools configured to random values may cause "out of memory" error which leads to absolutelly same failure.

Please, somebody throw light upon this subject once more :)

Regards, Artem.

25.01.2012 13:52, Simon Goldschmidt wrote:
jblackarty <address@hidden> wrote:
It's totally unclear are mem and memp independent mechanisms, or mem
utilizes memp, or memp uses mem, or they are cross-references each
other ? Custom pools are part of pools (memp), or pools are part of
custom pools ?

There are complicated set of options:
Yes, that's the nature of lwIP being adjustable to the needs of your (possibly 
small or otherwise restricted) target hardware.

I'll start explaining the 'standard' options. Basically, lwIP has 2 strategies 
for memory allocation: pools and a heap. The heap is mainly only used for 
outgoing PBUFs allocated with the type PBUF_RAM. Then there is one memory pool 
per structure type:

These control the amount of structures of that type (e.g. MEMP_NUM_UDP_PCB sets 
the amount of available udp connections).

This is the size of the heap (used for PBUF_RAM allocation).

As it says in opt.h (did you read that file???), the number of pbufs in the 
pbuf pool (where PBUF_POOL_BUFSIZE controls the size of these pbufs). The pbufs 
from the pool are of type PBUF_POOL.

Nnow to the more advanced options:

Some people don't care about the danger of heap fragmentation and want to use 
the C library's malloc/free functions instead of the lwIP-internal memory 
allocation (if only to save code because the C library's functions are included 
in their binary, anyway). Set this to 1 to do so.

This is mainly only usefule with the previous option: when set to 1, memp pool 
allocation uses the heap allocation functions (this was introduced to let memp 
allocations be using the C library's malloc.

This is the other way round than the previous: when you're scared of heap 
fragmentation, let mem_malloc() allocate from specific pools. The size of these 
pools (and the number of entries in them) needs to be configured *and* you have 
to enable the next option.

This enables custom memp pools. They are needed for the previous option but you 
can also define more pools, for example to put your semaphores or mboxes into.

How they related to each other ?
For MEMP_MEM_MALLOC a comment says "Use mem_malloc/mem_free instead of
the lwip pool allocator.". But mem_malloc is part of pool mechanisms.
No, memp_malloc (not the 'p') allocates from pools, mem_malloc allocates from 
the heap!

How it can be disabled ? Also "Especially useful with MEM_LIBC_MALLOC
..." confuses. Isn't libc allocator completely disables pool mechanism
? These options must exclude each other.
No, why should they???

Is it possible disable allocating standard structs in pool at all ?
Yes, see above

Does it makes sense configure MEMP_NUM_* options if MEM_LIBC_MALLOC
enabled ?

MEM_SIZE includes only pool of standart structures or also pbufs pool ?
None of them. It controls the heap size and has nothing todo with pools.

Questions may be continued indefinitely.
Is that so?

lwip source code doesn't
describe architecture because it's heavily stuffed with complex macro
nested each in other.
lwIP relies on people's contribution, so if there's anything missing for a 
beginner, please don't hesitate to contribute. Writing something on the wiki is 
the easiest part to help future beginners getting started faster.

"Custom_memory_pools" article on wiki doesn't
help too because it doesn't describe whole memory mechanism completely.
Right, it only describes how to enable custom memory pools. I guess it's rather 
targeted at people already using lwIP as a guideline of how to get custom pools 

I will appreciate if someone throw light upon this subject.
Hope I did. :-)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]