From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <adrien.mazarguil@6wind.com>
Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com
 [209.85.212.174]) by dpdk.org (Postfix) with ESMTP id A6316C314
 for <dev@dpdk.org>; Mon, 25 May 2015 18:28:02 +0200 (CEST)
Received: by wichy4 with SMTP id hy4so53660173wic.1
 for <dev@dpdk.org>; Mon, 25 May 2015 09:28:01 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references;
 bh=OhiN/gIFETfN3rx5BU/4IRDMEyqhjBuMwSdlkeyavkg=;
 b=NRkI4zCiRUXgG0THd0GWZBVu+vpfpfSQIpJuy8lvn2UfVxJK4GyRj5mh31YC+pvllv
 i8utDc/c7wL0SBvVCaEXfnIp/1ZtteK4nRjYqPtcnSRhx0BSo6a5SATUB5ZcO1TL43Dw
 CdIPnoACbRws4Ifl95Hz99Zmo/u7Z/ti2f4Lq/DQPzf8nrlPZLrTRmlECwgfmxmBZJI6
 Nv9V5kJ+KJ01dtMKfHUyRwTWChMshWGVgjK7ZAYKx3CNptI3/EFxWljDIknX5niCV331
 FuCTFu9nm7EvKXnn2umvHj8UqyrFzSWbXoBVGgKO/1AMbgdKOL5mAWtsEQz4ELoU5IJj
 AKyA==
X-Gm-Message-State: ALoCoQkEHrjYqpVpNKRJPfUV2k6SRj+prJSsTBqnefYKS6kq1zVDSWzBFEIY2tu3mEk6ravx/HbC
X-Received: by 10.194.123.4 with SMTP id lw4mr1594647wjb.94.1432571281559;
 Mon, 25 May 2015 09:28:01 -0700 (PDT)
Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net.
 [82.239.227.177])
 by mx.google.com with ESMTPSA id mv11sm12599144wic.23.2015.05.25.09.28.00
 for <dev@dpdk.org> (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
 Mon, 25 May 2015 09:28:00 -0700 (PDT)
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: dev@dpdk.org
Date: Mon, 25 May 2015 18:27:46 +0200
Message-Id: <1432571266-25840-2-git-send-email-adrien.mazarguil@6wind.com>
X-Mailer: git-send-email 2.1.0
In-Reply-To: <1432571266-25840-1-git-send-email-adrien.mazarguil@6wind.com>
References: <1432571266-25840-1-git-send-email-adrien.mazarguil@6wind.com>
Subject: [dpdk-dev] [PATCH 2/2] mempool: fix pages computation to determine
	number of objects
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 25 May 2015 16:28:02 -0000

In rte_mempool_obj_iter(), even when a single page is required per object,
a loop checks that the the next page is contiguous and drops the first one
otherwise. This commit checks subsequent pages only when several are
required per object.

Also a minor fix for the amount of remaining space that prevents using the
entire region.

Fixes: 148f963fb532 ("xen: core library changes")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 lib/librte_mempool/rte_mempool.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index d1a02a2..3c1efec 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -175,12 +175,17 @@ rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
 		pgn += j;
 
 		/* do we have enough space left for the next element. */
-		if (pgn >= pg_num)
+		if (pgn > pg_num)
 			break;
 
-		for (k = j;
+		/*
+		 * Compute k so that (k - j) is the number of contiguous
+		 * pages starting from index j. Note that there is at least
+		 * one page.
+		 */
+		for (k = j + 1;
 				k != pgn &&
-				paddr[k] + pg_sz == paddr[k + 1];
+				paddr[k - 1] + pg_sz == paddr[k];
 				k++)
 			;
 
-- 
2.1.0