[dpdk-dev] possible kni bug and proposed fix
ALeX Wang
ee07b291 at gmail.com
Sun May 15 06:48:11 CEST 2016
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,
More information about the dev
mailing list