[lwip-users] MEM_SIZE seems to small for TCP_MSS, PBUF_POOL_BUFSIZE
Hello, I'm using STMicroelectronics's CubeMX which generates RTOS+LwIP code. I have following in opt.h: #define MEM_SIZE 2000 #define TCP_MSS 536 #define TCP_SND_BUF (2 * TCP_MSS) #define TCP_SND_QUEUELEN 9 #define PBUF_POOL_SIZE16 #define PBUF_POOL_BUFSIZE TCP_MSS+40+0+14+4-1 // tailored this formula, 593 and then align It looks like: a) 16 * 593 = 9488 is way bigger than 2000 b) 2 * TCP_MSS * 9 = 9648 is also bigger than 2000 I'm concerned especially about pbuf pool. It looks like a plainly preallocated thing, pool size times pool element size, thats all – 9.2 kB of memory to be used. Send buffer and queue looks similar. Am I right and MEM_SIZE should be bigger? -- Best regards, Sebastian Gniazdowski ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Il 15/03/2018 11:28, Simon Goldschmidt ha scritto: Giuseppe Modugno wrote: [..] I think with the following options: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 1 #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ It's MEMP_USE_CUSTOM_POOLS, not MEM_USE_CUSTOM_POOLS. It was a typo. And it compiles for me, see the win32 port for an example. Yes, now it compiles without errors. The file lwippools.h lacked the LWIP_MALLOC_MEMPOOL macros to define the set of pools used by lwip in case MEM_USE_POOLS is set. ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Giuseppe Modugno wrote: > [..] > I think with the following options: > > #define MEM_LIBC_MALLOC 0 > #define MEM_USE_POOLS 1 > #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ It's MEMP_USE_CUSTOM_POOLS, not MEM_USE_CUSTOM_POOLS. And it compiles for me, see the win32 port for an example. Simon ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Giuseppe Modugno wrote: > [..] > In my case, I have a completely free (not used by the linker) 32kB RAM > region starting from 0x2007C000. To instruct lwip to use that region for > heap, I think I have to define: > > #define MEM_SIZE (32 * 1024 - 1 * SIZEOF_STRUCT_MEM) > #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) > > Supposing we don't need other additional space for alignment. > In this case the total free heap memory available for data is exactly > MEM_SIZE, that is less than 32kB. > > Is it correct? I think so, yes. However, your definition of MEM_SIZE won't compile outside of mem.c. Maybe it would be better to rework the code to use MEM_SIZE as size of the available block, at least if an external block is used... Simon ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Il 14/03/2018 16:42, Giuseppe Modugno ha scritto: I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. Another question regarding memory management of lwip. I understood lwip uses memory pools for many things (TCP pcbs, UDP pcbs, RAW pcb, timers and so on). The memory pools are defined in include/lwip/priv/memp_std.h. They aren't allocated from the heap, but from pools. I think because it is supposed they must be allocated frequently, so they could bring to fragmentation and the allocation should be fast. Does lwip use strictly heap (mem_malloc) for its own purposes? It seems yes (I see some mem_malloc calls in httpd, dhcp, pbuf, ...). Is it possible to compile lwip so it doesn't use heap at all? I think with the following options: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 1 #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ In this way, heap implementation isn't a real heap, but a set of different-sized pools. This set is defined in arhc/lwippools.h. Is it correct? I tried to compile with this options, but I have this error (for example compiling memp.c): mingw32-gcc.exe -Wall -std=c11 -Wall -pedantic -Wparentheses -Wsequence-point -Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wold-style-definition -Wcast-align -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Wno-address -Wunreachable-code -Wuninitialized -Wlogical-op -Wno-format -g -DLWIP_DEBUG -DDEBUG -Isrc\lwip\src\include -Isrc -Isrc\ports\mingw\lwip_arch -Isrc\ports\mingw -Isrc\bus -Isrc\WpdPack\Include -I..\..\..\work_git -Isrc\lwip\src\include\lwip\apps -c C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c -o mingw\Debug\src\lwip\src\core\memp.o In file included from src\lwip\src\include/lwip/memp.h:58:0, from C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c:48: src\lwip\src\include/lwip/priv/memp_priv.h:89:5: error: expected expression before ')' token ) , ^ ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Il 14/03/2018 20:26, goldsi...@gmx.de ha scritto: On 14.03.2018 16:42, Giuseppe Modugno wrote: I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. Is that a question? Or an action request? It was a question, even if I forgot to add a question mark :-) To my understanding, the comment above #ifndef LWIP_RAM_HEAP_POINTER in mem.c clearly states that enough memory is required. It does NOT say that amount is MEM_SIZE. If you want, create a patch with a better documentation and we could apply it. Ah ok, I now understand the comment "we need one struct mem at the end and some room for alignment". MEM_SIZE isn't the total available memory for heap management (including accessory structs), but it is the *useful* memory space the application needs for the heap (excluding accessory structs). For example, if MEM_SIZE is 1024, I can be sure one malloc(1024) won't fail. In my case, I have a completely free (not used by the linker) 32kB RAM region starting from 0x2007C000. To instruct lwip to use that region for heap, I think I have to define: #define MEM_SIZE (32 * 1024 - 1 * SIZEOF_STRUCT_MEM) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) Supposing we don't need other additional space for alignment. In this case the total free heap memory available for data is exactly MEM_SIZE, that is less than 32kB. Is it correct? ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
On 14.03.2018 16:42, Giuseppe Modugno wrote: I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. Is that a question? Or an action request? To my understanding, the comment above #ifndef LWIP_RAM_HEAP_POINTER in mem.c clearly states that enough memory is required. It does NOT say that amount is MEM_SIZE. If you want, create a patch with a better documentation and we could apply it. Simon ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
[lwip-users] MEM_SIZE
I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users