linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yajun Deng" <yajun.deng@linux.dev>
To: "Huang, Ying" <ying.huang@intel.com>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Matthew Wilcox" <willy@infradead.org>,
	david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org,
	rafael@kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] mmzone: Introduce for_each_populated_zone_pgdat()
Date: Tue, 25 Apr 2023 06:38:18 +0000	[thread overview]
Message-ID: <c570ff25fbfa38a5aee84a892762da85@linux.dev> (raw)
In-Reply-To: <875y9kfr0o.fsf@yhuang6-desk2.ccr.corp.intel.com>

April 25, 2023 1:51 PM, "Huang, Ying" <ying.huang@intel.com> wrote:

> Andrew Morton <akpm@linux-foundation.org> writes:
> 
>> On Mon, 24 Apr 2023 04:50:37 +0100 Matthew Wilcox <willy@infradead.org> wrote:
>> 
>>> On Mon, Apr 24, 2023 at 11:07:56AM +0800, Yajun Deng wrote:
>>>> Instead of define an index and determining if the zone has memory,
>>>> introduce for_each_populated_zone_pgdat() helper that can be used
>>>> to iterate over each populated zone in pgdat, and convert the most
>>>> obvious users to it.
>>> 
>>> I don't think the complexity of the helper justifies the simplification
>>> of the users.
>> 
>> Are you sure?
>> 
>>>> +++ b/include/linux/mmzone.h
>>>> @@ -1580,6 +1580,14 @@ extern struct zone *next_zone(struct zone *zone);
>>>> ; /* do nothing */ \
>>>> else
>>>> 
>>>> +#define for_each_populated_zone_pgdat(zone, pgdat, max) \
>>>> + for (zone = pgdat->node_zones; \
>>>> + zone < pgdat->node_zones + max; \
>>>> + zone++) \
>>>> + if (!populated_zone(zone)) \
>>>> + ; /* do nothing */ \
>>>> + else
>>>> +
>> 
>> But each of the call sites is doing this, so at least the complexity is
>> now seen in only one place.
>> 
>> btw, do we need to do the test that way? Why won't this work?
>> 
>> #define for_each_populated_zone_pgdat(zone, pgdat, max) \
>> for (zone = pgdat->node_zones; \
>> zone < pgdat->node_zones + max; \
>> zone++) \
>> if (populated_zone(zone))
>> 
>> I suspect it was done the original way in order to save a tabstop,
>> which is no longer needed.
> 
> This may cause unexpected effect when used with "if" statement. For
> example,
> 
> if (something)
> for_each_populated_zone_pgdat(zone, pgdat, max)
> total += zone->present_pages;
> else
> pr_info("something is false!\n");
> 

Thanks Huang, Ying for the example.

Yes, this macros with multiple statements but doesn't have a do - while loop,
It needs if and else together.

> Best Regards,
> Huang, Ying

      parent reply	other threads:[~2023-04-25  6:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24  3:07 [PATCH] mmzone: Introduce for_each_populated_zone_pgdat() Yajun Deng
2023-04-24  3:50 ` Matthew Wilcox
2023-04-24 21:58   ` Andrew Morton
2023-04-25  3:23     ` Matthew Wilcox
2023-04-25  5:51     ` Huang, Ying
2023-04-25  6:27     ` Yajun Deng
2023-04-25  6:38     ` Yajun Deng [this message]

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=c570ff25fbfa38a5aee84a892762da85@linux.dev \
    --to=yajun.deng@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --cc=rafael@kernel.org \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).