cancel
Showing results for 
Search instead for 
Did you mean: 

Ethernet TCP Multi server/client memory dependacy

sarun
Associate III

My work

I have been experimenting with ethernet with tcp server, and i got some good referance to start the basic level of communication from the follwoing pages.

  1. https://controllerstech.com/stm32-ethernet-4-tcp-server/
  2. https://community.st.com/t5/stm32-mcus/how-to-create-a-project-for-stm32h7-with-ethernet-and-lwip-stack/ta-p/49308

What i have done

  • Based on this iam experimenting on server, on the controller iam able to do the communication with 9 server @100ms with 100bytes of data. 
  • For the server side when client sends some data server return 100 bytes of data
  • For client side iam using winscok on visual studio, here iam initilizing same number of clients as in the server and transmitting data at 100ms (100 bytes)
  • Observed packets through waveshark and there is no packet corruption
  • From the above referances some of the modification i have done is initilizing multiple instacnes at a time and pbuf and payload memory allocation at the time of connection accept, berfore it was done  when data is being transmitted.

What i want to do

Planning to push it to maximum number of server that i can do communication simultaneously (upto 50).

Issue i faced

When increasing the number of instance intitilized, during communication controller will either run into hardfault or on the client side transmission will fail, from this i have learnt it is because of wrong memory configuration.

Currently my configuration is able to run on a maximum number of 9 clients at a time.

Assist i need

Still it is unclear to me what are the paramter that will have an impact on number of instances, especially on the memory configuration side

Update

Iam able to run the 50 server simultaneously, for optimizing memmory i want to understand the exact memory configuration required.

My Findings and configurations

Correct me if iam wrong, each instance requires there own tx and rx descriptors for simultaneous communication minimum 96 bytes for each.

Pbuf is for handling all the incoming and outgoing data which highly depends on the number of bytes incoming

Rx pool i dont have a clear differenciation on this with Pbuf,

 

The configurations are based on the referance from the above link, and i have modified some parameters which thought necessary for increasing the number of instancs.

sarun_0-1721100848481.pngsarun_1-1721100892615.png

 

sarun_2-1721100953784.pngsarun_3-1721100972143.png

sarun_4-1721101018129.png

MPU configuration

sarun_5-1721101082484.png

Linker configuration

RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K

.lwip_sec (NOLOAD) :

{
. = ABSOLUTE(0x30000000);

*(.RxDecripSection)

. = ABSOLUTE(0x30001400);

*(.TxDecripSection)

. = ABSOLUTE(0x30002800);

*(.Rx_PoolSection)

} >RAM_D2

I want to have have a clear understanding of the memory configuration parameters, if you have any answer/referarances I would appreciate your assistance.

1 ACCEPTED SOLUTION

Accepted Solutions
STea
ST Employee

Hello @sarun ,

lwip heap memory size is the amount of memory allocated for the lwip stack to handle network data. It can be configured by the macro MEM_SIZE, which defines the size of the heap memory in bytes. The default value of MEM_SIZE is 1600 bytes, but it can be increased if the application sends a lot of data that needs to be copied. The heap memory can also be assigned to a specific region by using the macro LWIP_RAM_HEAP_POINTER, which points to the start address of the heap memory.

Each TCP PCB consumes a certain amount of memory. Increasing MEMP_NUM_TCP_PCB will directly increase the memory usage of the lwIP stack. This includes memory for the PCB structures themselves and associated buffers for data transmission and reception.
lwIP uses memory pools for various structures, including PCBs. Increasing the number of PCBs will require larger memory pools, which can lead to higher static memory allocation.
to summarize memory usage with Ethernet is divided by DMA descriptors and Tx/Rx buffers followed by the Lwip Heap which may vary in size but needs to respect your physical memory boundaries and RAM sizes ... 
you can also get a deeper understanding of the memory requirement in this link .
Regards

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
STea
ST Employee

Hello @sarun ,

lwip heap memory size is the amount of memory allocated for the lwip stack to handle network data. It can be configured by the macro MEM_SIZE, which defines the size of the heap memory in bytes. The default value of MEM_SIZE is 1600 bytes, but it can be increased if the application sends a lot of data that needs to be copied. The heap memory can also be assigned to a specific region by using the macro LWIP_RAM_HEAP_POINTER, which points to the start address of the heap memory.

Each TCP PCB consumes a certain amount of memory. Increasing MEMP_NUM_TCP_PCB will directly increase the memory usage of the lwIP stack. This includes memory for the PCB structures themselves and associated buffers for data transmission and reception.
lwIP uses memory pools for various structures, including PCBs. Increasing the number of PCBs will require larger memory pools, which can lead to higher static memory allocation.
to summarize memory usage with Ethernet is divided by DMA descriptors and Tx/Rx buffers followed by the Lwip Heap which may vary in size but needs to respect your physical memory boundaries and RAM sizes ... 
you can also get a deeper understanding of the memory requirement in this link .
Regards

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
sarun
Associate III

Hello @STea  Thanks for the replay,

I have done some digging and understood that

Descriptor Size :

  • The size of the memory  for Ethernet descriptors depends on the number of instances (client/server) that need to run simultaneously.
  • For a single client/server, the minimum descriptor size required is 96 bytes.

 RX Pool Configuration:

  • The RX pool (Receive Pool) must be configured to handle incoming data.

TX Data :

  • Outgoing data should be allocated outside of the RX pool . 

PBUF :

  • To handle data transmission and reception on the application side, pbuf structures are needed.
  • The number of pbuf structures and their sizes determine the rate of communication and the amount of data that can be transmitted and received at a time.

 

Memory Required For a single SOCKET is 156 bytes (tcp_pcb variable)

sarun_0-1721826327515.png

Amount of memmory required for a single client/server is= TX descriptor(fixed)+Rx descriptor(fixed)+socket size(fixed)+TXPbuf(variable)+RXPbuf

Here I am assuming a payload size of 110 bytes for transmitting and reception

96+96+156+110+110= 568 bytes

I  was following  that same referance you provided in the link and so far that is the only material i found to get some good inputs.

With the said understandings i was able to run 50 clients/servers in both TCP and UDP. Still i feel like more can be optimized and i will try to obtain more info.

Thanks for the input @STea 

and i have a small doubt are PCBs allocated in the LWIP heap?

STea
ST Employee

Hello @sarun ,

answering "and i have a small doubt are PCBs allocated in the LWIP heap?"
in fact, it is indeed allocated in the LWIP Heap using the tcp_alloc() function in for TCP as an example that function calls memp_malloc() which allocates memory in the LWIP Heap(dynamically).
Regards

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.