[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c570ff25fbfa38a5aee84a892762da85@linux.dev>
Date: Tue, 25 Apr 2023 06:38:18 +0000
From: "Yajun Deng" <yajun.deng@...ux.dev>
To: "Huang, Ying" <ying.huang@...el.com>,
"Andrew Morton" <akpm@...ux-foundation.org>
Cc: "Matthew Wilcox" <willy@...radead.org>, david@...hat.com,
osalvador@...e.de, gregkh@...uxfoundation.org, rafael@...nel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH] mmzone: Introduce for_each_populated_zone_pgdat()
April 25, 2023 1:51 PM, "Huang, Ying" <ying.huang@...el.com> wrote:
> Andrew Morton <akpm@...ux-foundation.org> writes:
>
>> On Mon, 24 Apr 2023 04:50:37 +0100 Matthew Wilcox <willy@...radead.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
Powered by blists - more mailing lists