From: Linus Torvalds <torvalds@linux-foundation.org>
To: Cedric Blancher <cedric.blancher@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>,
Matthew Wilcox <mawilcox@linuxonhyperv.com>,
Konstantin Khlebnikov <koct9i@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux MM <linux-mm@kvack.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Matthew Wilcox <mawilcox@microsoft.com>
Subject: Re: [PATCH 2/2] radix-tree: Fix optimisation problem
Date: Sun, 25 Sep 2016 12:04:33 -0700 [thread overview]
Message-ID: <CA+55aFxOJTOvxhv+hECHuGV+=xBHMuQitu86J=qBNmMYQ1ACSg@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFzge97L-JLKZq0CTW1wtMOsnt8QzOw3b5qCMmzbKxZ5aw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 811 bytes --]
On Sun, Sep 25, 2016 at 11:04 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> The more I look at that particular piece of code, the less I like it. It's
> buggy shit. It needs to be rewritten entirely too actually check for sibling
> entries, not that ad-hoc arithmetic crap.
Here's my attempt at cleaning the mess up.
I'm not claiming it's perfect, but I think it's better. It gets rid of
the ad-hoc arithmetic in radix_tree_descend(), and just makes all that
be inside the is_sibling_entry() logic instead. Which got renamed and
made to actually return the main sibling. So now there is at least
only *one* piece of code that does that range comparison, and I don't
think there is any huge need to explain what's going on, because the
"magic" is unconditional.
Willy?
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1766 bytes --]
lib/radix-tree.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 1b7bf7314141..210709b07759 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -78,18 +78,20 @@ static inline void *node_to_entry(void *ptr)
#ifdef CONFIG_RADIX_TREE_MULTIORDER
/* Sibling slots point directly to another slot in the same node */
-static inline bool is_sibling_entry(struct radix_tree_node *parent, void *node)
+static inline void **get_sibling_entry(struct radix_tree_node *parent, void *node)
{
- void **ptr = node;
- return (parent->slots <= ptr) &&
- (ptr < parent->slots + RADIX_TREE_MAP_SIZE);
+ void **ptr = (void **) entry_to_node(node);
+ if ((parent->slots <= ptr) && (ptr < parent->slots + RADIX_TREE_MAP_SIZE))
+ return ptr;
+ return NULL;
}
#else
-static inline bool is_sibling_entry(struct radix_tree_node *parent, void *node)
+static inline void **get_sibling_entry(struct radix_tree_node *parent, void *node)
{
- return false;
+ return NULL;
}
#endif
+#define is_sibling_entry(parent, node) (get_sibling_entry(parent,node) != NULL)
static inline unsigned long get_slot_offset(struct radix_tree_node *parent,
void **slot)
@@ -105,10 +107,10 @@ static unsigned int radix_tree_descend(struct radix_tree_node *parent,
#ifdef CONFIG_RADIX_TREE_MULTIORDER
if (radix_tree_is_internal_node(entry)) {
- unsigned long siboff = get_slot_offset(parent, entry);
- if (siboff < RADIX_TREE_MAP_SIZE) {
- offset = siboff;
- entry = rcu_dereference_raw(parent->slots[offset]);
+ void **sibentry = get_sibling_entry(parent, entry);
+ if (sibentry) {
+ offset = get_slot_offset(parent, sibentry);
+ entry = rcu_dereference_raw(*sibentry);
}
}
#endif
next prev parent reply other threads:[~2016-09-25 19:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 18:53 [PATCH 0/2] Fix radix_tree_lookup_slot() Matthew Wilcox
2016-09-22 18:53 ` [PATCH 1/2] radix tree test suite: Test radix_tree_replace_slot() for multiorder entries Matthew Wilcox
2016-09-22 18:53 ` [PATCH 2/2] radix-tree: Fix optimisation problem Matthew Wilcox
2016-09-22 18:09 ` Linus Torvalds
2016-09-23 20:16 ` Matthew Wilcox
2016-09-24 20:21 ` Linus Torvalds
2016-09-24 20:47 ` Linus Torvalds
2016-09-24 21:04 ` Kirill A. Shutemov
2016-09-24 22:54 ` Linus Torvalds
2016-09-26 4:26 ` Ross Zwisler
2016-09-24 8:36 ` Konstantin Khlebnikov
2016-09-24 23:35 ` Cedric Blancher
2016-09-25 0:18 ` Linus Torvalds
2016-09-25 17:59 ` Cedric Blancher
2016-09-25 18:04 ` Linus Torvalds
2016-09-25 19:04 ` Linus Torvalds [this message]
2016-09-25 19:40 ` Cedric Blancher
2016-09-25 19:56 ` Linus Torvalds
2016-09-26 21:28 ` Matthew Wilcox
2016-09-26 21:48 ` Cedric Blancher
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='CA+55aFxOJTOvxhv+hECHuGV+=xBHMuQitu86J=qBNmMYQ1ACSg@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=cedric.blancher@gmail.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=koct9i@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mawilcox@linuxonhyperv.com \
--cc=mawilcox@microsoft.com \
--cc=ross.zwisler@linux.intel.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