Skip to contentSkip to conversation

mempool: fix search of maximum contiguous pages

PATCH In review Wei Dai 5 participants 11 messages Oct 13, 2016 – Oct 25, 2016

lore
Share & tools
lore

Wei Dai

author
#0 lore raw

PATCH 1/1 mempool: fix search of maximum contiguous pages

paddr[i] + pg_sz always points to the start physical address of the 2nd page after pddr[i], so only up to 2 pages can be combinded to be used. With this revision, more than 2 pages can be used.

Fixes 84121f197187 ("mempool: store memory chunks in a list")
---
 lib/librte_mempool/rte_mempool.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +4 -1
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
 
 	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
 			;
 
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
Signature · 1 line
2.7.4
#1 lore raw

+Olivier

Quoted 29 lines · Wei Dai

paddr[i] + pg_sz always points to the start physical address of the 2nd page after pddr[i], so only up to 2 pages can be combinded to be used. With this revision, more than 2 pages can be used.

Fixes 84121f197187 ("mempool: store memory chunks in a list")
---
  lib/librte_mempool/rte_mempool.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +4 -1
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
 
  	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
  		/* populate with the largest group of contiguous pages */
  		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
  			;
 
  		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
#2 lore raw
In reply to Wei Dai

Hi

Quoted 12 lines
---
 lib/librte_mempool/rte_mempool.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
 

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr, · line 435

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +4 -1
 	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
 			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]? Then you don't need extra variable (paddr_next) here. Konstantin

Quoted 4 lines
lib/librte_mempool/rte_mempool.c +0 -1
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
--

2.7.4

#3 lore raw
Quoted 25 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ananyev, Konstantin
Sent: Thursday, October 13, 2016 10:54 AM
To: Dai, Wei <[email protected]>; [email protected]; Gonzalez Monroy, Sergio <[email protected]>; Tan, Jianfeng <[email protected]>; Dai, Wei <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] mempool: fix search of maximum contiguous pages

Hi

Quoted 14 lines
---
 lib/librte_mempool/rte_mempool.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
 
 	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
Quoted 11 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr, · line 435

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +4 -1
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
 			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 7 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Quoted 4 lines
lib/librte_mempool/rte_mempool.c +0 -1
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
--

2.7.4

author
#4 lore raw
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct
 rte_mempool *mp, char *vaddr,
 
 	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
Quoted 11 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr, · line 435

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +4 -1
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
 			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Quoted 4 lines

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 2 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Thank you, Konstantin
'paddr[i + n - 1] + pg_sz = paddr[i + n]' also can fix it and have straight meaning. But I assume that my revision with paddr_next += pg_sz may have a bit better performance. By the way, paddr[i] + n * pg_sz = paddr[i + n] can also resolve it.

/Wei

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool.c +0 -1
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
--

2.7.4

#5 lore raw
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct
 rte_mempool *mp, char *vaddr,
 

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct · line 436

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +4 -1
 	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
 			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Quoted 8 lines
Quoted 4 lines

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 2 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Thank you, Konstantin
'paddr[i + n - 1] + pg_sz = paddr[i + n]' also can fix it and have straight meaning. But I assume that my revision with paddr_next += pg_sz may have a bit better performance.

I don't think there would be any real difference, again it is not performance critical code-path.

Quoted 1 line

By the way, paddr[i] + n * pg_sz = paddr[i + n] can also resolve it.

Yes, that's one seems even better for me - make things more clear. Konstantin

Quoted 8 lines

/Wei

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool.c +0 -1
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
--

2.7.4

#6 lore raw

Hi Wei,

Quoted 33 lines · Konstantin
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct
 rte_mempool *mp, char *vaddr,
 

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct · line 436

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +4 -1
  	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
  		/* populate with the largest group of contiguous pages */
  		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
  			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Quoted 8 lines
Quoted 4 lines

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 2 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Thank you, Konstantin
'paddr[i + n - 1] + pg_sz = paddr[i + n]' also can fix it and have straight meaning. But I assume that my revision with paddr_next += pg_sz may have a bit better performance.

Quoted 5 lines

I don't think there would be any real difference, again it is not performance critical code-path.

Quoted 1 line

By the way, paddr[i] + n * pg_sz = paddr[i + n] can also resolve it.

Yes, that's one seems even better for me - make things more clear.

Thank you for fixing this.

My vote would go for "addr[i + n - 1] + pg_sz == paddr[i + n]"

If you feel "paddr[i] + n * pg_sz = paddr[i + n]" is clearer, I have no problem with it either.

Regards,
Olivier

#7 lore raw

2016-10-13 17:05, Olivier MATZ:

Quoted 40 lines

Hi Wei,

Quoted 37 lines · Konstantin
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct
 rte_mempool *mp, char *vaddr,
 

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct · line 436

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +4 -1
  	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
  		/* populate with the largest group of contiguous pages */
  		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
  			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Quoted 8 lines
Quoted 4 lines

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 2 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Thank you, Konstantin
'paddr[i + n - 1] + pg_sz = paddr[i + n]' also can fix it and have straight meaning. But I assume that my revision with paddr_next += pg_sz may have a bit better performance.

I don't think there would be any real difference, again it is not performance critical code-path.

Quoted 1 line

By the way, paddr[i] + n * pg_sz = paddr[i + n] can also resolve it.

Quoted 8 lines
Quoted 1 line

Yes, that's one seems even better for me - make things more clear.

Thank you for fixing this.

My vote would go for "addr[i + n - 1] + pg_sz == paddr[i + n]"

If you feel "paddr[i] + n * pg_sz = paddr[i + n]" is clearer, I have no problem with it either.

No answer from Wei Dai.
Please Olivier advise what to do with this patch.
Thanks

#8 lore raw

Hi Thomas,

Quoted 45 lines · Thomas Monjalon

2016-10-13 17:05, Olivier MATZ:

Quoted 44 lines

Hi Wei,

Quoted 33 lines · Konstantin
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +0 -0
index 71017e1..e3e254a 100644
@@ -426,9 +426,12 @@ rte_mempool_populate_phys_tab(struct
 rte_mempool *mp, char *vaddr,
 

lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys_tab(struct · line 436

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +4 -1
  	for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) {
 
+		phys_addr_t paddr_next;
+		paddr_next = paddr[i] + pg_sz;
+
  		/* populate with the largest group of contiguous pages */
  		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr_next == paddr[i+n]; n++, paddr_next += pg_sz)
  			;

Good catch.
Why not just paddr[i + n - 1] != paddr[i + n]?

Quoted 8 lines
Quoted 4 lines

Sorry, I meant 'paddr[i + n - 1] + pg_sz == paddr[i+n]' off course.

Quoted 2 lines

Then you don't need extra variable (paddr_next) here. Konstantin

Thank you, Konstantin
'paddr[i + n - 1] + pg_sz = paddr[i + n]' also can fix it and have straight meaning. But I assume that my revision with paddr_next += pg_sz may have a bit better performance.

Quoted 5 lines

I don't think there would be any real difference, again it is not performance critical code-path.

Quoted 1 line

By the way, paddr[i] + n * pg_sz = paddr[i + n] can also resolve it.

Yes, that's one seems even better for me - make things more clear.

Thank you for fixing this.

Quoted 9 lines
Quoted 4 lines

My vote would go for "addr[i + n - 1] + pg_sz == paddr[i + n]"

If you feel "paddr[i] + n * pg_sz = paddr[i + n]" is clearer, I have no problem with it either.

No answer from Wei Dai.
Please Olivier advise what to do with this patch.
Thanks

I think it's good to have this fix in 16.11.
I'm sending a v2 based on Wei's patch.

Olivier

#9 lore raw

PATCH v2 1/1 mempool: fix search of maximum contiguous pages

In reply to Wei Dai

From: Wei Dai <[email protected]>

paddr[i] + pg_sz always points to the start physical address of the 2nd page after pddr[i], so only up to 2 pages can be combinded to be used. With this revision, more than 2 pages can be used.

Fixes 84121f197187 ("mempool: store memory chunks in a list")
---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +1 -1
index 71017e1..e94e56f 100644
@@ -428,7 +428,7 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
 
 		/* populate with the largest group of contiguous pages */
 		for (n = 1; (i + n) < pg_num &&
-			     paddr[i] + pg_sz == paddr[i+n]; n++)
+			     paddr[i + n - 1] + pg_sz == paddr[i + n]; n++)
 			;
 
 		ret = rte_mempool_populate_phys(mp, vaddr + i * pg_sz,
Signature · 1 line
2.8.1