Skip to content

Commit ee99c71

Browse files
kosakitorvalds
authored andcommitted
mm: introduce for_each_populated_zone() macro
Impact: cleanup In almost cases, for_each_zone() is used with populated_zone(). It's because almost function doesn't need memoryless node information. Therefore, for_each_populated_zone() can help to make code simplify. This patch has no functional change. [akpm@linux-foundation.org: small cleanup] Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mel@csn.ul.ie> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a6dc60f commit ee99c71

6 files changed

Lines changed: 27 additions & 48 deletions

File tree

‎include/linux/mmzone.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,14 @@ extern struct zone *next_zone(struct zone *zone);
806806
zone; \
807807
zone = next_zone(zone))
808808

809+
#define for_each_populated_zone(zone) \
810+
for (zone = (first_online_pgdat())->node_zones; \
811+
zone; \
812+
zone = next_zone(zone)) \
813+
if (!populated_zone(zone)) \
814+
; /* do nothing */ \
815+
else
816+
809817
static inline struct zone *zonelist_zone(struct zoneref *zoneref)
810818
{
811819
return zoneref->zone;

‎kernel/power/snapshot.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,10 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask)
321321

322322
INIT_LIST_HEAD(list);
323323

324-
for_each_zone(zone) {
324+
for_each_populated_zone(zone) {
325325
unsigned long zone_start, zone_end;
326326
struct mem_extent *ext, *cur, *aux;
327327

328-
if (!populated_zone(zone))
329-
continue;
330-
331328
zone_start = zone->zone_start_pfn;
332329
zone_end = zone->zone_start_pfn + zone->spanned_pages;
333330

@@ -804,8 +801,8 @@ static unsigned int count_free_highmem_pages(void)
804801
struct zone *zone;
805802
unsigned int cnt = 0;
806803

807-
for_each_zone(zone)
808-
if (populated_zone(zone) && is_highmem(zone))
804+
for_each_populated_zone(zone)
805+
if (is_highmem(zone))
809806
cnt += zone_page_state(zone, NR_FREE_PAGES);
810807

811808
return cnt;

‎kernel/power/swsusp.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,16 @@ int swsusp_shrink_memory(void)
229229
size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES;
230230
tmp = size;
231231
size += highmem_size;
232-
for_each_zone (zone)
233-
if (populated_zone(zone)) {
234-
tmp += snapshot_additional_pages(zone);
235-
if (is_highmem(zone)) {
236-
highmem_size -=
232+
for_each_populated_zone(zone) {
233+
tmp += snapshot_additional_pages(zone);
234+
if (is_highmem(zone)) {
235+
highmem_size -=
237236
zone_page_state(zone, NR_FREE_PAGES);
238-
} else {
239-
tmp -= zone_page_state(zone, NR_FREE_PAGES);
240-
tmp += zone->lowmem_reserve[ZONE_NORMAL];
241-
}
237+
} else {
238+
tmp -= zone_page_state(zone, NR_FREE_PAGES);
239+
tmp += zone->lowmem_reserve[ZONE_NORMAL];
242240
}
241+
}
243242

244243
if (highmem_size < 0)
245244
highmem_size = 0;

‎mm/page_alloc.c‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -922,13 +922,10 @@ static void drain_pages(unsigned int cpu)
922922
unsigned long flags;
923923
struct zone *zone;
924924

925-
for_each_zone(zone) {
925+
for_each_populated_zone(zone) {
926926
struct per_cpu_pageset *pset;
927927
struct per_cpu_pages *pcp;
928928

929-
if (!populated_zone(zone))
930-
continue;
931-
932929
pset = zone_pcp(zone, cpu);
933930

934931
pcp = &pset->pcp;
@@ -1879,10 +1876,7 @@ void show_free_areas(void)
18791876
int cpu;
18801877
struct zone *zone;
18811878

1882-
for_each_zone(zone) {
1883-
if (!populated_zone(zone))
1884-
continue;
1885-
1879+
for_each_populated_zone(zone) {
18861880
show_node(zone);
18871881
printk("%s per-cpu:\n", zone->name);
18881882

@@ -1922,12 +1916,9 @@ void show_free_areas(void)
19221916
global_page_state(NR_PAGETABLE),
19231917
global_page_state(NR_BOUNCE));
19241918

1925-
for_each_zone(zone) {
1919+
for_each_populated_zone(zone) {
19261920
int i;
19271921

1928-
if (!populated_zone(zone))
1929-
continue;
1930-
19311922
show_node(zone);
19321923
printk("%s"
19331924
" free:%lukB"
@@ -1967,12 +1958,9 @@ void show_free_areas(void)
19671958
printk("\n");
19681959
}
19691960

1970-
for_each_zone(zone) {
1961+
for_each_populated_zone(zone) {
19711962
unsigned long nr[MAX_ORDER], flags, order, total = 0;
19721963

1973-
if (!populated_zone(zone))
1974-
continue;
1975-
19761964
show_node(zone);
19771965
printk("%s: ", zone->name);
19781966

@@ -2784,11 +2772,7 @@ static int __cpuinit process_zones(int cpu)
27842772

27852773
node_set_state(node, N_CPU); /* this node has a cpu */
27862774

2787-
for_each_zone(zone) {
2788-
2789-
if (!populated_zone(zone))
2790-
continue;
2791-
2775+
for_each_populated_zone(zone) {
27922776
zone_pcp(zone, cpu) = kmalloc_node(sizeof(struct per_cpu_pageset),
27932777
GFP_KERNEL, node);
27942778
if (!zone_pcp(zone, cpu))

‎mm/vmscan.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,11 +2061,9 @@ static unsigned long shrink_all_zones(unsigned long nr_pages, int prio,
20612061
struct zone *zone;
20622062
unsigned long ret = 0;
20632063

2064-
for_each_zone(zone) {
2064+
for_each_populated_zone(zone) {
20652065
enum lru_list l;
20662066

2067-
if (!populated_zone(zone))
2068-
continue;
20692067
if (zone_is_all_unreclaimable(zone) && prio != DEF_PRIORITY)
20702068
continue;
20712069

‎mm/vmstat.c‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ static void refresh_zone_stat_thresholds(void)
135135
int cpu;
136136
int threshold;
137137

138-
for_each_zone(zone) {
139-
140-
if (!zone->present_pages)
141-
continue;
142-
138+
for_each_populated_zone(zone) {
143139
threshold = calculate_threshold(zone);
144140

145141
for_each_online_cpu(cpu)
@@ -301,12 +297,9 @@ void refresh_cpu_vm_stats(int cpu)
301297
int i;
302298
int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
303299

304-
for_each_zone(zone) {
300+
for_each_populated_zone(zone) {
305301
struct per_cpu_pageset *p;
306302

307-
if (!populated_zone(zone))
308-
continue;
309-
310303
p = zone_pcp(zone, cpu);
311304

312305
for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)

0 commit comments

Comments
 (0)