From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f194.google.com (mail-yw0-f194.google.com [209.85.161.194]) by dpdk.org (Postfix) with ESMTP id B80569AB6 for ; Sun, 15 May 2016 06:48:11 +0200 (CEST) Received: by mail-yw0-f194.google.com with SMTP id y6so15635198ywe.0 for ; Sat, 14 May 2016 21:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=0d8pJ7CQLsf9EXbvTjMfpssaBeUE3TaXpVHtxFXu/xE=; b=WcZeXUM/HPIJUpleZM0amSSuLyud8oQso5xwE26BOnNPvBZI26yieY/UY+lnbinXWZ o1pFkQ/B+xVgoOmjQ9E8LWLC9mnHylDiGGv9h5bHGcd+ARlLevSxc2vPvFxkZXDM/2Kd H5uJMUmJzGpO5d9AGJTl6z+vD9WdxXQRqS7N30Wx/AKFRwC4NDgWWxp9eppokvAa3FBA YI76fdo7kwN95QDidnx7ebNZc8gjciECTxherpGPSIzJHacf5RHvUWpWs5I2XYp9pJVa CZr6Leqq7269WOF1n0ucY/NBRi0ANwbvRYj7P2eR+Tot08X7xo0gsMYjxFg+JDN6FRHJ tHqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=0d8pJ7CQLsf9EXbvTjMfpssaBeUE3TaXpVHtxFXu/xE=; b=KCC7dqOijfvLLd399JM6orDlCzQKr9xA0Hs1MzckdZNbwfotkk7GSPkuJFKM6BVxhp 4Pd3/g9rECBh477ba7pK3tYNQPLbekNq0sPsWZ9OVsw8PVoNkoivFpXOnCIauLCO34dW pFwkkLydBSIaC+1cKm4L1bVlfIOoL2o+HkpeKF8FkxLJGEAh9ju1RCzfzFU9iIpb1WYC YpjqWYu6KD/8+0gp/sIDDpDtYDi5Dq0NB5im+cNnkwApIB4Qg/AI9V/Sz3k1f02jhD+Z Crgy6kaNhYflmNBaTKtIlGpaeCGpsFqQu/RTbsb7IZ5cPPzRU2f5jHhFTKz1JveOtE+i qyUA== X-Gm-Message-State: AOPr4FXpnuoxYcEu6aQXG6slefmjdOuKffcR9FoATN3Ogj1J7qp/iHonMA85kI9SWjdn9bAjbW4Jo2wit5lStw== MIME-Version: 1.0 X-Received: by 10.37.11.216 with SMTP id 207mr11291798ybl.184.1463287691191; Sat, 14 May 2016 21:48:11 -0700 (PDT) Received: by 10.129.70.194 with HTTP; Sat, 14 May 2016 21:48:11 -0700 (PDT) Date: Sat, 14 May 2016 21:48:11 -0700 Message-ID: From: ALeX Wang To: dev@dpdk.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] possible kni bug and proposed fix 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: , X-List-Received-Date: Sun, 15 May 2016 04:48:12 -0000 Hi, When using the kni module to test my application inside debian (virtualbox) VM (kernel version 4.4), I get the "KNI: Out of memory" from syslog every time I `tcpreply` packets through the kni interface. After checking source code, I saw that when I call 'rte_kni_rx_burst()', no matter how many packets are actually retrieved, we always call 'kni_allocate_mbufs()' and try allocate 'MAX_MBUF_BURST_NUM' more mbufs... I fix the issue via using this patch below, Could you confirm if this is an actual bug? diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index ea9baf4..5d7c1ce 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -129,6 +129,7 @@ struct rte_kni_memzone_pool { static void kni_free_mbufs(struct rte_kni *kni); static void kni_allocate_mbufs(struct rte_kni *kni); +static void kni_allocate_n_mbufs(struct rte_kni *kni, int size); static volatile int kni_fd = -1; static struct rte_kni_memzone_pool kni_memzone_pool = { @@ -556,7 +557,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num) /* If buffers removed, allocate mbufs and then put them into alloc_q */ if (ret) - kni_allocate_mbufs(kni); + kni_allocate_n_mbufs(kni, (int)ret); return ret; } @@ -577,6 +578,12 @@ kni_free_mbufs(struct rte_kni *kni) static void kni_allocate_mbufs(struct rte_kni *kni) { + kni_allocate_n_mbufs(kni, MAX_MBUF_BURST_NUM); +} + +static void +kni_allocate_n_mbufs(struct rte_kni *kni, int size) +{ int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; @@ -595,13 +602,18 @@ kni_allocate_mbufs(struct rte_kni *kni) RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) != offsetof(struct rte_kni_mbuf, ol_flags)); + if (size > MAX_MBUF_BURST_NUM) { + RTE_LOG(ERR, KNI, "Invalid mbufs size\n"); + return; + } + /* Check if pktmbuf pool has been configured */ if (kni->pktmbuf_pool == NULL) { RTE_LOG(ERR, KNI, "No valid mempool for allocating mbufs\n"); return; } - for (i = 0; i < MAX_MBUF_BURST_NUM; i++) { + for (i = 0; i < size; i++) { pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool); if (unlikely(pkts[i] == NULL)) { /* Out of memory */ Thanks, -- Alex Wang,