Skip to content

Commit

Permalink
sock: fix nr_write_mbuf not updated on sock close
Browse files Browse the repository at this point in the history
nr_write_mbuf should be updated on sock close, when there are some
inflight pkts are going to be reclaimed.

Signed-off-by: Yuanhan Liu <[email protected]>
  • Loading branch information
yuanhanliu committed Dec 26, 2023
1 parent 98ee880 commit b24d456
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
8 changes: 5 additions & 3 deletions include/tx_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ struct tx_desc {
void *pkt;
} __attribute__((__aligned__(64)));

#define tx_desc_done(desc, pool) do { \
if ((desc)->flags & TX_DESC_FLAG_MEM_FROM_MBUF) \
#define tx_desc_done(desc, worker) do { \
if ((desc)->flags & TX_DESC_FLAG_MEM_FROM_MBUF) { \
packet_free(desc->pkt); \
worker->nr_write_mbuf -= 1; \
} \
if ((desc)->write_done) \
desc->write_done(desc->base, desc->param); \
tx_desc_free(pool, desc); \
tx_desc_free(worker->tx_desc_pool, desc); \
} while (0)


Expand Down
2 changes: 1 addition & 1 deletion src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static void reclaim_txq(struct tcp_sock *tsock)
break;

debug_assert(i <= tsock->txq.size);
tx_desc_done(desc, tsock->worker->tx_desc_pool);
tx_desc_done(desc, tsock->worker);
}

free(tsock->txq.descs);
Expand Down
5 changes: 1 addition & 4 deletions src/tcp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,8 @@ static inline int ack_sent_data(struct tpa_worker *worker, struct tcp_sock *tsoc
tsock_write_latency_update(tsock, desc, now);
}

if (desc->flags & TX_DESC_FLAG_MEM_FROM_MBUF)
worker->nr_write_mbuf -= 1;

nr_acked_pkt += 1;
tx_desc_done(desc, worker->tx_desc_pool);
tx_desc_done(desc, worker);
} while (acked_len > 0);

/*
Expand Down
10 changes: 8 additions & 2 deletions test/unit/tcp_timeout_rto.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ static void test_tcp_timeout_rto_timeout(void)
}

/* TODO: speed up it */
tcp_cfg.retries = 3;
start_ts_us = worker->ts_us;
while (tsock->rto_shift < 3) {
while (tsock->rto_shift < tcp_cfg.retries) {
pkt = NULL;
assert(ut_tcp_output(&pkt, 1) <= 1); {
assert((uint32_t)(tsock->snd_nxt - tsock->snd_una) == sizeof(buf));
Expand All @@ -96,7 +97,12 @@ static void test_tcp_timeout_rto_timeout(void)
}
}

ut_close(tsock, CLOSE_TYPE_4WAY);
ut_close(tsock, CLOSE_TYPE_CLOSE_DIRECTLY);
/*
* make sure nr_write_mbuf is updated correctly
* after sock txq reclaim.
*/
assert(worker->nr_write_mbuf == 0);
}

/*
Expand Down

0 comments on commit b24d456

Please sign in to comment.