From: David Hildenbrand <david@redhat.com>
To: "Huang, Ying" <ying.huang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-cxl@vger.kernel.org,
Dan Williams <dan.j.williams@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Alistair Popple <apopple@nvidia.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Bjorn Helgaas <bhelgaas@google.com>, Baoquan He <bhe@redhat.com>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>
Subject: Re: [RFC] resource: Avoid unnecessary resource tree walking in __region_intersects()
Date: Fri, 11 Oct 2024 10:02:43 +0200 [thread overview]
Message-ID: <38566dbf-1293-4fd5-9cbd-385e6c35344c@redhat.com> (raw)
In-Reply-To: <87set3a1nm.fsf@yhuang6-desk2.ccr.corp.intel.com>
On 11.10.24 03:06, Huang, Ying wrote:
> David Hildenbrand <david@redhat.com> writes:
>
>> On 10.10.24 08:55, Huang Ying wrote:
>>> Currently, if __region_intersects() finds any overlapped but unmatched
>>> resource, it walks the descendant resource tree to check for
>>> overlapped and matched descendant resources. This is achieved using
>>> for_each_resource(), which iterates not only the descent tree, but
>>> also subsequent sibling trees in certain scenarios. While this
>>> doesn't introduce bugs, it makes code hard to be understood and
>>> potentially inefficient.
>>> So, the patch renames next_resource() to __next_resource() and
>>> modified it to return NULL after traversing all descent resources.
>>> Test shows that this avoids unnecessary resource tree walking in
>>> __region_intersects().
>>> It appears even better to revise for_each_resource() to traverse the
>>> descendant resource tree of "_root" only. But that will cause "_root"
>>> to be evaluated twice, which I don't find a good way to eliminate.
>>
>> I'm not sure I'm enjoying below code, it makes it harder for me to
>> understand what's happening.
>>
>> I'm also not 100% sure why "p" becomes "root" and "dp" becomes "p" when
>> calling the function :) Likely this works as intended, but it's confusing
>> (IOW, bad naming, especially for dp).
>>
>>
>> I think you should just leave next_resource() alone and rather add
>> a new function that doesn't conditionally consume NULL pointers
>> (and also no skip_children because you're passing false either way).
>>
>> static struct resource *next_resource_XXX(struct resource *root,
>> struct resource *p)
>> {
>> while (!p->sibling && p->parent) {
>> p = p->parent;
>> if (p == root)
>> return NULL;
>> }
>> return p->sibling;
>> }
>>
>> Maybe even better, add a new for_each_resource() macro that expresses the intended semantics.
>>
>> #define for_each_resource_XXX(_root, _p) \
>> for ((_p) = (_root)->child; (_p); (_p) = next_resource_XXX(_root, _p))
>
> Yes. This can improve code readability.
>
> A possible issue is that "_root" will be evaluated twice in above macro
> definition.
Do you mean that we would process it twice in the loop body, or what
exactly do you mean with "evaluate" ?
And just I understand what we want to achieve: we want to walk the
subtree below "root" and prevent going to root->sibling or root->parent
if "root" is not actually the "real root", correct?
X
|--------|
A----D E
|
B--C
So assume we start walking at A, we want to evaluate A,B,C but not D,E,X.
Does that sum up what we want to achieve?
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-10-11 8:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 6:55 Huang Ying
2024-10-10 12:54 ` David Hildenbrand
2024-10-11 1:06 ` Huang, Ying
2024-10-11 8:02 ` David Hildenbrand [this message]
2024-10-11 8:48 ` Huang, Ying
2024-10-11 10:51 ` Andy Shevchenko
2024-10-11 10:49 ` Andy Shevchenko
2024-10-11 10:51 ` David Hildenbrand
2024-10-11 11:15 ` Andy Shevchenko
2024-10-11 11:19 ` Andy Shevchenko
2024-10-11 11:30 ` David Hildenbrand
2024-10-11 13:21 ` Huang, Ying
2024-10-23 21:07 ` Dan Williams
2024-10-24 6:57 ` Andy Shevchenko
2024-10-24 12:30 ` Huang, Ying
2024-10-24 13:01 ` Andy Shevchenko
2024-10-24 21:57 ` Dan Williams
2024-10-25 0:31 ` Huang, Ying
2024-10-25 13:22 ` Andy Shevchenko
2024-10-25 15:14 ` Dan Williams
2024-10-28 2:49 ` Huang, Ying
2024-10-25 0:34 ` Huang, Ying
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=38566dbf-1293-4fd5-9cbd-385e6c35344c@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alison.schofield@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=apopple@nvidia.com \
--cc=bhe@redhat.com \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ying.huang@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