examples/vhost: fix mbuf allocation failure
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Mon, 2 May 2016 21:23:48 +0000 (14:23 -0700)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 10 May 2016 18:22:40 +0000 (20:22 +0200)
commitbdb19b771e6f849d828d34aff48c91c6a3030fe0
tree28d306e870cd10989b1889e45b5f34d548974b31
parent9c5ef51207c62d3a2edb01cbd2a81ea61f5d37bd
examples/vhost: fix mbuf allocation failure

It has always been a mystery (at least to me before) that how many
mbuf is enough while creating an mbuf pool. While current macro
NUM_MBUFS_PER_PORT gives your some insights, it's not that accurate:
it doesn't consider the case we may receive a big packet, say 64K
when TSO is enabled.

We actually have tried to fix it once before, with commit 5499c1fc9baa
("examples/vhost: fix mbuf allocation"), but it just workarounded it
by enlarging it a bit so that the case described in the commit log
by passes. So, while trying to fix it ultimately, I'm thinking how
big is big enough, and what are the factors need consider to figure
out a proper value.

Therefore, here you are. I introduced a helper function to create
the mbuf pool, and do the "how many mbufs are needed" calculation
there. Also, I put detailed comments how that comes, to serve as
the guidelines.

Fixes: 9fd72e3cbd29 ("examples/vhost: add virtio offload")
Fixes: 5499c1fc9baa ("examples/vhost: fix mbuf allocation")

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
examples/vhost/main.c