Skip to content

Commit

Permalink
kni: fix mbuf allocation for kernel side use
Browse files Browse the repository at this point in the history
[ upstream commit 0db3d55 ]

In kni_allocate_mbufs(), we alloc mbuf for alloc_q as this code.
allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1) \
		& (MAX_MBUF_BURST_NUM - 1);
The value of allocq_free maybe zero, for example :
The ring size is 1024. After init, write = read = 0. Then we fill
kni->alloc_q to full. At this time, write = 1023, read = 0.

Then the kernel send 32 packets to userspace. At this time, write
= 1023, read = 32. And then the userspace receive this 32 packets.
Then fill the kni->alloc_q, (32 - 1023 - 1) & 31 = 0, fill nothing.
...
Then the kernel send 32 packets to userspace. At this time, write
= 1023, read = 992. And then the userspace receive this 32 packets.
Then fill the kni->alloc_q, (992 - 1023 - 1) & 31 = 0, fill nothing.

Then the kernel send 32 packets to userspace. The kni->alloc_q only
has 31 mbufs and will drop one packet.

Absolutely, this is a special scene. Normally, it will fill some
mbufs everytime, but may not enough for the kernel to use.

In this patch, we always keep the kni->alloc_q to full for the kernel
to use.

Fixes: 49da4e8 ("kni: allocate no more mbuf than empty slots in queue")

Signed-off-by: Cheng Liu <liucheng11@huawei.com>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
  • Loading branch information
wyjwang authored and bluca committed Jul 12, 2021
1 parent 619944d commit 1728466
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/librte_kni/rte_kni.c
Expand Up @@ -677,8 +677,9 @@ kni_allocate_mbufs(struct rte_kni *kni)
return;
}

allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1)
& (MAX_MBUF_BURST_NUM - 1);
allocq_free = kni_fifo_free_count(kni->alloc_q);
allocq_free = (allocq_free > MAX_MBUF_BURST_NUM) ?
MAX_MBUF_BURST_NUM : allocq_free;
for (i = 0; i < allocq_free; i++) {
pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool);
if (unlikely(pkts[i] == NULL)) {
Expand Down

0 comments on commit 1728466

Please sign in to comment.