From: David Laight <David.Laight@ACULAB.COM>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"'linux-sctp@vger.kernel.org'" <linux-sctp@vger.kernel.org>,
Eric Biggers <ebiggers@kernel.org>,
'Marcelo Ricardo Leitner' <marcelo.leitner@gmail.com>,
'Catalin Marinas' <catalin.marinas@arm.com>,
"'kent.overstreet@gmail.com'" <kent.overstreet@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
"'Neil Horman'" <nhorman@tuxdriver.com>
Subject: [PATCH 10/13] lib/generic-radix-tree: Simplify offset calculation:
Date: Tue, 25 Aug 2020 14:52:47 +0000 [thread overview]
Message-ID: <bc04c6adae56428c9e247b0506da5f25@AcuMS.aculab.com> (raw)
Since these are equivalent:
(idx / objs_per_page) * PAGE_SIZE + (idx % objs_per_page) * obj_size;
idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size);
Use the latter since it is slightly faster.
It also deosn't need an extra check for obj_size being a power of 2.
Signed-off-by: David Laight <david.laight@aculab.com>
---
include/linux/generic-radix-tree.h | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/include/linux/generic-radix-tree.h b/include/linux/generic-radix-tree.h
index 53149bc1b92a..5fe1c4c5588d 100644
--- a/include/linux/generic-radix-tree.h
+++ b/include/linux/generic-radix-tree.h
@@ -100,14 +100,9 @@ void __genradix_free(struct __genradix *);
static inline size_t __idx_to_offset(size_t idx, size_t obj_size)
{
- if (!is_power_of_2(obj_size)) {
- size_t objs_per_page = PAGE_SIZE / obj_size;
+ size_t objs_per_page = PAGE_SIZE / obj_size;
- return (idx / objs_per_page) * PAGE_SIZE +
- (idx % objs_per_page) * obj_size;
- } else {
- return idx * obj_size;
- }
+ return idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size);
}
#define __genradix_cast(_radix) (typeof((_radix)->type[0]) *)
--
2.25.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
reply other threads:[~2020-08-25 14:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc04c6adae56428c9e247b0506da5f25@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=ebiggers@kernel.org \
--cc=kent.overstreet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sctp@vger.kernel.org \
--cc=marcelo.leitner@gmail.com \
--cc=nhorman@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).