xiaoxiang781216 commented on code in PR #7525: URL: https://github.com/apache/nuttx/pull/7525#discussion_r1038916855
########## net/tcp/tcp_conn.c: ########## @@ -836,10 +863,25 @@ void tcp_free(FAR struct tcp_conn_s *conn) } #endif - /* Mark the connection available and put it into the free list */ + /* Mark the connection available. */ conn->tcpstateflags = TCP_CLOSED; - dq_addlast(&conn->sconn.node, &g_free_tcp_connections); + + /* Check if this is a preallocated connection to store it in the free + * connections list, else deallocate it. + */ + +#ifdef CONFIG_NET_ALLOC_CONNS + if ((conn->flags & TCP_PREALLOC) == 0) + { + kmm_free(conn); Review Comment: > OK, we agree. (Especially on point 3!) > > The only issue is that this way preallocated connections will be always in BSS. This means that changing this value will have the effect of _moving_ the connection struct from BSS to heap (as it will be allocated if it is nevertheless needed). > > This may be a bit problematic in arch'es with multiple memory regions. > > It is not my favorite, but I can live with that. > We can allocate the preallocated conn from heap too, it is no much difference whether they come from .bss or heap. The more important thing is never return them to heap. > One thing that I don't truly like is the `alloc_conn` variable as it is used now (tcp_conn.c, line 628). I wanted to mark the connection as pre-allocated within `tcp_initialize()`, but the conn struct will be memset to 0 in line 735, so this information is lost. > > Do you have any suggestions for this? One simple approach is: 1. Don't preallocate conn in startup instead 2. Put conn to free list if free list is smaller than NET_TCP_PREALLOC_CONNS 3. Call kmm_free if the free list is larger than NET_TCP_PREALLOC_CONNS So, we don't need flag to distinguish whether conn is preallocate or not. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org