From patchwork Thu Feb 18 00:08:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Tan X-Patchwork-Id: 10615 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 6F3719A8E; Thu, 18 Feb 2016 08:09:08 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id B49969A88 for ; Thu, 18 Feb 2016 08:09:06 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP; 17 Feb 2016 23:09:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,464,1449561600"; d="scan'208";a="49981176" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by fmsmga004.fm.intel.com with ESMTP; 17 Feb 2016 23:09:04 -0800 From: Jianfeng Tan To: dev@dpdk.org Date: Thu, 18 Feb 2016 08:08:39 +0800 Message-Id: <1455754119-121572-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] example/vhost: fix failed to allocate mbufs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" How to reproduce: 1. Start vhost-switch ./examples/vhost/build/vhost-switch -c 0x3 -n 4 -- -p 1 --stat 0 2. Start VM with a virtio port $ $QEMU -smp cores=2,sockets=1 -m 4G -cpu host -enable-kvm \ -chardev socket,id=char1,path= \ -device virtio-net-pci,netdev=vhostuser1 \ -netdev vhost-user,id=vhostuser1,chardev=char1 -object memory-backend-file,id=mem,size=4G,mem-path=,share=on \ -numa node,memdev=mem -mem-prealloc \ -hda 3. Start l2fwd in VM $ ./examples/l2fwd/build/l2fwd -c 0x1 -n 4 -m 1024 -- -p 0x1 4. Use ixia to inject packets in a small data bit rate. Error: vhost-switch keeps printing error message: failed to allocate memory for mbuf. Root cause: How many mbufs allocated for a port is calculated by below formula. NUM_MBUFS_PER_PORT = ((MAX_QUEUES*RTE_TEST_RX_DESC_DEFAULT) + \ (num_switching_cores*MAX_PKT_BURST) + \ (num_switching_cores*RTE_TEST_TX_DESC_DEFAULT) +\ (num_switching_cores*MBUF_CACHE_SIZE)) We suppose num_switching_cores is 1 and MBUF_CACHE_SIZE is 128. And when initializing port, master core fills mbuf mempool cache, so there would be some left in that cache, for example 121. So total mbufs which can be used is: (MAX_PKT_BURST + MBUF_CACHE_SIZE - 121) = (32 + 128 - 121) = 39. What makes it worse is that there is a buffer to store mbufs (which will be tx_burst to physical port), if it occupies some mbufs, there will be possible < 32 mbufs left, so vhost dequeue prints out this msg. In all, it fails to include master core's mbuf mempool cache. Signed-off-by: Jianfeng Tan Reported-by: Qian Xu --- doc/guides/rel_notes/release_16_04.rst | 5 +++++ examples/vhost/main.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst index eb1b3b2..09fa8f7 100644 --- a/doc/guides/rel_notes/release_16_04.rst +++ b/doc/guides/rel_notes/release_16_04.rst @@ -56,6 +56,11 @@ This section should contain bug fixes added to the relevant sections. Sample for The title should contain the code/lib section like a commit message. Add the entries in alphabetic order in the relevant sections below. +* **examples/vhost: fix failed to allocate mbuf.** + + vhost-switch often fails to allocate mbuf when dequeue from vring because it + wrongly calculate the number of mbufs needed. + EAL ~~~ diff --git a/examples/vhost/main.c b/examples/vhost/main.c index e08f451..a97300b 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -70,7 +70,7 @@ #define NUM_MBUFS_PER_PORT ((MAX_QUEUES*RTE_TEST_RX_DESC_DEFAULT) + \ (num_switching_cores*MAX_PKT_BURST) + \ (num_switching_cores*RTE_TEST_TX_DESC_DEFAULT) +\ - (num_switching_cores*MBUF_CACHE_SIZE)) + ((num_switching_cores+1)*MBUF_CACHE_SIZE)) #define MBUF_CACHE_SIZE 128 #define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE