Hello all,

I got issue, may be there is a missing solution in rte_kni.c or other parts.

There is not any function to free kni allocated bufs and rte_pktmbuf_free is 
not enough to handle it. (kni_free_mbufs is not reachable.)

In default-testing kni application works as below


  1.  Call rte_kni_rx_burst function to get messages
  2.  Then push to other KNI interface via rte_kni_tx_burst. There is no 
memory-leak because  kni_free_mbufs is called and freed unused allocations.

On the other hand, in my scenario


  1.  Call rte_kni_rx_burst func to get messages, burst_size is 32 but 1 packet 
is received from Kernel
  2.  Then try to free all messages via rte_pktmbuf_free
  3.  Freed 1 unit and 31 unit is not freed. memory leak

Other scenario,


  1.  Call rte_kni_rx_burst func to  get messages, burst_size is 32 but 1 
packet is received from Kernel
  2.  Push to ethernet_device via rte_eth_tx_burst
  3.  There is not any free operation by rte_eth_tx_burst
  4.  Try to free via rte_pktmbuf_free
  5.  1 unit is freed 31 unit is left in memory. Still memory leak


What i am missing ? I think same issue happens in version 17.11 .

unsigned
rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num)
{
              num = RTE_MIN(kni_fifo_free_count(kni->rx_q), num);
              void *phy_mbufs[num];
              unsigned int ret;
              unsigned int i;

              for (i = 0; i < num; i++)
                            phy_mbufs[i] = va2pa_all(mbufs[i]);

              ret = kni_fifo_put(kni->rx_q, phy_mbufs, num);

              /* Get mbufs from free_q and then free them */
              kni_free_mbufs(kni);  <-------- Here is freeing unused 
allocations.

              return ret;
}
unsigned
rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num)
{
              unsigned int ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);

              /* If buffers removed, allocate mbufs and then put them into 
alloc_q */
              if (ret)
                            kni_allocate_mbufs(kni);

              return ret;
}

static void
kni_free_mbufs(struct rte_kni *kni)
{
              int i, ret;
              struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM];

              ret = kni_fifo_get(kni->free_q, (void **)pkts, 
MAX_MBUF_BURST_NUM);   <<<--- to free all allocated memory needs to use this 
function. (kni->free_q)
              if (likely(ret > 0)) {
                            for (i = 0; i < ret; i++)
                                          rte_pktmbuf_free(pkts[i]);
              }
}


Best Regards.

___
Yasin CANER
Lider Mühendis
Ulak Haberleşme A.Ş. Ankara

From: Yasin CANER
Sent: Thursday, May 4, 2023 10:32 AM
To: [email protected]
Subject: DPDK 22.11 - How to fix memory leak for KNI - How to debug

Hello all,

I think there is a memory leak for KNI.

Firstly, try to active trace modüle to follow memory management but could not. 
İt doesn't create file and dont have any clue.

Run Command : -c dpdk_core_mask -d librte_net_virtio.so -d librte_mbuf.so -d 
librte_mempool.so -d librte_mempool_ring.so -d librte_mempool_stack.so -d 
librte_mempool_bucket.so -d librte_kni.so --log-level lib.kni:debug --log-level 
lib.eal:debug --log-level lib.ethdev:debug --trace=kni --trace-dir=/tmp/


Secondly, I used followed functions.

``code
  used_mpool  = rte_mempool_in_use_count(rdpdk_cfg->mbuf_pool);
  count_mpool = rte_mempool_avail_count(rdpdk_cfg->mbuf_pool);
``

After calling function rte_kni_rx_burst, 32 unit is allocated. Then i force to 
free message_buf (mbuf). It frees 1 unit. 31 units left in memory!


How to fix or understand this issue.
Follow logs,




  1.  (59383)  6:55:10    lrtc():3212> [KNI]Picked up 1 packets from port 0 
[KNI:F000]   --> 1 packet is received from Kernel that is allocate 32 unit
  2.  (59383)  6:55:10   print_mempool_tx():2511> 
[UseCount_mpool:468][avail_mpool:9931]
  3.  (59383)  6:55:10    pkni():2536> [KNI] i:0/1
  4.  (59383)  6:55:10    pkni():2616> [KNI][EGR]  P:[IPv6]  P:[0] 
[fe80::f816:3eff:fe93:f5fd]->[ff02::2] --> Packet is a broadcast packet IPv6
  5.  (59383)  6:55:10    pkni():2620> [KNI][EGR][pkt-len:70]
  6.  (59383)  6:55:10   print_mempool_tx():2511> 
[UseCount_mpool:467][avail_mpool:9932] --> mbuf is freed to understand 
mem-leak. İt is same happens after calling rte_eth_tx_burst
  7.  (59383)  6:55:10    lrtc():3212> [KNI]Picked up 1 packets from port 1 
[KNI:F000] --> 1 packet is received from Kernel that is allocate 32 unit 9932 
to 9900 then same process happens and 31 units is not freed.
  8.  (59383)  6:55:10   print_mempool_tx():2511> 
[UseCount_mpool:499][avail_mpool:9900]
  9.  (59383)  6:55:10    pkni():2536> [KNI] i:0/1
  10. (59383)  6:55:10    pkni():2616> [KNI][EGR]  P:[IPv6]    P:[1] 
[fe80::f816:3eff:fed2:9101]->[ff02::2]
  11. (59383)  6:55:10    pkni():2620> [KNI][EGR][pkt-len:70]
  12. (59383)  6:55:10   print_mempool_tx():2511> 
[UseCount_mpool:498][avail_mpool:9901]


Kernel : 5.4.0-146-generic #163-Ubuntu SMP Fri Mar 17 18:26:02 UTC 2023 x86_64 
x86_64 x86_64 GNU/Linux
Ubuntu 20.04
DPDK dpdk-stable-22.11.1
İgb_uio is used.

Best regards.
___
Yasin CANER
Lider Mühendis
Ulak Haberleşme A.Ş. Ankara


Bu elektronik posta ve onunla iletilen bütün dosyalar sadece göndericisi 
tarafından alması amaçlanan yetkili, gerçek ya da tüzel kişinin kullanımı 
içindir. Eğer söz konusu yetkili alıcı değilseniz, bu elektronik postanın 
içeriğini açıklamanız, kopyalamanız, yönlendirmeniz ve kullanmanız kesinlikle 
yasaktır ve bu elektronik postayı derhal silmeniz gerekmektedir. Şirketimiz bu 
mesajın içerdiği bilgilerin doğruluğu veya eksiksiz olduğu konusunda herhangi 
bir garanti vermemektedir. Bu nedenle, bu bilgilerin ne şekilde olursa olsun 
içeriğinden, iletilmesinden, alınmasından ve saklanmasından sorumlu değildir. 
Bu mesajdaki görüşler yalnızca gönderen kişiye aittir ve Şirketimizin 
görüşlerini yansıtmayabilir. Tarafınız ile paylaşılan kişisel verilerin, 6698 
sayılı Kişisel Verilerin Korunması Kanununa uygun olarak işlenmesi gereğini 
bilginize sunarız.

________________________________

This e-mail and all files sent with it are intended for authorized natural or 
legal persons, who should be the only persons to open and read them. If you are 
not an authorized recipient, you are strictly prohibited from disclosing, 
copying, forwarding, and using the contents of this e-mail, and you must 
immediately delete it. Our company does not guarantee the accuracy or 
thoroughness of the information contained in this message. It is therefore in 
no way responsible for the content, sending, retrieval and storage of this 
information. The opinions contained in this message are the views of the sender 
only and do not necessarily reflect the views of the company. We would like to 
inform you that any personal data shared with you should be processed in 
accordance with the Law on Protection of Personal Data numbered 6698.

Reply via email to