Skip to contentSkip to conversation

mm: swap: calculate pages via roundup() in __swapin_nr_pages()

PATCH New Zhaoyu Liu 1 participant 1 message Apr 8, 2024

Subsystems (2)
lore
Share & tools
lore

Zhaoyu Liu

author
#0 lore raw

PATCH 1/1 mm: swap: calculate pages via roundup() in __swapin_nr_pages()

Use roundup() to replace while&shift. When the "pages" is large, using roundup() will be faster than while&shift.

---
 mm/swap_state.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
mm/swap_state.c +2 -6
index 642c30d8376c..d34dc95d0910 100644
@@ -590,12 +590,8 @@ static unsigned int __swapin_nr_pages(unsigned long prev_offset,
 		 */
 		if (offset != prev_offset + 1 && offset != prev_offset - 1)
 			pages = 1;
-	} else {
-		unsigned int roundup = 4;
-		while (roundup < pages)
-			roundup <<= 1;
-		pages = roundup;
-	}
+	} else
+		pages = roundup(pages, 4);
 
 	if (pages > max_pages)
 		pages = max_pages;
Signature · 1 line
2.25.1