Skip to contentSkip to conversation

mm/zsmalloc: strength reduce zspage_size calculation

PATCH In review Joey Pabalinas 2 participants 3 messages Feb 26, 2018 – Feb 28, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/zsmalloc: strength reduce zspage_size calculation

Replace the repeated multiplication in the main loop body calculation of zspage_size with an equivalent (and cheaper) addition operation.

 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zsmalloc.c +2 -2
index c3013505c30527dc42..647a1a2728634b5194 100644
@@ -821,15 +821,15 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
  */
 static int get_pages_per_zspage(int class_size)
 {
+	int zspage_size = 0;
 	int i, max_usedpc = 0;
 	/* zspage order which gives maximum used size per KB */
 	int max_usedpc_order = 1;
 
 	for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
-		int zspage_size;
 		int waste, usedpc;
 
-		zspage_size = i * PAGE_SIZE;
+		zspage_size += PAGE_SIZE;
 		waste = zspage_size % class_size;
 		usedpc = (zspage_size - waste) * 100 / zspage_size;
 
Signature · 1 line
2.16.2
maintainer
#1 lore raw

Hi Joey,

Quoted 20 lines · Joey Pabalinas

Replace the repeated multiplication in the main loop body calculation of zspage_size with an equivalent (and cheaper) addition operation.

 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zsmalloc.c +1 -0
index c3013505c30527dc42..647a1a2728634b5194 100644
@@ -821,15 +821,15 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
  */
 static int get_pages_per_zspage(int class_size)
 {
+	int zspage_size = 0;
 	int i, max_usedpc = 0;
 	/* zspage order which gives maximum used size per KB */
 	int max_usedpc_order = 1;

mm/zsmalloc.c static enum fullness_group fix_fullness_group(struct size_class *class, · line 835

Quoted 10 lines
mm/zsmalloc.c +1 -2
 
 	for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
-		int zspage_size;
 		int waste, usedpc;
 
-		zspage_size = i * PAGE_SIZE;
+		zspage_size += PAGE_SIZE;
 		waste = zspage_size % class_size;
 		usedpc = (zspage_size - waste) * 100 / zspage_size;
 

Thanks for the patch! However, it's used only zs_create_pool which is really cold path so I don't feel it would improve for real practice.

Thanks.

#2 lore raw
Quoted 2 lines · Minchan Kim

Thanks for the patch! However, it's used only zs_create_pool which is really cold path so I don't feel it would improve for real practice.

Very true; in retrospect this this definitely isn't a very hot path at all, haha. Cheers :)

Signature · 1 line
Joey Pabalinas