Skip to content

Commit

Permalink
mm/dmapool.c: micro-optimisation remove unnecessary branch
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Mateusz Nosek <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Mateusz Nosek authored and torvalds committed Apr 7, 2020
1 parent 1d90b64 commit 1386f7a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions mm/dmapool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1386f7a

Please sign in to comment.