kni:optimization of rte_kni_rx_burst
PATCH 1/1 kni:optimization of rte_kni_rx_burst
From: Hemant Agrawal <[email protected]>
if any buffer is read from the tx_q, MAX_BURST buffers will be allocated and attempted to be added to to the alloc_q.
This seems terribly inefficient and it also looks like the alloc_q will quickly fill to its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.
This patch allocates the number of buffers as many dequeued from tx_q.
--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
lib/librte_kni/rte_kni.c +8 -5
@@ -128,7 +128,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_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ;static struct rte_kni_memzone_pool kni_memzone_pool = {
@@ -575,7 +575,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_mbufs (kni, ret);return ret; }
@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret;struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM ];
@@ -620,7 +620,10 @@ kni_allocate_mbufs(struct rte_kni *kni)return ; } -for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */
@@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free them */ -if (ret >=0 && ret < i && ret <MAX_MBUF_BURST_NUM ) { +if (ret >=0 && ret < i && ret < num) {int j;for (j = ret; j < i; j++)
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 14248648813214-git-send-email-Hemant-KZfg59tc24xl57MIdRCFDg@public.gmane.org
Thank you Hemant, I think there might be one issue left with the patch though. The alloc_q must initially be filled with mbufs before getting mbuf back on the tx_q.
So the patch should allow rte_kni_rx_burst to check if alloc_q is empty. If so, it should invoke kni_allocate_mbufs(kni, 0)
(to fill the alloc_q with MAX_MBUF_BURST_NUM mbufs)
The patch for rte_kni_rx_burst would then look like:
@@ -575,7 +575,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_mbufs(kni, ret);
+ else if (unlikely(kni->alloc_q->write == kni->alloc_q->read))
+ kni_allocate_mbufs(kni, 0);
Olivier.
Quoted 65 lines · Hemant Agrawal
From: Hemant Agrawal <[email protected]>
if any buffer is read from the
tx_q,MAX_BURSTbuffers will be allocated and attempted to be added to to thealloc_q.
This seems terribly inefficient and it also looks like thealloc_qwill quickly fill to its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.This patch allocates the number of buffers as many dequeued from
tx_q.Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)lib/librte_kni/rte_kni.c +8
-5@@ -128,7 +128,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_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ;static struct rte_kni_memzone_pool kni_memzone_pool = {@@ -575,7 +575,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_mbufs (kni, ret);return ret; }@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret;struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM ];@@ -620,7 +620,10 @@ kni_allocate_mbufs(struct rte_kni *kni)return ; } -for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */ @@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free them */ -if (ret >=0 && ret < i && ret <MAX_MBUF_BURST_NUM ) {MAX_MBUF_BURST_NUM +if (ret >=0 && ret < i && ret < num) {int j;for (j = ret; j < i; j++)
Signature · 7 lines
*Olivier Demé* *Druid Software Ltd.* *Tel: +353 1 202 1831* *Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com* *Hall 7, stand 7F70.* Druid Software: Monetising enterprise small cells solutions.
A message that is not in the archive (sent off-list or not yet received): 54EDBC76.2050507-UsMDwKmwmRBx67MzidHQgQC/[email protected]
Hi OIivier
Comments inline.
Regards,
Hemant
Quoted 18 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though. The
alloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:
lib/librte_kni/rte_kni.c rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf · line 581
Quoted 8 lines
lib/librte_kni/rte_kni.c +3
-1@@ -575,7 +575,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_mbufs (kni, ret); +else if (unlikely (kni->alloc_q->write == kni->alloc_q->read)) +kni_allocate_mbufs (kni,0 );
[hemant] This will introduce a run-time check.
I missed to include the other change in the patch.
I am doing it in kni_alloc i.e. initiate the alloc_q with default burst size.
kni_allocate_mbufs(ctx, 0);
In a way, we are now suggesting to reduce the size of alloc_q to only default burst size.
Can we reach is situation, when the kernel is adding packets faster in tx_q than the application is able to dequeue?
alloc_q can be empty in this case and kernel will be striving.
Quoted 85 lines
Olivier.
Quoted 3 lines · Hemant Agrawal
From: Hemant Agrawal <[email protected]>
if any buffer is read from the
tx_q,MAX_BURSTbuffers will be allocated andattempted to be added to to the
alloc_q.Quoted 1 line
This seems terribly inefficient and it also looks like the
alloc_qwill quickly fillto its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.
Quoted 24 lines
This patch allocates the number of buffers as many dequeued from
tx_q.Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0
-04e70fa0..4cf8e30 100644
lib/librte_kni/rte_kni.c +2
-0@@ -128,7 +128,7 @@ struct rte_kni_memzone_pool { static void kni_free_mbufs(struct rte_kni *kni); -static voidkni_allocate_mbufs (struct rte_kni *kni); +static void kni_allocate_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ; static struct rte_kni_memzone_pool kni_memzone_pool = { @@ -575,7 +575,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf**mbufs, unsigned num)
Quoted 1 line
/* If buffers removed, allocate mbufs and then put them into
alloc_q*/
Quoted 7 lines
if (ret)
lib/librte_kni/rte_kni.c +1
-1-kni_allocate_mbufs (kni); +kni_allocate_mbufs (kni, ret);return ret; }lib/librte_kni/rte_kni.c kni_free_mbufs(struct rte_kni *kni) · line 600
Quoted 8 lines
lib/librte_kni/rte_kni.c +1
-1@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; @@ -620,7 +620,10@@
Quoted 13 lines
kni_allocate_mbufs(struct rte_kni *kni)
return;
}lib/librte_kni/rte_kni.c +4
-1-for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */ lib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 639
Quoted 4 lines
lib/librte_kni/rte_kni.c +0
-1@@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free them */ -if (ret >=0 && ret < i && ret <MAX_MBUF_BURST_NUM ){
MAX_MBUF_BURST_NUMlib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 645
Quoted 5 lines
lib/librte_kni/rte_kni.c +1
-0+if (ret >=0 && ret < i && ret < num) {int j;for (j = ret; j < i; j++)--
*Olivier Demé*
*Druid Software Ltd.*
*Tel: +353 1 202 1831*
*Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com**Hall 7, stand 7F70.*Druid Software: Monetising enterprise small cells solutions.
A message that is not in the archive (sent off-list or not yet received): BY2PR0301MB069369AA0C7436E5F9A63AE9C2170-swgC6WJTr6E3qekZfdyv35wN6zqB+hSMnBOFsp37pqbUKgpGm//BTAC/[email protected]
I guess it would be unusual but possible for the kernel to enqueue faster to tx_q than the application dequeues. But that would also be possible with a real NIC, so I think it is acceptable for the kernel to have to drop egress packets in that case.
Quoted 123 lines · On 25/02/15 12:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
HemantQuoted 18 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though. The
alloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:lib/librte_kni/rte_kni.c rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf · line 581
Quoted 8 lines
lib/librte_kni/rte_kni.c +3
-1@@ -575,7 +575,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_mbufs (kni, ret); +else if (unlikely (kni->alloc_q->write == kni->alloc_q->read)) +kni_allocate_mbufs (kni,0 );[hemant] This will introduce a run-time check.
I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default burst size.kni_allocate_mbufs(ctx, 0);In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?
alloc_qcan be empty in this case and kernel will be striving.Quoted 81 lines
Olivier.
Quoted 3 lines · Hemant Agrawal
From: Hemant Agrawal <[email protected]>
if any buffer is read from the
tx_q,MAX_BURSTbuffers will be allocated andattempted to be added to to the
alloc_q.Quoted 1 line
This seems terribly inefficient and it also looks like the
alloc_qwill quickly fillto its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.
Quoted 23 lines
This patch allocates the number of buffers as many dequeued from
tx_q.Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0
-04e70fa0..4cf8e30 100644
lib/librte_kni/rte_kni.c +2
-0@@ -128,7 +128,7 @@ struct rte_kni_memzone_pool { static void kni_free_mbufs(struct rte_kni *kni); -static voidkni_allocate_mbufs (struct rte_kni *kni); +static void kni_allocate_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ; static struct rte_kni_memzone_pool kni_memzone_pool = { @@ -575,7 +575,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf**mbufs, unsigned num)
Quoted 1 line
/* If buffers removed, allocate mbufs and then put them into alloc_q*/
Quoted 7 lines
if (ret)
lib/librte_kni/rte_kni.c +1
-1-kni_allocate_mbufs (kni); +kni_allocate_mbufs (kni, ret);return ret; }lib/librte_kni/rte_kni.c kni_free_mbufs(struct rte_kni *kni) · line 600
Quoted 8 lines
lib/librte_kni/rte_kni.c +1
-1@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; @@ -620,7 +620,10@@
Quoted 13 lines
kni_allocate_mbufs(struct rte_kni *kni)return; }lib/librte_kni/rte_kni.c +4
-1-for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */ lib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 639
Quoted 4 lines
lib/librte_kni/rte_kni.c +0
-1@@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free them */ -if (ret >=0 && ret < i && ret <MAX_MBUF_BURST_NUM ){
MAX_MBUF_BURST_NUMlib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 645
Quoted 4 lines
lib/librte_kni/rte_kni.c +1
-0+if (ret >=0 && ret < i && ret < num) {int j;for (j = ret; j < i; j++)--
*Olivier Demé*
*Druid Software Ltd.*
*Tel: +353 1 202 1831*
*Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com**Hall 7, stand 7F70.*Druid Software: Monetising enterprise small cells solutions.
Signature · 7 lines
*Olivier Demé* *Druid Software Ltd.* *Tel: +353 1 202 1831* *Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com* *Hall 7, stand 7F70.* Druid Software: Monetising enterprise small cells solutions.
Quoted 33 lines · On 25/02/15 13:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
HemantQuoted 18 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though. The
alloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:lib/librte_kni/rte_kni.c rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf · line 581
Quoted 8 lines
lib/librte_kni/rte_kni.c +3
-1@@ -575,7 +575,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_mbufs (kni, ret); +else if (unlikely (kni->alloc_q->write == kni->alloc_q->read)) +kni_allocate_mbufs (kni,0 );[hemant] This will introduce a run-time check.
Quoted 5 lines
I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default burst size.kni_allocate_mbufs(ctx, 0);In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.
As an aside comment here, I think that we should allow to tweak the userspace <-> kernel queue sizes (rx_q, tx_q, free_q and alloc_q) . Whether this should be a build configuration option or a parameter to rte_kni_init(), it is not completely clear to me, but I guess rte_kni_init() is a better option.
Having said that, the original mail from Hemant was describing that KNI was giving an out-of-memory. This to me indicates that the pool is incorrectly dimensioned. Even if KNI will not pre-allocate in the alloc_q, or not completely, in the event of high load, you will get this same "out of memory".
We can reduce the usage of buffers by the KNI subsystem in kernel space and in userspace, but the kernel will always need a small cache of pre-allocated buffers (coming from user-space), since the KNI kernel module does not know where to grab the packets from (which pool). So my guess is that the dimensioning problem experienced by Hemant would be the same, even with the proposed changes.
Quoted 2 lines
Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?
I think so. We cannot control much how the kernel will schedule the KNI thread(s), specially if the # of threads in relation to the cores is incorrect (not enough), hence we need at least a reasonable amount of buffering to prevent early dropping to those "internal" burst side effects.
Marc
Quoted 83 lines
alloc_qcan be empty in this case and kernel will be striving.Quoted 81 lines
Olivier.
Quoted 3 lines · Hemant Agrawal
From: Hemant Agrawal <[email protected]>
if any buffer is read from the
tx_q,MAX_BURSTbuffers will be allocated andattempted to be added to to the
alloc_q.Quoted 1 line
This seems terribly inefficient and it also looks like the
alloc_qwill quickly fillto its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.
Quoted 23 lines
This patch allocates the number of buffers as many dequeued from
tx_q.Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0
-04e70fa0..4cf8e30 100644
lib/librte_kni/rte_kni.c +2
-0@@ -128,7 +128,7 @@ struct rte_kni_memzone_pool { static void kni_free_mbufs(struct rte_kni *kni); -static voidkni_allocate_mbufs (struct rte_kni *kni); +static void kni_allocate_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ; static struct rte_kni_memzone_pool kni_memzone_pool = { @@ -575,7 +575,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf**mbufs, unsigned num)
Quoted 1 line
/* If buffers removed, allocate mbufs and then put them into alloc_q*/
Quoted 7 lines
if (ret)
lib/librte_kni/rte_kni.c +1
-1-kni_allocate_mbufs (kni); +kni_allocate_mbufs (kni, ret);return ret; }lib/librte_kni/rte_kni.c kni_free_mbufs(struct rte_kni *kni) · line 600
Quoted 8 lines
lib/librte_kni/rte_kni.c +1
-1@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; @@ -620,7 +620,10@@
Quoted 13 lines
kni_allocate_mbufs(struct rte_kni *kni)return; }lib/librte_kni/rte_kni.c +4
-1-for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */ lib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 639
Quoted 4 lines
lib/librte_kni/rte_kni.c +0
-1@@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free them */ -if (ret >=0 && ret < i && ret <MAX_MBUF_BURST_NUM ){
MAX_MBUF_BURST_NUMlib/librte_kni/rte_kni.c kni_allocate_mbufs(struct rte_kni *kni) · line 645
Quoted 4 lines
lib/librte_kni/rte_kni.c +1
-0+if (ret >=0 && ret < i && ret < num) {int j;for (j = ret; j < i; j++)--
*Olivier Demé*
*Druid Software Ltd.*
*Tel: +353 1 202 1831*
*Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com**Hall 7, stand 7F70.*Druid Software: Monetising enterprise small cells solutions.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Marc,
I think one of the observations is that currently the alloc_q grows very quickly to the maximum fifo size (1024). The patch suggests fixing the alloc_q to a fix size and maybe make that size configurable in rte_kni_alloc or rte_kni_init.
It should then be up to the application to provision the mempool accordingly. Currently the out of memory problem shows up if the mempool doesn't have 1024 buffers per KNI.
Olivier.
Quoted 143 lines · Marc Sune
Quoted 35 lines · On 25/02/15 13:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
HemantQuoted 24 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though. The
alloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:(quoted diff) +0
-0@@ -575,7 +575,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)Review
Quoted 4 lines
(quoted diff) +3
-1- kni_allocate_mbufs(kni); + kni_allocate_mbufs(kni, ret); + else if (unlikely(kni->alloc_q->write == kni->alloc_q->read)) + kni_allocate_mbufs(kni, 0);[hemant] This will introduce a run-time check.
Quoted 6 lines
I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default
burst size.kni_allocate_mbufs(ctx, 0);In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.As an aside comment here, I think that we should allow to tweak the userspace <-> kernel queue sizes (
rx_q,tx_q,free_qandalloc_q) . Whether this should be a build configuration option or a parameter torte_kni_init(), it is not completely clear to me, but I guessrte_kni_init()is a better option.Having said that, the original mail from Hemant was describing that KNI was giving an out-of-memory. This to me indicates that the pool is incorrectly dimensioned. Even if KNI will not pre-allocate in the
alloc_q, or not completely, in the event of high load, you will get this same "out of memory".We can reduce the usage of buffers by the KNI subsystem in kernel space and in userspace, but the kernel will always need a small cache of pre-allocated buffers (coming from user-space), since the KNI kernel module does not know where to grab the packets from (which pool). So my guess is that the dimensioning problem experienced by Hemant would be the same, even with the proposed changes.
Quoted 2 lines
Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?I think so. We cannot control much how the kernel will schedule the KNI thread(s), specially if the # of threads in relation to the cores is incorrect (not enough), hence we need at least a reasonable amount of buffering to prevent early dropping to those "internal" burst side effects.
Marc
Quoted 85 lines
alloc_qcan be empty in this case and kernel will be striving.Quoted 83 lines
Olivier.
Quoted 3 lines · Hemant Agrawal
From: Hemant Agrawal <[email protected]>
if any buffer is read from the
tx_q,MAX_BURSTbuffers will be allocated andattempted to be added to to the
alloc_q.Quoted 1 line
This seems terribly inefficient and it also looks like the
alloc_qwill quickly fillto its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.
Quoted 23 lines
This patch allocates the number of buffers as many dequeued from
tx_q.Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)lib/librte_kni/rte_kni.c index renamed from lib/librte_kni/rte_kni.c +0
-04e70fa0..4cf8e30 100644
lib/librte_kni/rte_kni.c +2
-0@@ -128,7 +128,7 @@ struct rte_kni_memzone_pool { static void kni_free_mbufs(struct rte_kni *kni); -static voidkni_allocate_mbufs (struct rte_kni *kni); +static void kni_allocate_mbufs (struct rte_kni *kni,int num);static volatile int kni_fd =-1 ; static struct rte_kni_memzone_pool kni_memzone_pool = { @@ -575,7 +575,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf**mbufs, unsigned num)
Quoted 2 lines
/* If buffers removed, allocate mbufs and then put them into
alloc_q*/
Quoted 7 lines
if (ret)
lib/librte_kni/rte_kni.c +1
-1-kni_allocate_mbufs (kni); +kni_allocate_mbufs (kni, ret);return ret; }lib/librte_kni/rte_kni.c kni_free_mbufs(struct rte_kni *kni) · line 600
Quoted 8 lines
lib/librte_kni/rte_kni.c +1
-1@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni) }static void -kni_allocate_mbufs (struct rte_kni *kni) +kni_allocate_mbufs (struct rte_kni *kni,int num) {int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; @@ -620,7 +620,10@@
Quoted 16 lines
kni_allocate_mbufs(struct rte_kni *kni)return; }lib/librte_kni/rte_kni.c +4
-1-for (i =0 ; i <MAX_MBUF_BURST_NUM ; i++) { +if (num ==0 || num >MAX_MBUF_BURST_NUM ) + num =MAX_MBUF_BURST_NUM ; + +for (i =0 ; i < num; i++) { pkts[i] =rte_pktmbuf_alloc (kni->pktmbuf_pool);if (unlikely (pkts[i] ==NULL )) {/* Out of memory */ @@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni) ret =kni_fifo_put (kni->alloc_q, (void **)pkts, i);/* Check if any mbufs not put into alloc_q, and then free Quoted 2 lines
them */
- if (ret >= 0 && ret < i && ret <MAX_MBUF_BURST_NUM){
MAX_MBUF_BURST_NUMQuoted 4 lines
+ if (ret >= 0 && ret < i && ret < num) { int j; for (j = ret; j < i; j++)Signature · 7 lines
*Olivier Demé* *Druid Software Ltd.* *Tel: +353 1 202 1831* *Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com* *Hall 7, stand 7F70.* Druid Software: Monetising enterprise small cells solutions.
Signature · 7 lines
*Olivier Demé* *Druid Software Ltd.* *Tel: +353 1 202 1831* *Email: odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected] <mailto:odeme-UsMDwKmwmRBx67MzidHQgQC/[email protected]>* *URL: http://www.druidsoftware.com* *Hall 7, stand 7F70.* Druid Software: Monetising enterprise small cells solutions.
Quoted 49 lines · Marc Sune
Quoted 40 lines · On 25/02/15 13:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
Hemant-----Original Message-----
Quoted 24 lines
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though.
Thealloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:(quoted diff) +0
-0@@ -575,7 +575,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)Review
Quoted 6 lines
(quoted diff) +3
-1- kni_allocate_mbufs(kni); + kni_allocate_mbufs(kni, ret); + else if (unlikely(kni->alloc_q->write == kni->alloc_q->read)) + kni_allocate_mbufs(kni, 0); [hemant] This will introduce a run-time check.I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default burst
size.Quoted 5 lines
kni_allocate_mbufs(ctx, 0);In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.
Quoted 6 lines
As an aside comment here, I think that we should allow to tweak the userspace <-> kernel queue sizes (
rx_q,tx_q,free_qandalloc_q) . Whether this should be a build configuration option or a parameter torte_kni_init(), it is not completely clear to me, but I guessrte_kni_init()is a better option.
rte_kni_init() is definitely a better option. It allows things to be tuned based on individual system config rather than requiring different builds.
Quoted 18 lines
Having said that, the original mail from Hemant was describing that KNI was giving an out-of-memory. This to me indicates that the pool is incorrectly dimensioned. Even if KNI will not pre-allocate in the
alloc_q, or not completely, in the event of high load, you will get this same "out of memory".We can reduce the usage of buffers by the KNI subsystem in kernel space and in userspace, but the kernel will always need a small cache of pre-allocated buffers (coming from user-space), since the KNI kernel module does not know where to grab the packets from (which pool). So my guess is that the dimensioning problem experienced by Hemant would be the same, even with the proposed changes.
Quoted 3 lines
Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?
Quoted 6 lines
I think so. We cannot control much how the kernel will schedule the KNI thread(s), specially if the # of threads in relation to the cores is incorrect (not enough), hence we need at least a reasonable amount of buffering to prevent early dropping to those "internal" burst side effects.
Marc
Strongly agree with Marc here. We *really* don't want just a single burst worth of mbufs available to the kernel in alloc_q. That's just asking for congestion when there's no need for it.
The original problem reported by Olivier is more of a resource tuning problem than anything else. The number of mbufs you need in the system has to take into account internal queue depths.
Jay
A message that is not in the archive (sent off-list or not yet received): CADNuJVqw4hBD1kk1Y4A2+8-5yi0A0K9_5zBQaO3zOnnwXC0nog-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 95 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jay Rolette
Sent: 25/Feb/2015 7:00 PM
To: Marc Sune
Cc: DPDK
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstQuoted 47 lines · Marc Sune
Quoted 38 lines · On 25/02/15 13:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
Hemant-----Original Message-----
Quoted 22 lines
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though.
Thealloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:(quoted diff) +0
-0@@ -575,7 +575,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)Review
Quoted 6 lines
(quoted diff) +3
-1- kni_allocate_mbufs(kni); + kni_allocate_mbufs(kni, ret); else if + (unlikely(kni->alloc_q->write == kni->alloc_q->read)) + kni_allocate_mbufs(kni, 0); [hemant] This will introduce a run-time check.I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default
burst size.Quoted 5 lines
kni_allocate_mbufs(ctx, 0);In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.Quoted 6 lines
As an aside comment here, I think that we should allow to tweak the userspace <-> kernel queue sizes (
rx_q,tx_q,free_qandalloc_q) . Whether this should be a build configuration option or a parameter torte_kni_init(), it is not completely clear to me, but I guessrte_kni_init()is a better option.
rte_kni_init()is definitely a better option. It allows things to be tuned based on individual system config rather than requiring different builds.Quoted 18 lines
Having said that, the original mail from Hemant was describing that KNI was giving an out-of-memory. This to me indicates that the pool is incorrectly dimensioned. Even if KNI will not pre-allocate in the
alloc_q, or not completely, in the event of high load, you will get this same "out of memory".We can reduce the usage of buffers by the KNI subsystem in kernel space and in userspace, but the kernel will always need a small cache of pre-allocated buffers (coming from user-space), since the KNI kernel module does not know where to grab the packets from (which pool). So my guess is that the dimensioning problem experienced by Hemant would be the same, even with the proposed changes.
Quoted 3 lines
Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?Quoted 6 lines
I think so. We cannot control much how the kernel will schedule the KNI thread(s), specially if the # of threads in relation to the cores is incorrect (not enough), hence we need at least a reasonable amount of buffering to prevent early dropping to those "internal" burst side effects.
Marc
Quoted 7 lines
Strongly agree with Marc here. We *really* don't want just a single burst worth of mbufs available to the kernel in
alloc_q. That's just asking for congestion when there's no need for it.The original problem reported by Olivier is more of a resource tuning problem than anything else. The number of mbufs you need in the system has to take into account internal queue depths.
[hemant] Following are my suggestions for the time being.
1. The existing code allocates X buffers and try to add them to alloc_q. If alloc_q is not having space, it frees them. This is not optimized at all. In the rx_burst, we shall only add the numbers of packets, as removed from tx_q.
2. During the kni_alloc, we can set kni_allocate_mbufs X*Y buffers initially for alloc_q. We can further improve it to make it configurable in future enhancements. Currently we can have the value of Y as 2.
3. kni_allocate_mbufs will allocate as many buffer are requested in function parameter.
Quoted 2 lines
Jay
A message that is not in the archive (sent off-list or not yet received): BY2PR0301MB06939B503E040A8173F21408C2140-swgC6WJTr6E3qekZfdyv35wN6zqB+hSMnBOFsp37pqbUKgpGm//BTAC/[email protected]
Quoted 92 lines · On 26/02/15 08:00, [email protected] wrote:
Quoted 92 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jay Rolette
Sent: 25/Feb/2015 7:00 PM
To: Marc Sune
Cc: DPDK
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstQuoted 41 lines · Marc Sune
Quoted 39 lines · On 25/02/15 13:24, [email protected] wrote:
Hi OIivier
Comments inline.
Regards,
Hemant-----Original Message-----
Quoted 22 lines
From: dev [mailto:[email protected]] On Behalf Of Olivier Deme
Sent: 25/Feb/2015 5:44 PM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] kni:optimization ofrte_kni_rx_burstThank you Hemant, I think there might be one issue left with the patch though.
Thealloc_qmust initially be filled with mbufs before getting mbuf back on thetx_q.So the patch should allow
rte_kni_rx_burstto check ifalloc_qis empty. If so, it should invokekni_allocate_mbufs(kni, 0)(to fill thealloc_qwithMAX_MBUF_BURST_NUMmbufs)The patch for
rte_kni_rx_burstwould then look like:(quoted diff) +0
-0@@ -575,7 +575,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)Review
Quoted 6 lines
(quoted diff) +3
-1- kni_allocate_mbufs(kni); + kni_allocate_mbufs(kni, ret); else if + (unlikely(kni->alloc_q->write == kni->alloc_q->read)) + kni_allocate_mbufs(kni, 0); [hemant] This will introduce a run-time check.I missed to include the other change in the patch.
I am doing it inkni_alloci.e. initiate thealloc_qwith default
burst size.kni_allocate_mbufs(ctx, 0);Quoted 9 lines
Quoted 3 lines
In a way, we are now suggesting to reduce the size of
alloc_qto only default burst size.As an aside comment here, I think that we should allow to tweak the userspace <-> kernel queue sizes (
rx_q,tx_q,free_qandalloc_q) . Whether this should be a build configuration option or a parameter torte_kni_init(), it is not completely clear to me, but I guessrte_kni_init()is a better option.
rte_kni_init()is definitely a better option. It allows things to be tuned based on individual system config rather than requiring different builds.Quoted 17 lines
Having said that, the original mail from Hemant was describing that KNI was giving an out-of-memory. This to me indicates that the pool is incorrectly dimensioned. Even if KNI will not pre-allocate in the
alloc_q, or not completely, in the event of high load, you will get this same "out of memory".We can reduce the usage of buffers by the KNI subsystem in kernel space and in userspace, but the kernel will always need a small cache of pre-allocated buffers (coming from user-space), since the KNI kernel module does not know where to grab the packets from (which pool). So my guess is that the dimensioning problem experienced by Hemant would be the same, even with the proposed changes.
Quoted 3 lines
Can we reach is situation, when the kernel is adding packets faster in
tx_qthan the application is able to dequeue?Quoted 6 lines
I think so. We cannot control much how the kernel will schedule the KNI thread(s), specially if the # of threads in relation to the cores is incorrect (not enough), hence we need at least a reasonable amount of buffering to prevent early dropping to those "internal" burst side effects.
Marc
Strongly agree with Marc here. We *really* don't want just a single burst worth of mbufs available to the kernel in
alloc_q. That's just asking for congestion when there's no need for it.
Quoted 5 lines
Quoted 3 lines
The original problem reported by Olivier is more of a resource tuning problem than anything else. The number of mbufs you need in the system has to take into account internal queue depths.
[hemant] Following are my suggestions for the time being.
1. The existing code allocates X buffers and try to add them toalloc_q. Ifalloc_qis not having space, it frees them. This is not optimized at all. In therx_burst, we shall only add the numbers of packets, as removed fromtx_q.
Agree
Quoted 1 line
2. During the
kni_alloc, we can setkni_allocate_mbufsX*Y buffers initially foralloc_q. We can further improve it to make it configurable in future enhancements. Currently we can have the value of Y as 2.
Provided that the dimensioning (X*Y), if defined in runtime it is set during rte_kni_init(), in principle I agree.
However it is not clear to me if you wantg to call kni_allocate_mbufs(X*Y) for every kni_alloc or just in the first one (in other words, if X*Y == size of alloc_q). Since alloc_q is shared and assuming X*Y == size of alloc_q, I think doing it that in the first kni_alloc() would be sufficient, and then it will get refilled once RX/TX events happen.
A different approach, that would require more refactor, since it changes slightly the current strategy, would be to pre-alloc the alloc_q based of the number of KNI interfaces created (kni_alloc). In this sense, rte_kni_init() would get then 2 parameters: the length of the entire shared alloc_q (actually all the queues in the KNI subsystem, with the current impl.) and the number of buffers / KNI interface. This approach could lower the mbuf consumption in certain configurations.
Quoted 1 line
3.
kni_allocate_mbufswill allocate as many buffer are requested in function parameter.
Agree
Marc
Quoted 2 lines
Quoted 2 lines
Jay