Skip to content

Commit

Permalink
lib/net: review the size of mbuf pools
Browse files Browse the repository at this point in the history
This commit fixes two miscalculations in the size of mbuf pools:

1. calculate_mempool_config_para() was not accounting for
multiple members in bonded interfaces; and

2. Although unlikely, a GK or GT instance might receive all
the packets, so the instances must account for this worst case.
  • Loading branch information
AltraMayor committed May 21, 2024
1 parent ce3864d commit df1d243
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
8 changes: 6 additions & 2 deletions gk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2541,9 +2541,13 @@ gk_stage1(void *arg)

num_mbuf = calculate_mempool_config_para("gk", gk_conf->net,
gk_conf->front_max_pkt_burst + gk_conf->back_max_pkt_burst +
/*
* One cannot divide the sum below per gk_conf->num_lcores
* because, though unlikely, it might happen that
* all packets go to a single instance.
*/
(gk_conf->net->front.total_pkt_burst +
gk_conf->net->back.total_pkt_burst + gk_conf->num_lcores - 1) /
gk_conf->num_lcores);
gk_conf->net->back.total_pkt_burst));

sol_conf = gk_conf->sol_conf;
for (i = 0; i < gk_conf->num_lcores; i++) {
Expand Down
8 changes: 6 additions & 2 deletions gt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,8 +2067,12 @@ init_gt_instances(struct gt_config *gt_conf)
gt_conf->net, gt_conf->max_pkt_burst +
gt_conf->frag_max_entries + gt_conf->max_pkt_burst +
gt_conf->max_ggu_notify_pkts +
(gt_conf->net->front.total_pkt_burst +
gt_conf->num_lcores - 1) / gt_conf->num_lcores);
/*
* One cannot divide the sum below per gt_conf->num_lcores
* because, though unlikely, it might happen that
* all packets go to a single instance.
*/
gt_conf->net->front.total_pkt_burst);

/* Set up queue identifiers now for RSS, before instances start. */
for (i = 0; i < gt_conf->num_lcores; i++) {
Expand Down
43 changes: 30 additions & 13 deletions lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2234,25 +2234,42 @@ start_iface(struct gatekeeper_if *iface)
return ret;
}

static inline uint32_t
if_rx_desc(const struct gatekeeper_if *iface)
{
return (uint32_t)iface->num_ports * iface->num_rx_desc;
}

static inline uint32_t
if_tx_desc(const struct gatekeeper_if *iface)
{
return (uint32_t)iface->num_ports * iface->num_tx_desc;
}

unsigned int
calculate_mempool_config_para(const char *block_name,
struct net_config *net_conf, unsigned int total_pkt_burst)
{
unsigned int num_mbuf;

/*
* The total number of receive descriptors to
* allocate per lcore for the receive ring over all interfaces.
* The total number of receive descriptors to allocate per lcore
* for the receive ring of the front interface.
*/
uint16_t total_rx_desc = net_conf->front.num_rx_desc +
(net_conf->back_iface_enabled ? net_conf->back.num_rx_desc : 0);
uint32_t total_rx_desc = if_rx_desc(&net_conf->front);

/*
* The total number of transmit descriptors to
* allocate per lcore for the transmit ring over all interfaces.
* The total number of transmit descriptors to allocate per lcore
* for the transmit ring of the front interface.
*/
uint16_t total_tx_desc = net_conf->front.num_tx_desc +
(net_conf->back_iface_enabled ? net_conf->back.num_tx_desc : 0);
uint32_t total_tx_desc = if_tx_desc(&net_conf->front);

uint32_t max_num_pkt;
unsigned int num_mbuf;

if (net_conf->back_iface_enabled) {
/* Account for the back interface. */
total_rx_desc += if_rx_desc(&net_conf->back);
total_tx_desc += if_tx_desc(&net_conf->back);
}

/*
* The number of elements in the mbuf pool.
Expand All @@ -2261,16 +2278,16 @@ calculate_mempool_config_para(const char *block_name,
* It's the number of RX descriptors, the number of TX descriptors,
* and the number of packet burst buffers.
*/
uint32_t max_num_pkt = total_rx_desc + total_tx_desc + total_pkt_burst;
max_num_pkt = total_rx_desc + total_tx_desc + total_pkt_burst;

/*
* The optimum size (in terms of memory usage) for a mempool is when
* it is a power of two minus one.
*/
num_mbuf = rte_align32pow2(max_num_pkt) - 1;

G_LOG(NOTICE, "%s: %s: total_pkt_burst = %hu packets, total_rx_desc = %hu descriptors, total_tx_desc = %hu descriptors, max_num_pkt = %u packets, num_mbuf = %u packets.\n",
block_name, __func__, total_pkt_burst, total_rx_desc,
G_LOG(NOTICE, "%s(%s): total_pkt_burst = %u packets, total_rx_desc = %u descriptors, total_tx_desc = %u descriptors, max_num_pkt = %u packets, num_mbuf = %u packets\n",
__func__, block_name, total_pkt_burst, total_rx_desc,
total_tx_desc, max_num_pkt, num_mbuf);

return num_mbuf;
Expand Down

0 comments on commit df1d243

Please sign in to comment.