DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev]  possible kni bug and proposed fix
@ 2016-05-15  4:48 ALeX Wang
  2016-05-16 11:20 ` Ferruh Yigit
  0 siblings, 1 reply; 5+ messages in thread
From: ALeX Wang @ 2016-05-15  4:48 UTC (permalink / raw)
  To: dev

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,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-17 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-15  4:48 [dpdk-dev] possible kni bug and proposed fix ALeX Wang
2016-05-16 11:20 ` Ferruh Yigit
2016-05-16 15:31   ` ALeX Wang
2016-05-17 10:07     ` Ferruh Yigit
2016-05-17 17:09       ` ALeX Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).