Re: [PATCH] for_each_zone / for_each_pgdat

Linus Torvalds
2002-04-15T21:10:34Z

On Mon, 15 Apr 2002, Rik van Riel wrote:
>
> However, I really don't like the fact of teaching now-simple
> VM code about pgdats again ;)

Well, you don't actually have to teach it about pgdats, but try out how
much simpler the actual implementation is if you were to just add a
"endzone" macro, allowing the macros to do nesting.

Once you do that, you can basically expand the thing any which way,
something like

#define for_each_zone(zone) \
do { pg_data_t * __pgdat; \
for (__pgdat = pgdat_list; __pgdat; __pgdat = __pgdat->next) { \
int __i; \
for (i = 0; i < MAX_ZONES; i++) { \
zone = pgdat->node_zones; \
if (!zone->size) \
break; \
do { \

#define end_zone \
while (0); \
} \
} \
} while (0)

Which requires the user to use something like

for_each_zone(zone) {
...
} end_zone;

but doesn't need changing the double loop into a artificial single loop.

Linus