diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0bca2376bd42..573d138fa7a5 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -307,27 +307,31 @@ static unsigned long highmem_dirtyable_memory(unsigned long total) { #ifdef CONFIG_HIGHMEM int node; - unsigned long x = 0; + unsigned long x; int i; - unsigned long dirtyable = atomic_read(&highmem_file_pages); + unsigned long dirtyable = 0; for_each_node_state(node, N_HIGH_MEMORY) { for (i = ZONE_NORMAL + 1; i < MAX_NR_ZONES; i++) { struct zone *z; + unsigned long nr_pages; if (!is_highmem_idx(i)) continue; z = &NODE_DATA(node)->node_zones[i]; - dirtyable += zone_page_state(z, NR_FREE_PAGES); + if (!populated_zone(z)) + continue; + nr_pages = zone_page_state(z, NR_FREE_PAGES); /* watch for underflows */ - dirtyable -= min(dirtyable, high_wmark_pages(z)); - - x += dirtyable; + nr_pages -= min(nr_pages, high_wmark_pages(z)); + dirtyable += nr_pages; } } + x = dirtyable + atomic_read(&highmem_file_pages); + /* * Unreclaimable memory (kernel memory or anonymous memory * without swap) can bring down the dirtyable pages below