<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:black;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1272738930;
        mso-list-type:hybrid;
        mso-list-template-ids:1397256672 629067590 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:2;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-font-family:Calibri;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">Hi Michal,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">I'll "top post" on this reply as the content is in HTML format below. In future, please try to send plain-text emails to DPDK mailing lists.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">Regarding the issue you're having, its interesting that allocating from hugepage backed memory "solves" the problem, even when going<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">back to the lower traffic rate. The main difference for a CPU to access hugepage backed or 4k paged backed memory is the DTLB[1] pressure.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">In your scenario, both page-sizes work equally well at the start (no drops). This is likely as all buffers are being accessed linearly,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">and there are no packet drops, resulting in good re-use of buffers.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">Lets discuss the 4K page scenario:<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">When the rate is turned up, packets are dropped, and the CPU(s) cannot keep up. This results in NIC rx descriptor rings being totally<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">full of used packets, and the mempools that contain the buffers become more "fragmented" in that not every buffer is on the same<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">4k page anymore. In the worst case, each mbuf could be on a _<i><span style="font-style:italic">different</span></i>_ 4k page!<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">I think that when turning down the rate again, the fragmentation of mbufs in the mempool remains, resulting in continued loss of packets.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">Estimating and talking is never conclusive – lets measure using Linux "Perf" tool. Run this command 3x, just like you posted the drop stats below.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">I expect to see lower dTLB-load-misses on the first run (no drops, 10 mpps), and that the dTLB misses are higher for 15 mpps *<b><span style="font-weight:bold">and</span></b>*
 for 10 mpps again afterwards.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">perf stat -e cycles,dTLB-load-misses -C <datapath_lcore_here> -- sleep 1<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">Please try the commands, and report back your findings! Hope that helps, -Harry<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black">[1] TLB & DPDK Resources;<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><a href="https://en.wikipedia.org/wiki/Translation_lookaside_buffer">https://en.wikipedia.org/wiki/Translation_lookaside_buffer</a> (DTLB just means
 Data-TLB, as opposed to instruction-TLB)<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><a href="https://stackoverflow.com/questions/52077230/huge-number-of-dtlb-load-misses-when-dpdk-forwarding-test">https://stackoverflow.com/questions/52077230/huge-number-of-dtlb-load-misses-when-dpdk-forwarding-test</a><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><a href="https://www.dpdk.org/wp-content/uploads/sites/35/2018/12/LeiJiayu_Revise-4K-Pages-Performance-Impact-For-DPDK-Applications.pdf">https://www.dpdk.org/wp-content/uploads/sites/35/2018/12/LeiJiayu_Revise-4K-Pages-Performance-Impact-For-DPDK-Applications.pdf</a><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="#f6f6f6" face="Calibri"><span style="font-size:11.0pt;color:black"><o:p> </o:p></span></font></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><font size="2" face="Calibri"><span style="font-size:11.0pt;font-weight:bold">From:</span></font></b> Michał Niciejewski <michal.niciejewski@codilime.com>
<br>
<b><span style="font-weight:bold">Sent:</span></b> Wednesday, December 22, 2021 9:57 AM<br>
<b><span style="font-weight:bold">To:</span></b> users@dpdk.org<br>
<b><span style="font-weight:bold">Subject:</span></b> Unexpected behavior when using mbuf pool with external buffers<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><font size="2" face="Calibri"><span style="font-size:11.0pt"><o:p> </o:p></span></font></p>
<div>
<p class="MsoNormal"><font size="2" face="Calibri"><span style="font-size:11.0pt">Hi,<br>
<br>
recently I stumbled upon a problem with mbuf pool with external buffers. I allocated some memory with aligned_alloc(), registered it, DMA mapped the memory, and created mbuf pool:<br>
<br>
size_t mem_size = RTE_ALIGN_CEIL(MBUFS_NUM * QUEUE_NUM * RTE_MBUF_DEFAULT_BUF_SIZE, 4096);<br>
auto mem = aligned_alloc(4096, mem_size);<br>
mlock(mem, mem_size);<br>
rte_pktmbuf_extmem ext_mem = {<br>
    .buf_ptr = mem,<br>
    .buf_iova = (uintptr_t)mem,<br>
    .buf_len = mem_size,<br>
    .elt_size = RTE_MBUF_DEFAULT_BUF_SIZE,<br>
};<br>
<br>
if (rte_extmem_register(ext_mem.buf_ptr, ext_mem.buf_len, nullptr, 0, 4096) != 0)<br>
    throw runtime_error("Failed to register DPDK external memory");<br>
<br>
if (rte_dev_dma_map(dev, ext_mem.buf_ptr, ext_mem.buf_iova, ext_mem.buf_len) != 0)<br>
    throw runtime_error("Failed to DMA map external memory");<br>
<br>
mp = rte_pktmbuf_pool_create_extbuf("ext_mbuf_pool", MBUFS_NUM * QUEUE_NUM, 0, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_eth_dev_socket_id(0), &ext_mem, 1);<br>
if (mp == nullptr)<br>
    throw runtime_error("Failed to create external mbuf pool");<br>
<br>
The main loop of the program works like normal l2fwd: it receives packets and sends them to another port.<br>
<br>
std::vector<rte_mbuf *> mbufs(MAX_PKT_BURST);<br>
while (true) {<br>
    auto rx_num = rte_eth_rx_burst(0, queue, mbufs.data(), MAX_PKT_BURST);<br>
    if (!rx_num)<br>
        continue;<br>
    // ...<br>
    auto tx_num = rte_eth_tx_burst(1, queue, mbufs.data(), rx_num);<br>
    rte_pktmbuf_free_bulk(mbufs.data() + tx_num, rx_num - tx_num);<br>
}<br>
<br>
Every second, the program prints some info about the packets received in this second and some stats regarding rte_eth_tx_burst calls. For example, logs printed while receiving and sending 10mpps:<br>
<br>
Number of all rx burst calls: 12238365<br>
Number of non-zero rx burst calls: 966834<br>
Avg pkt nb received per rx burst: 0.816879<br>
All received pkts: 9997264<br>
All sent pkts: 9997264<br>
All dropped pkts: 0<br>
<br>
For lower traffic, everything looks fine. But when I start sending more packets some unexpected behavior occurs. When I increase traffic to 15mpps most of the packets are dropped on TX:<br>
<br>
Queue: 0<br>
Number of rx burst calls: 4449541<br>
Number of non-zero rx burst calls: 1616833<br>
Avg pkt nb received per rx burst: 3.36962<br>
All received pkts: 14993272<br>
All sent pkts: 5827744<br>
All dropped pkts: 9165528<br>
<br>
After that, I checked again the results for 10mpps. Even though previously the application didn't have any troubles in managing 10mpps, now it does:<br>
<br>
Queue: 0<br>
Number of all rx burst calls: 8722385<br>
Number of non-zero rx burst calls: 1447741<br>
Avg pkt nb received per rx burst: 1.14617<br>
All received pkts: 9997316<br>
All sent pkts: 8194416<br>
All dropped pkts: 1802900<br>
<br>
So basically it looks like sending too many packets breaks something and starts causing problems when sending fewer packets.<br>
<br>
I also tried allocating huge pages for mbuf pool instead of memory returned from aligned_alloc:<br>
<br>
auto mem = mmap(0, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);<br>
<br>
And actually, it solved the problems - too big traffic doesn't affect lower traffic management. But I still want to know why memory allocated using aligned_alloc causes problems because in the place where I want to use mbuf pools with external buffers huge
 pages cannot be used like that.<br>
<br>
The full code used for testing: <a href="https://gist.github.com/tropuq/22625e0e5ac420a8ff5ae072a16f4c06" target="_blank">https://gist.github.com/tropuq/22625e0e5ac420a8ff5ae072a16f4c06</a><br>
<br>
NIC used: Supermicro AOC-S25G-I2S-O Std Low Profile 25G Dual Port SFP28, based on Intel XXV710<br>
<br>
Did anyone have similar issues or know what could cause such behavior? Is this allocation of the mbuf pool correct or am I missing something?<br>
<br>
Thanks in advance<br clear="all">
<o:p></o:p></span></font></p>
<div>
<p class="MsoNormal"><font size="2" face="Calibri"><span style="font-size:11.0pt"><o:p> </o:p></span></font></p>
</div>
<p class="MsoNormal"><font size="2" face="Calibri"><span style="font-size:11.0pt">--
<o:p></o:p></span></font></p>
<div>
<div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="margin-left:10.75pt;border-collapse:collapse">
<tbody>
<tr>
<td style="padding:0cm 0cm 0cm 0cm">
<p style="margin:0cm;line-height:14.4pt"><b><font size="2" color="#d4d4d4" face="Helvetica"><span style="font-size:10.5pt;font-family:"Helvetica",sans-serif;color:#333333;font-weight:bold">Michał Niciejewski<o:p></o:p></span></font></b></p>
</td>
</tr>
<tr>
<td style="padding:0cm 0cm 0cm 0cm">
<p style="margin:0cm;line-height:14.4pt"><font size="1" color="#d4d4d4" face="Helvetica"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#333333">Junior Software Engineer<o:p></o:p></span></font></p>
</td>
</tr>
<tr>
<td style="padding:0cm 0cm 0cm 0cm"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></font></p>
</div>
</div>
</div>
</body>
</html>