Skip to contentSkip to conversation

mm/dmapool.c: micro-optimisation remove unnecessary branch

PATCH Applied [email protected] 1 participant 1 message Mar 20, 2020

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

PATCH 1/1 mm/dmapool.c: micro-optimisation remove unnecessary branch

From: Mateusz Nosek <[email protected]>

Previously there was a check if 'size' is aligned to 'align' and if not then it was aligned. This check was expensive as both branch and division are expensive instructions in most architectures.
'ALIGN' function on already aligned value will not change it, and as it is cheaper than branch + division it can be executed all the time and branch can be removed.

---
 mm/dmapool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/dmapool.c +1 -3
index fe5d33060415..f9fb9bbd733e 100644
@@ -144,9 +144,7 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
 	else if (size < 4)
 		size = 4;
 
-	if ((size % align) != 0)
-		size = ALIGN(size, align);
-
+	size = ALIGN(size, align);
 	allocation = max_t(size_t, size, PAGE_SIZE);
 
 	if (!boundary)
Signature · 1 line
2.17.1