Skip to content

Commit 50ff91d

Browse files
pasisgalnoam
authored andcommitted
issue: 4315534 Remove TX buffer pre-allocation in LwIP
Pre-allocation was done only for PBUF_RAM buffers. Also, buffer allocation can trigger TX polling in corner cases. Removing the pre-allocated buffer avoids keeping extra buffer per socket. This can save resources in case of large buffers and big number of connections. Signed-off-by: Dmytro Podgornyi <[email protected]>
1 parent 4d5ec48 commit 50ff91d

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

src/core/lwip/tcp.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,6 @@ void tcp_pcb_init(struct tcp_pcb *pcb, u8_t prio, void *container)
972972
pcb->is_in_input = 0;
973973
pcb->enable_ts_opt = enable_ts_option;
974974
pcb->seg_alloc = NULL;
975-
pcb->pbuf_alloc = NULL;
976975
}
977976

978977
/**
@@ -1019,55 +1018,33 @@ void tcp_pcb_recycle(struct tcp_pcb *pcb)
10191018
tcp_tx_seg_free(pcb, pcb->seg_alloc);
10201019
pcb->seg_alloc = NULL;
10211020
}
1022-
if (pcb->pbuf_alloc) {
1023-
tcp_tx_pbuf_free(pcb, pcb->pbuf_alloc);
1024-
pcb->pbuf_alloc = NULL;
1025-
}
10261021
}
10271022

10281023
struct pbuf *tcp_tx_pbuf_alloc(struct tcp_pcb *pcb, u32_t length, pbuf_type type, pbuf_desc *desc,
10291024
struct pbuf *p_buff)
10301025
{
10311026
struct pbuf *p;
10321027

1033-
if (!pcb->pbuf_alloc || pcb->pbuf_alloc->type != type) {
1034-
1035-
// pbuf_alloc is not valid, we should allocate a new pbuf.
1036-
p = external_tcp_tx_pbuf_alloc(pcb, type, desc, p_buff);
1037-
if (!p) {
1038-
return NULL;
1039-
}
1040-
1041-
p->next = NULL;
1042-
p->type = type;
1043-
/* set reference count */
1044-
p->ref = 1;
1045-
/* set flags */
1046-
p->flags = 0;
1047-
} else {
1048-
// pbuf_alloc is valid, we dont need to allocate a new pbuf element.
1049-
p = pcb->pbuf_alloc;
1050-
pcb->pbuf_alloc = NULL;
1028+
p = external_tcp_tx_pbuf_alloc(pcb, type, desc, p_buff);
1029+
if (!p) {
1030+
return NULL;
10511031
}
10521032

1053-
/* Set up internal structure of the pbuf. */
1033+
p->next = NULL;
1034+
p->type = type;
1035+
p->ref = 1;
1036+
p->flags = 0;
10541037
p->len = p->tot_len = length;
10551038

10561039
return p;
10571040
}
10581041

1059-
// Release preallocated buffers
10601042
void tcp_tx_preallocted_buffers_free(struct tcp_pcb *pcb)
10611043
{
10621044
if (pcb->seg_alloc) {
10631045
tcp_tx_seg_free(pcb, pcb->seg_alloc);
10641046
pcb->seg_alloc = NULL;
10651047
}
1066-
1067-
if (pcb->pbuf_alloc) {
1068-
tcp_tx_pbuf_free(pcb, pcb->pbuf_alloc);
1069-
pcb->pbuf_alloc = NULL;
1070-
}
10711048
}
10721049

10731050
void tcp_tx_pbuf_free(struct tcp_pcb *pcb, struct pbuf *p)

src/core/lwip/tcp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ struct tcp_pcb {
335335
#endif /* TCP_QUEUE_OOSEQ */
336336

337337
struct tcp_seg *seg_alloc; /* Available tcp_seg element for use */
338-
struct pbuf *pbuf_alloc; /* Available pbuf element for use */
339338

340339
/* Function to be called when data is acknowledged. */
341340
tcp_acked_fn acked_cb;

src/core/lwip/tcp_out.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,11 +1390,6 @@ err_t tcp_output(struct tcp_pcb *pcb)
13901390
pcb->seg_alloc = tcp_create_segment(pcb, NULL, 0, 0, 0);
13911391
}
13921392

1393-
if (!pcb->pbuf_alloc) {
1394-
// Fetch pbuf for the next packet.
1395-
pcb->pbuf_alloc = tcp_tx_pbuf_alloc(pcb, 0, PBUF_RAM, NULL, NULL);
1396-
}
1397-
13981393
return rc == ERR_WOULDBLOCK ? ERR_OK : rc;
13991394
}
14001395

0 commit comments

Comments
 (0)