From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0107.outbound.protection.outlook.com [65.55.169.107]) by dpdk.org (Postfix) with ESMTP id D6E835A49 for ; Wed, 25 Feb 2015 12:48:08 +0100 (CET) Received: from DM2PR03CA0047.namprd03.prod.outlook.com (10.141.96.46) by BN1PR0301MB0691.namprd03.prod.outlook.com (25.160.171.28) with Microsoft SMTP Server (TLS) id 15.1.93.16; Wed, 25 Feb 2015 11:48:06 +0000 Received: from BY2FFO11FD003.protection.gbl (2a01:111:f400:7c0c::122) by DM2PR03CA0047.outlook.office365.com (2a01:111:e400:2428::46) with Microsoft SMTP Server (TLS) id 15.1.99.9 via Frontend Transport; Wed, 25 Feb 2015 11:48:05 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD003.mail.protection.outlook.com (10.1.14.125) with Microsoft SMTP Server (TLS) id 15.1.99.6 via Frontend Transport; Wed, 25 Feb 2015 11:48:05 +0000 Received: from nmglablinux18.freescale.com (nmglablinux18.zin33.ap.freescale.net [10.232.20.240]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t1PBm335004429; Wed, 25 Feb 2015 04:48:04 -0700 Received: by nmglablinux18.freescale.com (Postfix, from userid 5043) id 0EA233DD9D60; Wed, 25 Feb 2015 17:18:03 +0530 (IST) From: Hemant Agrawal To: Date: Wed, 25 Feb 2015 17:18:01 +0530 Message-ID: <14248648813214-git-send-email-Hemant@freescale.com> X-Mailer: git-send-email 1.5.2.4 X-EOPAttributedMessage: 0 Received-SPF: None (protection.outlook.com: nmglablinux18.freescale.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is 192.88.158.2) smtp.mailfrom=b10814@nmglablinux18.freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(979002)(6039001)(6009001)(428002)(189002)(199003)(46386002)(2351001)(77156002)(62966003)(450100001)(97736003)(68736005)(47776003)(50226001)(110136001)(42186005)(16796002)(101416001)(229853001)(50466002)(92566002)(64706001)(45336002)(36756003)(106466001)(81156004)(50986999)(103686003)(105586002)(19580395003)(19580405001)(69596002)(6806004)(87936001)(46102003)(48376002)(52956003)(86372001)(90966001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN1PR0301MB0691; H:az84smr01.freescale.net; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:0; LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0691; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005004); SRVR:BN1PR0301MB0691; X-Forefront-PRVS: 049897979A X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:BN1PR0301MB0691; X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2015 11:48:05.1063 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0691 Subject: [dpdk-dev] [PATCH] kni:optimization of rte_kni_rx_burst X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Feb 2015 11:48:09 -0000 From: Hemant Agrawal 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. Signed-off-by: Hemant Agrawal --- lib/librte_kni/rte_kni.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 4e70fa0..4cf8e30 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -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++) -- 1.9.1