From: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Rasmus Villemoes
<rasmus.villemoes-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
cpandya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle()
Date: Mon, 12 Feb 2018 12:06:01 -0800 [thread overview]
Message-ID: <e1265e8e-348c-1672-c5e5-27a6820f330a@gmail.com> (raw)
In-Reply-To: <5ca5194d-8b87-bcb6-73ca-a671075e4704-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
On 02/12/18 00:58, Rasmus Villemoes wrote:
> On 2018-02-12 07:27, frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
>> From: Frank Rowand <frank.rowand-7U/KSKJipcs@public.gmane.org>
>>
>> Create a cache of the nodes that contain a phandle property. Use this
>> cache to find the node for a given phandle value instead of scanning
>> the devicetree to find the node. If the phandle value is not found
>> in the cache, of_find_node_by_phandle() will fall back to the tree
>> scan algorithm.
>>
>> The cache is initialized in of_core_init().
>>
>> The cache is freed via a late_initcall_sync() if modules are not
>> enabled.
>
> Maybe a few words about the memory consumption of this solution versus
> the other proposed ones.
The patch comment is about this patch, not the other proposals.
Please do not take that as a snippy response. There were several
emails in the previous thread that discussed memory. In that
thread I responded as to how I would address the concerns. If
anyone wants to raise concerns about memory usage as a result of
this version of the patch they should do so in this current thread.
> Other nits below.
>
>> +static void of_populate_phandle_cache(void)
>> +{
>> + unsigned long flags;
>> + phandle max_phandle;
>> + u32 nodes = 0;
>> + struct device_node *np;
>> +
>> + if (phandle_cache)
>> + return;
>
> What's the point of that check?
Sanity check to make sure a memory leak of a previous cache
does not occur. I'll change it to free the cache if it
exists.
There is only one instance of of_populate_cache() being called,
so this is a theoretical issue. I intend to add another caller
in the devicetree overlay code in the future, but do not want
to do that now, to avoid a conflict with the overlay patch
series that has been in parallel development, and for which
I submitted v2 shortly after this set of patches.
> And shouldn't it be done inside the
> spinlock if at all?
Not an issue yet, but I'll keep my eye on the possibility of races
when I add a call to of_populate_cache() from the overlay code.
>> + max_phandle = live_tree_max_phandle();
>> +
>> + raw_spin_lock_irqsave(&devtree_lock, flags);
>> +
>> + for_each_of_allnodes(np)
>> + nodes++;
>
> Why not save a walk over all nodes and a spin_lock/unlock pair by
> combining the node count with the max_phandle computation? But you've
> just moved the existing live_tree_max_phandle, so probably better as a
> followup patch.
I'll consider adding the node counting into live_tree_max_phandle() later.
The other user of live_tree_max_phandle() is being modified in my overlay
patch series (see mention above). I don't want to create a conflict between
the two series.
>> + /* sanity cap for malformed tree */
>> + if (max_phandle > nodes)
>> + max_phandle = nodes;
>> +
>> + phandle_cache = kzalloc((max_phandle + 1) * sizeof(*phandle_cache),
>> + GFP_ATOMIC);
>
> Maybe kcalloc. Sure, you've capped max_phandle so there's no real risk
> of overflow.
OK, will do.
>> + for_each_of_allnodes(np)
>> + if (np->phandle != OF_PHANDLE_ILLEGAL &&
>> + np->phandle <= max_phandle &&
>> + np->phandle)
>
> I'd reverse the order of these conditions so that for all the nodes with
> no phandle we only do the np->phandle check. Also, extra whitespace
> before &&.
Will do.
>> + phandle_cache[np->phandle] = np;
>> +
>> + max_phandle_cache = max_phandle;
>> +
>> + raw_spin_unlock_irqrestore(&devtree_lock, flags);
>> +}
>> +
>
> Rasmus
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-02-12 20:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 6:27 [PATCH v2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() frowand.list-Re5JQEeQqe8AvxtiuMwx3w
2018-02-12 6:56 ` Frank Rowand
[not found] ` <6e967dd4-0fae-a912-88cd-b60f40ec0727-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-14 1:00 ` Frank Rowand
2018-02-14 15:50 ` Rob Herring
[not found] ` <1518416868-8804-1-git-send-email-frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-12 6:58 ` Frank Rowand
2018-02-13 14:49 ` Rob Herring
2018-02-14 1:07 ` Frank Rowand
2018-02-12 8:58 ` Rasmus Villemoes
[not found] ` <5ca5194d-8b87-bcb6-73ca-a671075e4704-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org>
2018-02-12 20:06 ` Frank Rowand [this message]
2018-02-12 10:51 ` Chintan Pandya
2018-02-12 20:33 ` Frank Rowand
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=e1265e8e-348c-1672-c5e5-27a6820f330a@gmail.com \
--to=frowand.list-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=cpandya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rasmus.villemoes-rjjw5hvvQKZaa/9Udqfwiw@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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).